Esempio n. 1
0
 public function testGetController()
 {
     $sc = new SystemContainer();
     $sc->setSearchNamespaces(SystemContainer::NAMESPACE_SEARCH_CONTROLLER, array());
     try {
         $request = new RequestMock('', '');
         $response = new ResponseMock();
         $sc->getController('Mock', $request, $response);
         $this->fail('Getting a controller with an empty search array should result in a ControllerException');
     } catch (\YapepBase\Exception\ControllerException $e) {
         $this->assertEquals(\YapepBase\Exception\ControllerException::ERR_CONTROLLER_NOT_FOUND, $e->getCode());
     }
     $sc->addSearchNamespace(SystemContainer::NAMESPACE_SEARCH_CONTROLLER, '\\YapepBaseTest\\Mock\\Controller');
     $this->assertInstanceOf('\\YapepBase\\Controller\\ControllerAbstract', $sc->getController('Mock', $request, $response));
 }
Esempio n. 2
0
 /**
  * Runs the error controller action for the specified HTTP error code.
  *
  * @param int $errorCode   The error code
  *
  * @return void
  */
 protected function runErrorAction($errorCode)
 {
     $controllerName = $this->config->get('system.errorController', self::DEFAULT_ERROR_CONTROLLER_NAME);
     try {
         try {
             $controller = $this->diContainer->getController($controllerName, $this->request, $this->response);
         } catch (ControllerException $exception) {
             // No such controller, fall back to built in default
             $controller = $this->diContainer->getDefaultErrorController($this->request, $this->response);
             $controllerName = self::DEFAULT_ERROR_CONTROLLER_NAME;
         }
     } catch (\Exception $e) {
         $this->dispatchedController = $controllerName;
         $this->dispatchedAction = 500;
         throw $e;
     }
     $this->dispatchedController = $controllerName;
     $this->dispatchedAction = $errorCode;
     $this->raiseEventIfNotRaisedYet(Event::TYPE_APPLICATION_BEFORE_CONTROLLER_RUN);
     $controller->run($errorCode);
     $this->raiseEventIfNotRaisedYet(Event::TYPE_APPLICATION_AFTER_CONTROLLER_RUN);
     $this->response->render();
     $this->raiseEventIfNotRaisedYet(Event::TYPE_APPLICATION_BEFORE_OUTPUT_SEND);
     $this->response->send();
     $this->raiseEventIfNotRaisedYet(Event::TYPE_APPLICATION_AFTER_OUTPUT_SEND);
 }