本文整理汇总了PHP中Framework\Registry::erase方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::erase方法的具体用法?PHP Registry::erase怎么用?PHP Registry::erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Framework\Registry
的用法示例。
在下文中一共展示了Registry::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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 (\Exception $e) {
throw new Exception\Controller("Controller {$name} is not found");
}
if (!method_exists($instance, $action)) {
$instance->willRenderLayoutView = false;
$instance->willRenderActionView = false;
throw new Exception\Action("Action {$action} is not found");
}
$inspector = new Inspector($instance);
$methodMeta = $inspector->getMethodMeta($action);
if (!empty($methodMeta['@protected']) || !empty($methodMeta['@private'])) {
throw new Exception\Action("Action {$action} is 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");
Registry::erase("controller");
}
示例2: _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");
}