本文整理汇总了PHP中Phalcon\DiInterface::wasFreshInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::wasFreshInstance方法的具体用法?PHP DiInterface::wasFreshInstance怎么用?PHP DiInterface::wasFreshInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::wasFreshInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Dispatches a handle action taking into account the routing parameters
*
* @return object|boolean
*/
public function dispatch()
{
if (is_object($this->_dependencyInjector) === false) {
$this->_throwDispatchException('A dependency injection container is required to access related dispatching services', self::EXCEPTION_NO_DI);
return false;
}
if (is_object($this->_eventsManager) === true) {
if ($this->_eventsManager->fire('dispatch:beforeDispatchLoop', $this) === false) {
return false;
}
}
$numberDispatches = 0;
$this->_finished = false;
$handler = null;
while (true) {
//Loop until finished is false
if ($this->_finished === true) {
break;
}
++$numberDispatches;
//Throw an exception after 256 consecutive forwards
if ($numberDispatches >= 256) {
$this->_throwDispatchException('Dispatcher has detected a cyclic routing causing stability problems', self::EXCEPTION_CYCLIC_ROUTING);
break;
}
$this->_finished = true;
//If the current namespace is null we use the set in $this->_defaultNamespace
if (is_null($this->_namespaceName) === true) {
$this->_namespaceName = $this->_defaultNamespace;
}
//If the handler is null we use the set in $this->_defaultHandler
if (is_null($this->_handlerName) === true) {
$this->_handlerName = $this->_defaultHandler;
}
//If the action is null we use the set in $this->_defaultAction
if (is_null($this->_actionName) === true) {
$this->_actionName = $this->_defaultAction;
}
//Calling beforeDispatch
if (is_object($this->_eventsManager) === true) {
if ($this->_eventsManager->fire('dispatch:beforeDispatch', $this) === false) {
continue;
}
//Check if the user made a forward in the listener
if ($this->_finished === false) {
continue;
}
}
//We don't camelize the classes if they are in namespaces
$p = strpos($this->_handlerName, '\\');
if ($p === false) {
$camelizedClass = Text::camelize($this->_handlerName);
} elseif ($p === 0) {
//@note this only handles one leading slash
$camelizedClass = substr($this->_handlerName, strlen($this->_handlerName) + 1);
} else {
$camelizedClass = $this->_handlerName;
}
//Create the complete controller class name prepending the namespace
if (is_null($this->_namespaceName) === false) {
if (strrpos($this->_namespaceName, '\\') === strlen($this->_namespaceName) - 1) {
$handlerClass = $this->_namespaceName . $camelizedClass . $this->_handlerSuffix;
} else {
$handlerClass = $this->_namespaceName . '\\' . $camelizedClass . $this->_handlerSuffix;
}
} else {
$handlerClass = $camelizedClass . $this->_handlerSuffix;
}
//Handlers are retrieved as shared instances from the Service Container
if ($this->_dependencyInjector->has($handlerClass) === false) {
//Check using autoloading
if (class_exists($handlerClass) === false) {
if ($this->_throwDispatchException($handlerClass . ' handler class cannot be loaded', self::EXCEPTION_HANDLER_NOT_FOUND) === false) {
if ($this->_finished === false) {
continue;
}
}
break;
}
}
//Handlers must be only objects
$handler = $this->_dependencyInjector->getShared($handlerClass);
if (is_object($handler) === false) {
if ($this->_throwDispatchException('Invalid handler returned from the services container', self::EXCEPTION_INVALID_HANDLER) === false) {
if ($this->_finished === false) {
continue;
}
}
break;
}
//If the object was recently created in the DI we initialize it
$wasFresh = $this->_dependencyInjector->wasFreshInstance();
$this->_activeHandler = $handler;
//Check if the method exists in the handler
$actionMethod = $this->_actionName . $this->_actionSuffix;
//.........这里部分代码省略.........