1 | <?php |
||
23 | class Application |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var ContainerInterface |
||
28 | */ |
||
29 | private static $container; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $configPath; |
||
35 | |||
36 | /** |
||
37 | * @var Request |
||
38 | */ |
||
39 | private $request; |
||
40 | |||
41 | /** |
||
42 | * @var MiddlewareRunnerInterface |
||
43 | */ |
||
44 | private $runner; |
||
45 | |||
46 | /** |
||
47 | * @var Response |
||
48 | */ |
||
49 | private $response; |
||
50 | |||
51 | /** |
||
52 | * @var ContainerInterface |
||
53 | */ |
||
54 | private static $defaultContainer; |
||
55 | |||
56 | /** |
||
57 | * Creates an application with an HTTP request |
||
58 | * |
||
59 | * If no request is provided then a Slick\Http\PhpEnvironment\Request is |
||
60 | * created with values form current php environment settings. |
||
61 | * |
||
62 | * @param Request $request |
||
63 | */ |
||
64 | 8 | public function __construct(Request $request = null) |
|
65 | { |
||
66 | 8 | $this->request = $request; |
|
67 | 8 | Configuration::addPath(__DIR__.'/Configuration'); |
|
68 | 8 | $definitions = include __DIR__.'/Configuration/services.php'; |
|
69 | 8 | self::$defaultContainer = ( |
|
70 | 8 | new ContainerBuilder($definitions) |
|
71 | ) |
||
72 | 8 | ->getContainer(); |
|
73 | 8 | } |
|
74 | |||
75 | /** |
||
76 | * Gets the application dependency injection container |
||
77 | * |
||
78 | * @return ContainerInterface |
||
79 | */ |
||
80 | 6 | public function getContainer() |
|
81 | { |
||
82 | 6 | if (is_null(self::$container)) { |
|
83 | 2 | self::$container = $this->checkContainer(); |
|
84 | 1 | } |
|
85 | 6 | return self::$container; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Sets the dependency injection container |
||
90 | * |
||
91 | * @param ContainerInterface $container |
||
92 | */ |
||
93 | 6 | public static function setContainer(ContainerInterface $container) |
|
94 | { |
||
95 | 6 | self::$container = $container; |
|
96 | 6 | } |
|
97 | |||
98 | /** |
||
99 | * Returns the application dependency container |
||
100 | * |
||
101 | * @return ContainerInterface |
||
102 | */ |
||
103 | 12 | public static function container() |
|
111 | |||
112 | /** |
||
113 | * Set middleware runner |
||
114 | * |
||
115 | * @param MiddlewareRunnerInterface $runner |
||
116 | * |
||
117 | * @return $this|self|Application |
||
118 | */ |
||
119 | 2 | public function setRunner(MiddlewareRunnerInterface $runner) |
|
124 | |||
125 | /** |
||
126 | * Returns the processed response |
||
127 | * |
||
128 | * @return Response |
||
129 | */ |
||
130 | 2 | public function getResponse() |
|
137 | |||
138 | /** |
||
139 | * Gets the HTTP middleware runner for this application |
||
140 | * |
||
141 | * @return MiddlewareRunnerInterface |
||
142 | */ |
||
143 | 2 | public function getRunner() |
|
153 | |||
154 | /** |
||
155 | * Set configuration path |
||
156 | * |
||
157 | * @param string $configPath |
||
158 | * |
||
159 | * @return Application|self |
||
160 | */ |
||
161 | public function setConfigPath($configPath) |
||
167 | |||
168 | /** |
||
169 | * Gets configuration path |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getConfigPath() |
||
181 | |||
182 | /** |
||
183 | * Gets HTTP request object |
||
184 | * |
||
185 | * @return Request |
||
186 | */ |
||
187 | 2 | public function getRequest() |
|
195 | |||
196 | /** |
||
197 | * Gets container with user overridden settings |
||
198 | * |
||
199 | * @return ContainerInterface|\Slick\Di\Container |
||
200 | */ |
||
201 | 2 | protected function checkContainer() |
|
218 | |||
219 | } |