1 | <?php |
||
13 | class App |
||
14 | { |
||
15 | /** |
||
16 | * Dependency Injection container. |
||
17 | * |
||
18 | * @var ContainerInterface |
||
19 | */ |
||
20 | private $container; |
||
21 | |||
22 | /** |
||
23 | * Application initialization. |
||
24 | * |
||
25 | * @param ContainerInterface $container Dependency Injection container. |
||
26 | * |
||
27 | * @throws Exception If no router is defined. |
||
28 | */ |
||
29 | 19 | public function __construct(ContainerInterface $container = null) |
|
30 | { |
||
31 | 19 | if ($container === null) { |
|
32 | 2 | $container = Container\PHPDiFactory::buildContainer(Loader::load()); |
|
33 | } |
||
34 | |||
35 | 19 | if ($container->has('router') === false) { |
|
36 | 1 | throw new Exception('Define router config'); |
|
37 | } |
||
38 | |||
39 | 19 | $this->container = $container; |
|
40 | 19 | } |
|
41 | |||
42 | /** |
||
43 | * Container getter. |
||
44 | * |
||
45 | * @return ContainerInterface |
||
46 | */ |
||
47 | 19 | public function getContainer() |
|
51 | |||
52 | /** |
||
53 | * Penny dispatcher getter. |
||
54 | * |
||
55 | * @return Dispatcher |
||
56 | */ |
||
57 | 16 | private function getDispatcher() |
|
72 | |||
73 | /** |
||
74 | * Penny HTTP flow event getter. |
||
75 | * |
||
76 | * @return EventManagerInterface |
||
77 | */ |
||
78 | 14 | private function getEventManager() |
|
82 | |||
83 | /** |
||
84 | * Setup event with Request and Response provided |
||
85 | * |
||
86 | * @param mixed|null $request Representation of an outgoing, |
||
87 | * client-side request. |
||
88 | * @param mixed|null $response Representation of an incoming, |
||
89 | * server-side response. |
||
90 | * |
||
91 | * @throws RuntimeException if event did not supported. |
||
92 | */ |
||
93 | 17 | private function setUpEventWithRequestResponse($request, $response) |
|
109 | |||
110 | /** |
||
111 | * Application execution. |
||
112 | * |
||
113 | * @param mixed|null $request Representation of an outgoing, |
||
114 | * client-side request. |
||
115 | * @param mixed|null $response Representation of an incoming, |
||
116 | * server-side response. |
||
117 | * |
||
118 | * @return mixed |
||
119 | */ |
||
120 | 17 | public function run($request = null, $response = null) |
|
141 | |||
142 | /** |
||
143 | * Handle Response. |
||
144 | * |
||
145 | * @param EventManagerInterface $eventManager |
||
146 | * @param EventInterface $event |
||
147 | * @param RouteInfoInterface $routeInfo |
||
148 | */ |
||
149 | private function handleResponse( |
||
167 | |||
168 | /** |
||
169 | * Event Manager trigger with exception |
||
170 | * |
||
171 | * @param EventManagerInterface $eventManager |
||
172 | * @param EventInterface $event |
||
173 | * @param string $name |
||
174 | * @param Exception $exception |
||
175 | * |
||
176 | * @return EventInterface |
||
177 | */ |
||
178 | 4 | private function triggerWithException( |
|
190 | } |
||
191 |