本文整理汇总了PHP中Interop\Container\ContainerInterface::injectOn方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::injectOn方法的具体用法?PHP ContainerInterface::injectOn怎么用?PHP ContainerInterface::injectOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interop\Container\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::injectOn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initController
public function initController(\Zend_EventManager_Event $e)
{
$controller = $e->getTarget();
$this->container->injectOn($controller);
}
示例2: dispatch
/**
* {@inheritdoc}
*
* The body of this method is a copy-paste of the parent class
*/
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
{
$this->setResponse($response);
/**
* Get controller class
*/
if (!$this->isDispatchable($request)) {
$controller = $request->getControllerName();
if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
}
$className = $this->getDefaultControllerClass($request);
} else {
$className = $this->getControllerClass($request);
if (!$className) {
$className = $this->getDefaultControllerClass($request);
}
}
/**
* If we're in a module or prefixDefaultModule is on, we must add the module name
* prefix to the contents of $className, as getControllerClass does not do that automatically.
* We must keep a separate variable because modules are not strictly PSR-0: We need the no-module-prefix
* class name to do the class->file mapping, but the full class name to insantiate the controller
*/
$moduleClassName = $className;
if ($this->_defaultModule != $this->_curModule || $this->getParam('prefixDefaultModule')) {
$moduleClassName = $this->formatClassName($this->_curModule, $className);
}
/**
* Load the controller class file
*/
$className = $this->loadClass($className);
$controller = new $moduleClassName($request, $this->getResponse(), $this->getParams());
// Code edited for PHP-DI
// -----------------------------------------------
// Inject the dependencies on the controller
$this->container->injectOn($controller);
// -----------------------------------------------
if (!$controller instanceof Zend_Controller_Action_Interface && !$controller instanceof Zend_Controller_Action) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Controller "' . $moduleClassName . '" is not an instance of Zend_Controller_Action_Interface');
}
/**
* Retrieve the action name
*/
$action = $this->getActionMethod($request);
/**
* Dispatch the method call
*/
$request->setDispatched(true);
// by default, buffer output
$disableOb = $this->getParam('disableOutputBuffering');
$obLevel = ob_get_level();
if (empty($disableOb)) {
ob_start();
}
try {
$controller->dispatch($action);
} catch (Exception $e) {
// Clean output buffer on error
$curObLevel = ob_get_level();
if ($curObLevel > $obLevel) {
do {
ob_get_clean();
$curObLevel = ob_get_level();
} while ($curObLevel > $obLevel);
}
throw $e;
}
if (empty($disableOb)) {
$content = ob_get_clean();
$response->appendBody($content);
}
// Destroy the page controller instance and reflection objects
$controller = null;
}
示例3: init
public function init()
{
parent::init();
// inject dependencies to action controller
$this->container->injectOn($this->getActionController());
}