public function testConstructor() { $sc = new SystemContainer(); $this->assertInstanceOf('\\YapepBase\\ErrorHandler\\ErrorHandlerRegistry', $sc->getErrorHandlerRegistry()); $this->assertInstanceOf('\\YapepBase\\Log\\Message\\ErrorMessage', $sc->getErrorLogMessage()); $this->assertInstanceOf('\\YapepBase\\Event\\EventHandlerRegistry', $sc->getEventHandlerRegistry()); $this->assertInstanceOf('\\YapepBase\\Session\\SessionRegistry', $sc->getSessionRegistry()); }
/** * Runs the request on the application * * @return void */ public function run() { // Inform the ErrorHandler about the run $this->diContainer->getErrorHandlerRegistry()->reportApplicationRun(); $eventHandlerRegistry = $this->diContainer->getEventHandlerRegistry(); try { $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_BEFORE_RUN)); $controllerName = null; $action = null; try { $this->router->getRoute($controllerName, $action); $this->dispatchedController = $controllerName; $this->dispatchedAction = $action; } catch (RouterException $exception) { if ($exception->getCode() == RouterException::ERR_NO_ROUTE_FOUND) { // The route was not found, generate a 404 HttpException throw new HttpException('Route not found. Controller/action: ' . $controllerName . '/' . $action, 404); } else { // This was not a no route found error, re-throw the exception throw $exception; } } $controller = $this->getDiContainer()->getController($controllerName, $this->request, $this->response); $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_BEFORE_CONTROLLER_RUN)); $controller->run($action); $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_AFTER_CONTROLLER_RUN)); $this->response->render(); $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_BEFORE_OUTPUT_SEND)); $this->response->send(); $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_AFTER_OUTPUT_SEND)); // @codeCoverageIgnoreStart } catch (HttpException $exception) { $this->runErrorAction($exception->getCode()); } catch (RedirectException $exception) { $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_BEFORE_OUTPUT_SEND)); $this->response->send(); $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_AFTER_OUTPUT_SEND)); } catch (\Exception $exception) { $this->handleFatalException($exception); } // Check that all required events were raised $requiredEventTypes = array(Event::TYPE_APPLICATION_BEFORE_RUN, Event::TYPE_APPLICATION_BEFORE_CONTROLLER_RUN, Event::TYPE_APPLICATION_AFTER_CONTROLLER_RUN, Event::TYPE_APPLICATION_BEFORE_OUTPUT_SEND, Event::TYPE_APPLICATION_AFTER_OUTPUT_SEND); foreach ($requiredEventTypes as $eventType) { $this->raiseEventIfNotRaisedYet($eventType); } $eventHandlerRegistry->raise(new Event(Event::TYPE_APPLICATION_AFTER_RUN)); // @codeCoverageIgnoreEnd }