public function initController(\Zend_EventManager_Event $e)
 {
     $controller = $e->getTarget();
     $this->container->injectOn($controller);
 }
Beispiel #2
0
 /**
  * {@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;
 }
 public function init()
 {
     parent::init();
     // inject dependencies to action controller
     $this->container->injectOn($this->getActionController());
 }