本文整理匯總了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;
//.........這裏部分代碼省略.........