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 | 18 | public function __construct(ContainerInterface $container = null) |
|
41 | |||
42 | /** |
||
43 | * Container getter. |
||
44 | * |
||
45 | * @return ContainerInterface |
||
46 | */ |
||
47 | 18 | public function getContainer() |
|
51 | |||
52 | /** |
||
53 | * Penny dispatcher getter. |
||
54 | * |
||
55 | * @return Dispatcher |
||
56 | */ |
||
57 | 15 | private function getDispatcher() |
|
58 | { |
||
59 | 15 | $dispatcher = $this->container->get('dispatcher'); |
|
60 | 15 | if (!is_callable($dispatcher)) { |
|
61 | 1 | throw new \RuntimeException('Dispatcher must be a callable'); |
|
62 | } |
||
63 | |||
64 | 14 | return $dispatcher; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Penny HTTP flow event getter. |
||
69 | * |
||
70 | * @return PennyEvmInterface |
||
71 | */ |
||
72 | 14 | private function getEventManager() |
|
76 | |||
77 | /** |
||
78 | * Setup event with Request and Response provided |
||
79 | * |
||
80 | * @param mixed|null $request Representation of an outgoing, |
||
81 | * client-side request. |
||
82 | * @param mixed|null $response Representation of an incoming, |
||
83 | * server-side response. |
||
84 | * |
||
85 | * @throws RuntimeException if event did not supported. |
||
86 | */ |
||
87 | 16 | private function setUpEventWithRequestResponse($request, $response) |
|
103 | |||
104 | /** |
||
105 | * Application execution. |
||
106 | * |
||
107 | * @param mixed|null $request Representation of an outgoing, |
||
108 | * client-side request. |
||
109 | * @param mixed|null $response Representation of an incoming, |
||
110 | * server-side response. |
||
111 | * |
||
112 | * @return mixed |
||
113 | */ |
||
114 | 16 | public function run($request = null, $response = null) |
|
132 | |||
133 | /** |
||
134 | * Handle Route. |
||
135 | * |
||
136 | * @param $routeInfo |
||
137 | * @param PennyEventInterface $event |
||
138 | * |
||
139 | * @throws RuntimeException if dispatch does not return RouteInfo object. |
||
140 | */ |
||
141 | 11 | private function handleRoute($routeInfo, PennyEventInterface $event) |
|
150 | |||
151 | /** |
||
152 | * Handle Response. |
||
153 | * |
||
154 | * @param PennyEvmInterface $eventManager |
||
155 | * @param PennyEventInterface $event |
||
156 | * @param RouteInfoInterface $routeInfo |
||
157 | */ |
||
158 | private function handleResponse( |
||
176 | |||
177 | /** |
||
178 | * Event Manager trigger with exception |
||
179 | * |
||
180 | * @param PennyEvmInterface $eventManager |
||
181 | * @param PennyEventInterface $event |
||
182 | * @param string $name |
||
183 | * @param Exception $exception |
||
184 | * |
||
185 | * @return PennyEventInterface |
||
186 | */ |
||
187 | 5 | private function triggerWithException( |
|
199 | } |
||
200 |