1 | <?php |
||
26 | class BaseApp extends Container |
||
27 | { |
||
28 | /** |
||
29 | * @const string |
||
30 | */ |
||
31 | const CHARSET = 'UTF-8'; |
||
32 | |||
33 | /** |
||
34 | * @var Config |
||
35 | */ |
||
36 | protected $config; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $environment; |
||
42 | |||
43 | /** |
||
44 | * @var ServiceProviderInterface[] |
||
45 | */ |
||
46 | protected $providers = []; |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | protected $booted = false; |
||
52 | |||
53 | /** |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $isCli = false; |
||
57 | |||
58 | /** |
||
59 | * Constructor. |
||
60 | * |
||
61 | * @param array|Config $config |
||
62 | * @param string $environment Defaults to "production" |
||
63 | */ |
||
64 | 21 | public function __construct($config = [], $environment = 'production') |
|
76 | |||
77 | /** |
||
78 | * Initializes the application object. |
||
79 | |||
80 | * Override and put initialization code that should always be run as early as |
||
81 | * possible here, but make sure no objects are actually instanced here, because then |
||
82 | * mock objects can't be injected in their place. Place object instance code in |
||
83 | * the preHandle method. |
||
84 | */ |
||
85 | 21 | protected function init() |
|
95 | |||
96 | /** |
||
97 | * Register service providers. |
||
98 | */ |
||
99 | 21 | protected function registerProviders() |
|
104 | |||
105 | /** |
||
106 | * Register service provider. |
||
107 | * |
||
108 | * @param ServiceProviderInterface $provider |
||
109 | */ |
||
110 | 21 | public function register(ServiceProviderInterface $provider) |
|
116 | |||
117 | /** |
||
118 | * @param array $phpSettings |
||
119 | * @param string $prefix |
||
120 | */ |
||
121 | 21 | protected function setPhpSettings($phpSettings, $prefix = '') |
|
132 | |||
133 | /** |
||
134 | * Boot the application and its service providers. |
||
135 | * |
||
136 | * This is normally called by handle(). If requests are not handled |
||
137 | * this method will have to called manually to boot. |
||
138 | */ |
||
139 | 5 | public function boot() |
|
153 | |||
154 | /** |
||
155 | * Pre handle method meant to be overridden in descendant classes (optional). |
||
156 | * |
||
157 | * This method is called before an request is handled. Object instance code should be |
||
158 | * place here and not in init() (more info about this at init()). |
||
159 | * |
||
160 | * @param Request $request |
||
161 | * @return Response|null |
||
162 | */ |
||
163 | 3 | protected function preHandle(Request $request) |
|
166 | |||
167 | /** |
||
168 | * Post route method meant to be overridden in descendant classes (optional). |
||
169 | * This method is called before an request is dispatched but after it's routed. This means that we know |
||
170 | * it's a valid route and have access to the route attributes at this stage. |
||
171 | * |
||
172 | * @param Request $request |
||
173 | * @return Response|null |
||
174 | */ |
||
175 | 1 | protected function postRoute(Request $request) |
|
178 | |||
179 | /** |
||
180 | * Handles an http request and returns a response. |
||
181 | * |
||
182 | * @param Request $request |
||
183 | * @return Response |
||
184 | */ |
||
185 | 4 | public function handle(Request $request) |
|
212 | |||
213 | /** |
||
214 | * Returns a response for no route / resource not found. |
||
215 | * |
||
216 | * @param Request $request |
||
217 | * @return Response |
||
218 | */ |
||
219 | 1 | protected function getNoRouteResponse(Request $request) |
|
223 | |||
224 | /** |
||
225 | * Post handle method meant to be overridden in descendant classes (optional). |
||
226 | * This method is called after an request has been handled but before |
||
227 | * the response is returned from the handle method. |
||
228 | * |
||
229 | * @param Request $request |
||
230 | */ |
||
231 | 2 | protected function postHandle(Request $request) |
|
234 | |||
235 | /** |
||
236 | * @return Config |
||
237 | */ |
||
238 | 21 | public function getConfig() |
|
242 | |||
243 | /** |
||
244 | * @return bool |
||
245 | */ |
||
246 | 21 | public function isCli(): bool |
|
250 | |||
251 | /** |
||
252 | * @return Session |
||
253 | */ |
||
254 | public function getSession() |
||
258 | |||
259 | /** |
||
260 | * @return Router |
||
261 | */ |
||
262 | public function getRouter() |
||
263 | { |
||
264 | return $this->get(Router::class); // Makes this method faster by bypassing __call() (which is quite slow). |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @return Request|null |
||
269 | */ |
||
270 | public function getRequest() |
||
271 | { |
||
272 | return $this->has(Request::class) ? $this->get(Request::class) : null; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @return string |
||
277 | */ |
||
278 | 1 | public function getEnvironment() |
|
282 | } |
||
283 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.