Total Complexity | 81 |
Total Lines | 821 |
Duplicated Lines | 0 % |
Changes | 12 | ||
Bugs | 0 | Features | 0 |
Complex classes like Application often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Application, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
44 | class Application extends Container implements ApplicationContract |
||
45 | { |
||
46 | /** |
||
47 | * The current globally available application. |
||
48 | * |
||
49 | * @var string $instance |
||
50 | */ |
||
51 | protected static $instance; |
||
52 | |||
53 | /** |
||
54 | * Php version. |
||
55 | */ |
||
56 | protected static $phpVersion = '7.3.12'; |
||
57 | |||
58 | /** |
||
59 | * The custom application path defined by the developer. |
||
60 | * |
||
61 | * @var string $appPath |
||
62 | */ |
||
63 | protected $appPath; |
||
64 | |||
65 | /** |
||
66 | * The base path for the Lenevor installation. |
||
67 | * |
||
68 | * @var string $basePath |
||
69 | */ |
||
70 | protected $basePath; |
||
71 | |||
72 | /** |
||
73 | * Indicates if the application has 'booted'. |
||
74 | * |
||
75 | * @var bool $booted |
||
76 | */ |
||
77 | protected $booted = false; |
||
78 | |||
79 | /** |
||
80 | * The array of booted callbacks. |
||
81 | * |
||
82 | * @var callable[] $bootedCallbacks |
||
83 | */ |
||
84 | protected $bootedCallbacks = []; |
||
85 | |||
86 | /** |
||
87 | * The array of booting callbacks. |
||
88 | * |
||
89 | * @var callable[] $bootingCallbacks |
||
90 | */ |
||
91 | protected $bootingCallbacks = []; |
||
92 | |||
93 | /** |
||
94 | * Get the current application environment. |
||
95 | * |
||
96 | * @var string |
||
97 | */ |
||
98 | protected $env; |
||
99 | |||
100 | /** |
||
101 | * The custom environment path defined by the developer. |
||
102 | * |
||
103 | * @var string $environmentPath |
||
104 | */ |
||
105 | protected $environmentPath; |
||
106 | |||
107 | /** |
||
108 | * The environment file to load during bootstrapping. |
||
109 | * |
||
110 | * @var string $environmentFile |
||
111 | */ |
||
112 | protected $environmentFile = '.env'; |
||
113 | |||
114 | /** |
||
115 | * Indicates if the application has been bootstrapped before. |
||
116 | * |
||
117 | * @var bool $hasBeenBootstrapped |
||
118 | */ |
||
119 | protected $hasBeenBootstrapped = false; |
||
120 | |||
121 | /** |
||
122 | * Indicates if the application is running in the console. |
||
123 | * |
||
124 | * @var bool|null $isRunningInConsole |
||
125 | */ |
||
126 | protected $isRunningInConsole; |
||
127 | |||
128 | /** |
||
129 | * The names of the loaded service providers. |
||
130 | * |
||
131 | * @var array $loadServiceProviders |
||
132 | */ |
||
133 | protected $loadServiceProviders = []; |
||
134 | |||
135 | /** |
||
136 | * All of the registered services providers. |
||
137 | * |
||
138 | * @var \Syscodes\Support\ServiceProvider[] $serviceProviders |
||
139 | */ |
||
140 | protected $serviceProviders = []; |
||
141 | |||
142 | /** |
||
143 | * Constructor. Create a new Application instance. |
||
144 | * |
||
145 | * @param string|null $path |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | public function __construct($path = null) |
||
150 | { |
||
151 | if ($path) |
||
152 | { |
||
153 | $this->setBasePath($path); |
||
154 | } |
||
155 | |||
156 | $this->registerBaseBindings(); |
||
157 | $this->registerBaseServiceProviders(); |
||
158 | $this->registerCoreContainerAliases(); |
||
159 | $this->requerimentVersion(static::$phpVersion); |
||
160 | $this->getExtensionLoaded(['mbstring']); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Throw an HttpException with the given data. |
||
165 | * |
||
166 | * @param int $code |
||
167 | * @param string $message |
||
168 | * @param array $headers |
||
169 | * |
||
170 | * @return void |
||
171 | * |
||
172 | * @throws \Syscodes\Core\Http\Exceptions\NotFoundHttpException |
||
173 | * @throws \Syscodes\Core\Http\Exceptions\HttpException |
||
174 | */ |
||
175 | public function abort($code, $message = '', array $headers = []) |
||
176 | { |
||
177 | // Convert the first letter in capital |
||
178 | $message = ucfirst($message); |
||
179 | |||
180 | if ($code == 404) { |
||
181 | throw new NotFoundHttpException($message); |
||
182 | } |
||
183 | |||
184 | throw new HttpException($code, $message, null, $headers); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Set the base path for the application. |
||
189 | * |
||
190 | * @param string $path |
||
191 | * |
||
192 | * @return $this |
||
193 | */ |
||
194 | public function setBasePath(string $path) |
||
195 | { |
||
196 | $this->basePath = rtrim($path, '\/'); |
||
197 | |||
198 | $this->bindContainerPaths(); |
||
199 | |||
200 | return $this; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Register all of the base service providers. |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | protected function registerBaseServiceProviders() |
||
209 | { |
||
210 | $this->register(new EventServiceProvider($this)); |
||
211 | $this->register(new LoggerServiceProvider($this)); |
||
212 | $this->register(new RoutingServiceProvider($this)); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Bind all of the application paths in the container. |
||
217 | * |
||
218 | * @return void |
||
219 | */ |
||
220 | protected function bindContainerPaths() |
||
221 | { |
||
222 | $this->instance('path', $this->path()); |
||
223 | $this->instance('path.base', $this->basePath()); |
||
224 | $this->instance('path.lang', $this->langPath()); |
||
225 | $this->instance('path.config', $this->configPath()); |
||
226 | $this->instance('path.public', $this->publicPath()); |
||
227 | $this->instance('path.storage', $this->storagePath()); |
||
228 | $this->instance('path.database', $this->databasePath()); |
||
229 | $this->instance('path.resources', $this->resourcePath()); |
||
230 | $this->instance('path.bootstrap', $this->bootstrapPath()); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Get the path to the application "app" directory. |
||
235 | * |
||
236 | * @param string $path |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | public function path($path = '') |
||
241 | { |
||
242 | $appPath = $this->basePath.DIRECTORY_SEPARATOR.'app'; |
||
243 | |||
244 | return $appPath.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Get the base path of the Lenevor installation. |
||
249 | * |
||
250 | * @param string $path Optionally, a path to append to the base path |
||
251 | * |
||
252 | * @return string |
||
253 | */ |
||
254 | public function basePath($path = '') |
||
255 | { |
||
256 | return $this->basePath.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Get the path to the bootstrap directory. |
||
261 | * |
||
262 | * @param string $path Optionally, a path to append to the bootstrap path |
||
263 | * |
||
264 | * @return string |
||
265 | */ |
||
266 | public function bootstrapPath($path = '') |
||
267 | { |
||
268 | return $this->basePath.DIRECTORY_SEPARATOR.'bootstrap'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Get the path to the application configuration files. |
||
273 | * |
||
274 | * @param string $path Optionally, a path to append to the config path |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | public function configPath($path = '') |
||
279 | { |
||
280 | return $this->basePath.DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Get the path to the database directory. |
||
285 | * |
||
286 | * @param string $path Optionally, a path to append to the database path |
||
287 | * |
||
288 | * @return string |
||
289 | */ |
||
290 | public function databasePath($path = '') |
||
291 | { |
||
292 | return $this->basePath.DIRECTORY_SEPARATOR.'database'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * Get the path to the lang directory. |
||
297 | * |
||
298 | * @return string |
||
299 | */ |
||
300 | public function langPath() |
||
301 | { |
||
302 | return $this->resourcePath().DIRECTORY_SEPARATOR.'lang'; |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Get the path to the public / web directory. |
||
307 | * |
||
308 | * @return string |
||
309 | */ |
||
310 | public function publicPath() |
||
311 | { |
||
312 | return $this->basePath.DIRECTORY_SEPARATOR.'public'; |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * Get the path to the resources directory. |
||
317 | * |
||
318 | * @param string $path $path Optionally, a path to append to the resources path |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function resourcePath($path = '') |
||
323 | { |
||
324 | return $this->basePath.DIRECTORY_SEPARATOR.'resources'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * Get the path to the storage directory. |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | public function storagePath() |
||
333 | { |
||
334 | return $this->basePath.DIRECTORY_SEPARATOR.'storage'; |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * Run the given array of bootstap classes. |
||
339 | * |
||
340 | * @param string[] $bootstrappers |
||
341 | * |
||
342 | * @return void |
||
343 | */ |
||
344 | public function bootstrapWith(array $bootstrappers) |
||
345 | { |
||
346 | $this->hasBeenBootstrapped = true; |
||
347 | |||
348 | foreach ($bootstrappers as $bootstrapper) { |
||
349 | $this->make($bootstrapper)->bootstrap($this); |
||
350 | } |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * Determine if middleware has been disabled for the application. |
||
355 | * |
||
356 | * @return bool |
||
357 | */ |
||
358 | public function skipGoingMiddleware() |
||
359 | { |
||
360 | return $this->bound('middleware.disable') && |
||
361 | $this->make('middleware.disable') === true; |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Set the directory for the environment file. |
||
366 | * |
||
367 | * @param string $path |
||
368 | * |
||
369 | * @return $this |
||
370 | */ |
||
371 | public function setEnvironmentPath($path) |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * Get the path to the environment file directory. |
||
380 | * |
||
381 | * @return string |
||
382 | */ |
||
383 | public function environmentPath() |
||
384 | { |
||
385 | return $this->environmentPath ?: $this->basePath; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Set the environment file to be loaded during bootstrapping. |
||
390 | * |
||
391 | * @param string $file |
||
392 | * |
||
393 | * @return $this |
||
394 | */ |
||
395 | public function setEnvironmentFile($file) |
||
396 | { |
||
397 | $this->environmentFile = $file; |
||
398 | |||
399 | return $this; |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Get the environment file the application is using. |
||
404 | * |
||
405 | * @return string |
||
406 | */ |
||
407 | public function environmentFile() |
||
408 | { |
||
409 | return $this->environmentFile ?: '.env'; |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Get the fully qualified path to the environment file. |
||
414 | * |
||
415 | * @return string |
||
416 | */ |
||
417 | public function environmentFilePath() |
||
418 | { |
||
419 | return $this->environmentPath().DIRECTORY_SEPARATOR.$this->environmentFile(); |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * Get or check the current application environment. |
||
424 | * |
||
425 | * @param string|array ...$environments |
||
426 | * |
||
427 | * @return string|bool |
||
428 | */ |
||
429 | public function environment(...$environments) |
||
430 | { |
||
431 | if (count($environments) > 0) { |
||
432 | $patterns = is_array($environments[0]) ? $environments[0] : $environments; |
||
433 | |||
434 | return Str::is($patterns, $this->env); |
||
|
|||
435 | } |
||
436 | |||
437 | return $this->env; |
||
438 | } |
||
439 | |||
440 | /** |
||
441 | * Detect the application's current environment. |
||
442 | * |
||
443 | * @param \Closure $callback |
||
444 | * |
||
445 | * @return string |
||
446 | */ |
||
447 | public function detectEnvironment(Closure $callback) |
||
448 | { |
||
449 | return $this->env = (new EnvironmentDetector)->detect($callback); |
||
450 | } |
||
451 | |||
452 | /** |
||
453 | * Determine if application is in local environment. |
||
454 | * |
||
455 | * @return bool |
||
456 | */ |
||
457 | public function isLocal() |
||
458 | { |
||
459 | return $this->env === 'local'; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * Determine if application is in production environment. |
||
464 | * |
||
465 | * @return bool |
||
466 | */ |
||
467 | public function isProduction() |
||
468 | { |
||
469 | return $this->env === 'production'; |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Determine if the application is unit tests. |
||
474 | * |
||
475 | * @return bool |
||
476 | */ |
||
477 | public function isUnitTests() |
||
478 | { |
||
479 | return $this->env === 'testing'; |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Determine if the application is running in the console. |
||
484 | * |
||
485 | * @return bool|null |
||
486 | */ |
||
487 | public function runningInConsole() |
||
488 | { |
||
489 | if (null === $this->isRunningInConsole) { |
||
490 | $this->isRunningInConsole = Environment::get('APP_RUNNING_CONSOLE') ?? isCli(); |
||
491 | } |
||
492 | |||
493 | return $this->isRunningInConsole; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * You can load different configurations depending on your |
||
498 | * current environment. Setting the environment also influences |
||
499 | * things like logging and error reporting. |
||
500 | * |
||
501 | * This can be set to anything, but default usage is: |
||
502 | * local (development) |
||
503 | * testing |
||
504 | * production |
||
505 | * |
||
506 | * @return string |
||
507 | */ |
||
508 | public function bootEnvironment() |
||
509 | { |
||
510 | if (file_exists(SYS_PATH.'src'.DIRECTORY_SEPARATOR.'environment'.DIRECTORY_SEPARATOR.$this->environment().'.php')) { |
||
511 | require_once SYS_PATH.'src'.DIRECTORY_SEPARATOR.'environment'.DIRECTORY_SEPARATOR.$this->environment().'.php'; |
||
512 | } else { |
||
513 | header('HTTP/1.1 503 Service Unavailable.', true, 503); |
||
514 | print('<style> |
||
515 | body { |
||
516 | align-items: center; |
||
517 | background: #FBFCFC; |
||
518 | display: flex; |
||
519 | font-family: verdana, sans-seif; |
||
520 | font-size: .9em; |
||
521 | font-weight: 600; |
||
522 | justify-content: center; |
||
523 | } |
||
524 | |||
525 | p { |
||
526 | background: #F0F3F4; |
||
527 | border-radius: 5px; |
||
528 | box-shadow: 0 1px 4px #333333; |
||
529 | color: #34495E; |
||
530 | padding: 10px; |
||
531 | text-align: center; |
||
532 | text-shadow: 0 1px 0 #424949; |
||
533 | width: 25%; |
||
534 | } |
||
535 | </style> |
||
536 | <p>The application environment is not set correctly.</p>'); |
||
537 | die(); // EXIT_ERROR |
||
538 | } |
||
539 | } |
||
540 | |||
541 | /** |
||
542 | * Determine if the application has been bootstrapped before. |
||
543 | * |
||
544 | * @return bool |
||
545 | */ |
||
546 | public function hasBeenBootstrapped() |
||
547 | { |
||
548 | return $this->hasBeenBootstrapped; |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * You can empty out this file, if you are certain that you match all requirements. |
||
553 | * You can remove this if you are confident that your PHP version is sufficient. |
||
554 | * |
||
555 | * @return string |
||
556 | */ |
||
557 | protected function requerimentVersion($version) |
||
567 | } |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * You can remove this if you are confident you have mbstring installed. |
||
572 | * |
||
573 | * @return string |
||
574 | */ |
||
575 | protected function getExtensionLoaded(array $extensionLoaded) |
||
576 | { |
||
577 | foreach ($extensionLoaded as $value) { |
||
578 | if ( ! extension_loaded($value)) { |
||
579 | if (PHP_SAPI == 'cli') { |
||
580 | $string = "\033[1;36m"; |
||
581 | $string .= "$value\033[0m"; |
||
582 | trigger_error("You must enable the {$string} extension to use Lenevor Framework.".PHP_EOL, E_USER_ERROR); |
||
583 | } |
||
584 | |||
585 | die("You must enable the <b>{$value}</b> extension to use Lenevor Framework."); |
||
586 | } |
||
587 | } |
||
588 | } |
||
589 | |||
590 | /** |
||
591 | * Resolve the given type from the container. |
||
592 | * |
||
593 | * (Overriding Container::make) |
||
594 | * |
||
595 | * @param string $id |
||
596 | * @param array $parameters |
||
597 | * |
||
598 | * @return mixed |
||
599 | */ |
||
600 | public function make($id, array $parameters = []) |
||
601 | { |
||
602 | $id = $this->getAlias($id); |
||
603 | |||
604 | return parent::make($id, $parameters); |
||
605 | } |
||
606 | |||
607 | /** |
||
608 | * Register all of the configured providers. |
||
609 | * |
||
610 | * @return void |
||
611 | */ |
||
612 | public function registerConfiguredProviders() |
||
613 | { |
||
614 | (new ProviderRepository($this)) |
||
615 | ->load($this['config']->get('services.providers')); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Register a service provider. |
||
620 | * |
||
621 | * @param \Syscodes\Support\ServiceProvider|string $provider |
||
622 | * @param bool $force |
||
623 | * |
||
624 | * @return \Syscodes\Support\ServiceProvider |
||
625 | */ |
||
626 | public function register($provider, $force = false) |
||
627 | { |
||
628 | if (($registered = $this->getProviderHasBeenLoaded($provider)) && ! $force) { |
||
629 | return $registered; |
||
630 | } |
||
631 | |||
632 | if (is_string($provider)) { |
||
633 | $provider = $this->resolveProviderClass($provider); |
||
634 | } |
||
635 | |||
636 | $provider->register(); |
||
637 | |||
638 | $this->markAsRegistered($provider); |
||
639 | |||
640 | return $provider; |
||
641 | } |
||
642 | |||
643 | /** |
||
644 | * Get the registered service provider instance if it exists. |
||
645 | * |
||
646 | * @param \Syscodes\Support\ServiceProvider|string $provider |
||
647 | * |
||
648 | * @return \Syscodes\Support\ServiceProvider |
||
649 | */ |
||
650 | protected function getProviderHasBeenLoaded($provider) |
||
651 | { |
||
652 | $name = is_string($provider) ? $provider : get_class($provider); |
||
653 | |||
654 | if (array_key_exists($name, $this->loadServiceProviders)) { |
||
655 | return Arr::first($this->serviceProviders, function($key, $value) use ($name) { |
||
656 | return get_class($value) == $name; |
||
657 | }); |
||
658 | } |
||
659 | } |
||
660 | |||
661 | /** |
||
662 | * Resolve a service provider instance from the class name. |
||
663 | * |
||
664 | * @param string $provider |
||
665 | * |
||
666 | * @return \Syscodes\Support\ServiceProvider |
||
667 | */ |
||
668 | public function resolveProviderClass($provider) |
||
669 | { |
||
670 | return new $provider($this); |
||
671 | } |
||
672 | |||
673 | /** |
||
674 | * Mark the given provider as registered. |
||
675 | * |
||
676 | * @param \Syscodes\Support\ServiceProvider $provider |
||
677 | * |
||
678 | * @return void |
||
679 | */ |
||
680 | protected function markAsRegistered($provider) |
||
681 | { |
||
682 | $this->serviceProviders[] = $provider; |
||
683 | |||
684 | $this->loadServiceProviders[get_class($provider)] = true; |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Determine if the given id type has been bound. |
||
689 | * |
||
690 | * @param string $id |
||
691 | * |
||
692 | * @return bool |
||
693 | */ |
||
694 | public function bound($id) |
||
695 | { |
||
696 | return parent::bound($id); |
||
697 | } |
||
698 | |||
699 | /** |
||
700 | * Determine if the application has booted. |
||
701 | * |
||
702 | * @return bool |
||
703 | */ |
||
704 | public function isBooted() |
||
705 | { |
||
706 | return $this->booted; |
||
707 | } |
||
708 | |||
709 | /** |
||
710 | * Boot the application´s service providers. |
||
711 | * |
||
712 | * @return void |
||
713 | */ |
||
714 | public function boot() |
||
715 | { |
||
716 | if ($this->isbooted()) { |
||
717 | return; |
||
718 | } |
||
719 | |||
720 | $this->bootAppCallbacks($this->bootingCallbacks); |
||
721 | |||
722 | array_walk($this->serviceProviders, function ($provider) { |
||
723 | $this->bootProviderClass($provider); |
||
724 | }); |
||
725 | |||
726 | $this->booted = true; |
||
727 | |||
728 | $this->bootAppCallbacks($this->bootedCallbacks); |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * Call the booting callbacks for the application. |
||
733 | * |
||
734 | * @param callable[] $callbacks |
||
735 | * |
||
736 | * @return void |
||
737 | */ |
||
738 | protected function bootAppCallbacks(array $callbacks) |
||
739 | { |
||
740 | foreach ($callbacks as $callback) { |
||
741 | $callback($this); |
||
742 | } |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * Boot the given service provider. |
||
747 | * |
||
748 | * @param \Syscodes\Support\ServiceProvider $provider |
||
749 | * |
||
750 | * @return mixed |
||
751 | */ |
||
752 | protected function bootProviderClass(ServiceProvider $provider) |
||
753 | { |
||
754 | if (method_exists($provider, 'boot')) |
||
755 | { |
||
756 | $provider->boot(); |
||
757 | } |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * Register a new boot listener. |
||
762 | * |
||
763 | * @param callable $callback |
||
764 | * |
||
765 | * @return void |
||
766 | */ |
||
767 | public function booting($callback) |
||
768 | { |
||
769 | $this->bootingCallbacks[] = $callback; |
||
770 | } |
||
771 | |||
772 | /** |
||
773 | * Register a new 'booted' listener. |
||
774 | * |
||
775 | * @param callable $callback |
||
776 | * |
||
777 | * @return void |
||
778 | */ |
||
779 | public function booted($callback) |
||
780 | { |
||
781 | $this->bootedCallbacks[] = $callback; |
||
782 | |||
783 | if ($this->isBooted()) { |
||
784 | $this->bootAppCallbacks([$callback]); |
||
785 | } |
||
786 | } |
||
787 | |||
788 | /** |
||
789 | * Get the current application locale. |
||
790 | * |
||
791 | * @return string |
||
792 | */ |
||
793 | public function getLocale() |
||
794 | { |
||
795 | return $this['config']->get('app.locale'); |
||
796 | } |
||
797 | |||
798 | /** |
||
799 | * Get the current application fallback locale. |
||
800 | * |
||
801 | * @return string |
||
802 | */ |
||
803 | public function getFallbackLocale() |
||
804 | { |
||
805 | return $this['config']->get('app.fallbackLocale'); |
||
806 | } |
||
807 | |||
808 | /** |
||
809 | * Determine if application locale is the given locale. |
||
810 | * |
||
811 | * @param string $locale |
||
812 | * |
||
813 | * @return bool |
||
814 | */ |
||
815 | public function isLocale($locale) |
||
816 | { |
||
817 | return $this->getLocale() == $locale; |
||
818 | } |
||
819 | |||
820 | /** |
||
821 | * Register the basic bindings into the container. |
||
822 | * |
||
823 | * @return void |
||
824 | */ |
||
825 | public function registerBaseBindings() |
||
826 | { |
||
827 | static::setInstance($this); |
||
828 | |||
829 | $this->instance('app', $this); |
||
830 | |||
831 | $this->instance('config', $this[\Syscodes\Config\Configure::class]); |
||
832 | } |
||
833 | |||
834 | /** |
||
835 | * Register the core class aliases in the container. |
||
836 | * |
||
837 | * @return void |
||
838 | */ |
||
839 | public function registerCoreContainerAliases() |
||
865 | } |
||
866 | } |
||
867 | } |
||
868 | } |