当前位置: 首页>>代码示例>>PHP>>正文


PHP Registry::set方法代码示例

本文整理汇总了PHP中Framework\Registry::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::set方法的具体用法?PHP Registry::set怎么用?PHP Registry::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Framework\Registry的用法示例。


在下文中一共展示了Registry::set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct()
 {
     echo 'Test model loaded.' . PHP_EOL;
     $database = new Framework\Database(array("type" => "mysql", "options" => array("host" => "localhost", "username" => "root", "password" => "root", "schema" => "prophpmvc")));
     $database = $database->initialize();
     $database = $database->connect();
     Framework\Registry::set("database", $database);
     self::runAll();
 }
开发者ID:vjroby,项目名称:library,代码行数:9,代码来源:testmodel.php

示例2: run

 /**
  * Запуск приложения
  *
  * @param array $configArray Массив конфигурации
  * @throws \Exception
  */
 public static function run(array $configArray)
 {
     $request = new Request();
     $config = new Config($configArray);
     Registry::set('request', $request);
     Registry::set('config', $config);
     Registry::set('pdo', new PDO('mysql:host=' . $config->get('db')['host'] . ';dbname=' . $config->get('db')['dbname'] . ';charset=utf8', $config->get('db')['user'], $config->get('db')['passwd']));
     $routing = new Routing($request->server('REQUEST_URI'));
     Registry::set('routing', $routing);
     $routing->run();
 }
开发者ID:lukianenko,项目名称:mindk,代码行数:17,代码来源:Application.php

示例3: connect

 public static function connect()
 {
     $mongoDB = Registry::get("MongoDB");
     if (!$mongoDB) {
         require_once APP_PATH . '/application/libraries/vendor/autoload.php';
         $configuration = Registry::get("configuration");
         try {
             $dbconf = $configuration->parse("configuration/database")->database->mongodb;
             $mongo = new \MongoDB\Client("mongodb://" . $dbconf->dbuser . ":" . $dbconf->password . "@" . $dbconf->url . "/" . $dbconf->dbname . "?replicaSet=" . $dbconf->replica . "&ssl=true");
             $mongoDB = $mongo->selectDatabase($dbconf->dbname);
         } catch (\Exception $e) {
             throw new \Framework\Database\Exception("DB Error");
         }
         Registry::set("MongoDB", $mongoDB);
     }
     return $mongoDB;
 }
开发者ID:vNative,项目名称:vnative,代码行数:17,代码来源:db.php

示例4: _pass

 protected function _pass($controller, $action, $parameters = array())
 {
     $name = ucfirst($controller);
     $this->_controller = $controller;
     $this->_action = $action;
     try {
         $instance = new $name(array("parameters" => $parameters));
         Registry::set("controller", $instance);
     } catch (\Framework\Database\Exception $e) {
         throw new \Framework\Database\Exception($e->getMessage());
     } catch (\Exception $e) {
         throw new Exception\Controller("Controller {$name} not found " . $name);
     }
     if (!method_exists($instance, $action)) {
         $instance->willRenderLayoutView = false;
         $instance->willRenderActionView = false;
         throw new Exception\Action("Action {$action} not found");
     }
     $inspector = new Inspector($instance);
     $methodMeta = $inspector->getMethodMeta($action);
     if (!empty($methodMeta["@protected"]) || !empty($methodMeta["@private"])) {
         throw new Exception\Action("Action {$action} not found");
     }
     $hooks = function ($meta, $type) use($inspector, $instance) {
         if (isset($meta[$type])) {
             $run = array();
             foreach ($meta[$type] as $method) {
                 $hookMeta = $inspector->getMethodMeta($method);
                 if (in_array($method, $run) && !empty($hookMeta["@once"])) {
                     continue;
                 }
                 $instance->{$method}();
                 $run[] = $method;
             }
         }
     };
     $hooks($methodMeta, "@before");
     call_user_func_array(array($instance, $action), is_array($parameters) ? $parameters : array());
     $hooks($methodMeta, "@after");
     // unset controller to fire the __destruct magic method
     Registry::erase("controller");
 }
开发者ID:vjroby,项目名称:library,代码行数:42,代码来源:router.php

示例5: mongod

 protected function mongod()
 {
     $mongod = Registry::get("mongod");
     if ($mongod) {
         return $mongod;
     } else {
         $cache = new \Framework\Cache(array("type" => "mongod"));
         $m = $cache->initialize();
         $m->connect('healthlitmus');
         Registry::set("mongod", $m);
         return $m;
     }
 }
开发者ID:HLitmus,项目名称:WebApp,代码行数:13,代码来源:controller.php

示例6: _setValue

 /**
  * Offers the solution to storage that can be accessed from everywhere.
  * @param type $key
  * @param type $value
  */
 protected function _setValue($key, $value)
 {
     if (!empty($key)) {
         $data = Registry::get($this->defaultKey, array());
         $data[$key] = $value;
         Registry::set($this->defaultKey, $data);
     }
 }
开发者ID:SwiftSchool,项目名称:School,代码行数:13,代码来源:extended.php

示例7: __construct

 public function __construct($options = array())
 {
     parent::__construct($options);
     // connect to database
     $database = Registry::get("database");
     $database->connect();
     $mongoDB = Registry::get("MongoDB");
     if (!$mongoDB) {
         $mongo = new \MongoClient();
         $mongoDB = $mongo->selectDB("stats");
         Registry::set("MongoDB", $mongoDB);
     }
     // schedule: load user from session
     Events::add("framework.router.beforehooks.before", function ($name, $parameters) {
         $session = Registry::get("session");
         $controller = Registry::get("controller");
         $user = $session->get("user");
         if ($user) {
             $controller->user = \User::first(array("id = ?" => $user));
         }
     });
     // schedule: save user to session
     Events::add("framework.router.afterhooks.after", function ($name, $parameters) {
         $session = Registry::get("session");
         $controller = Registry::get("controller");
         if ($controller->user) {
             $session->set("user", $controller->user->id);
         }
     });
     // schedule: disconnect from database
     Events::add("framework.controller.destruct.after", function ($name) {
         $database = Registry::get("database");
         $database->disconnect();
     });
 }
开发者ID:SwiftSchool,项目名称:School,代码行数:35,代码来源:controller.php

示例8: action

 /**
  * Вызвать действие контроллера
  *
  * @param string $action Действие
  * @param string $controller Контроллер
  * @param string $module Модуль
  * @param array $params Параметры
  */
 public static function action($action, $controller, $module, array $params = [])
 {
     $routing = Registry::get('routing');
     $request = Registry::get('request');
     $routing->setAction($action);
     $routing->setController($controller);
     $routing->setModule($module);
     $request->setParams($params);
     Registry::set('request', $request);
     $routing->run();
 }
开发者ID:lukianenko,项目名称:mindk,代码行数:19,代码来源:Request.php

示例9: _loadController

 /**
  * Load a controller
  * @return boolean|string
  */
 private function _loadController($method, $controller, $action, $parameters = array())
 {
     $name = ucfirst($controller);
     $this->_controller = $controller;
     $this->_action = $action;
     Event::fire("framework.router.controller.before", array($controller, $parameters));
     try {
         $instance = new $name(array("parameters" => $parameters));
         Registry::set("controller", $instance);
     } catch (\Exception $e) {
         throw new \Exception("Controller {$name} not found", 404);
     }
     Event::fire("framework.router.controller.after", array($controller, $parameters));
     if (!empty($action)) {
         // If request method valid append to action
         if ($this->_validateRequestMethod($method)) {
             $action = strtolower($method) . ucfirst($action);
         }
         // Check if called method exists
         if (!method_exists($instance, $action)) {
             throw new \Exception("Action {$action} not found", 404);
         }
         // Check if method is callable (checking for @protected or @private)
         $inspector = new Inspector($instance);
         $methodMeta = $inspector->getMethodMeta($action);
         if (!empty($methodMeta["@protected"]) || !empty($methodMeta["@private"])) {
             throw new \Exception("Action {$action} not found", 404);
         }
     }
     $hooks = function ($meta, $type) use($inspector, $instance) {
         if (isset($meta[$type])) {
             $run = array();
             foreach ($meta[$type] as $method) {
                 $hookMeta = $inspector->getMethodMeta($method);
                 if (in_array($method, $run) && !empty($hookMeta["@once"])) {
                     contiue;
                 }
                 $instance->{$method}();
                 $run[] = $method;
             }
         }
     };
     Event::fire("framework.router.beforehooks.before", array($action, $parameters));
     $hooks($methodMeta, "@before");
     Event::fire("framework.router.beforehooks.after", array($action, $parameters));
     Event::fire("framework.router.action.before", array($action, $parameters));
     // Call Method or resort to default
     switch (true) {
         case !empty($action):
             call_user_func_array(array($instance, $action), is_array($parameters) ? $parameters : array());
             break;
         default:
             call_user_func_array(array($instance, $this->_defaultAction), is_array($parameters) ? $parameters : array());
             break;
     }
     Event::fire("framework.router.action.after", array($action, $parameters));
     Event::fire("framework.router.afterhooks.before", array($action, $parameters));
     $hooks($methodMeta, "@after");
     Event::fire("framework.router.afterhooks.after", array($action, $parameters));
     // unset controller
     Registry::erase("controller");
 }
开发者ID:chapmang,项目名称:phpframework,代码行数:66,代码来源:router.php

示例10: setRequestParams

 /**
  * Установить параметры для объекта запроса
  */
 private function setRequestParams()
 {
     $request = Registry::get('request');
     if ($request) {
         $request->setModule($this->getModule());
         $request->setController($this->getController());
         $request->setAction($this->getAction());
         $request->initUriStringParams();
         Registry::set('request', $request);
     }
 }
开发者ID:lukianenko,项目名称:mindk,代码行数:14,代码来源:Routing.php


注:本文中的Framework\Registry::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。