Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Revision 399 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation;
4
 
5
use Closure;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
8
use Illuminate\Contracts\Foundation\CachesConfiguration;
9
use Illuminate\Contracts\Foundation\CachesRoutes;
10
use Illuminate\Contracts\Foundation\MaintenanceMode as MaintenanceModeContract;
11
use Illuminate\Contracts\Http\Kernel as HttpKernelContract;
12
use Illuminate\Events\EventServiceProvider;
13
use Illuminate\Filesystem\Filesystem;
14
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
15
use Illuminate\Foundation\Events\LocaleUpdated;
16
use Illuminate\Http\Request;
17
use Illuminate\Log\LogServiceProvider;
18
use Illuminate\Routing\RoutingServiceProvider;
19
use Illuminate\Support\Arr;
20
use Illuminate\Support\Collection;
21
use Illuminate\Support\Env;
22
use Illuminate\Support\ServiceProvider;
23
use Illuminate\Support\Str;
24
use Illuminate\Support\Traits\Macroable;
25
use RuntimeException;
26
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
27
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
28
use Symfony\Component\HttpKernel\Exception\HttpException;
29
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30
use Symfony\Component\HttpKernel\HttpKernelInterface;
31
 
32
class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
33
{
34
    use Macroable;
35
 
36
    /**
37
     * The Laravel framework version.
38
     *
39
     * @var string
40
     */
150 lars 41
    const VERSION = '9.48.0';
148 lars 42
 
43
    /**
44
     * The base path for the Laravel installation.
45
     *
46
     * @var string
47
     */
48
    protected $basePath;
49
 
50
    /**
51
     * Indicates if the application has been bootstrapped before.
52
     *
53
     * @var bool
54
     */
55
    protected $hasBeenBootstrapped = false;
56
 
57
    /**
58
     * Indicates if the application has "booted".
59
     *
60
     * @var bool
61
     */
62
    protected $booted = false;
63
 
64
    /**
65
     * The array of booting callbacks.
66
     *
67
     * @var callable[]
68
     */
69
    protected $bootingCallbacks = [];
70
 
71
    /**
72
     * The array of booted callbacks.
73
     *
74
     * @var callable[]
75
     */
76
    protected $bootedCallbacks = [];
77
 
78
    /**
79
     * The array of terminating callbacks.
80
     *
81
     * @var callable[]
82
     */
83
    protected $terminatingCallbacks = [];
84
 
85
    /**
86
     * All of the registered service providers.
87
     *
88
     * @var \Illuminate\Support\ServiceProvider[]
89
     */
90
    protected $serviceProviders = [];
91
 
92
    /**
93
     * The names of the loaded service providers.
94
     *
95
     * @var array
96
     */
97
    protected $loadedProviders = [];
98
 
99
    /**
100
     * The deferred services and their providers.
101
     *
102
     * @var array
103
     */
104
    protected $deferredServices = [];
105
 
106
    /**
107
     * The custom application path defined by the developer.
108
     *
109
     * @var string
110
     */
111
    protected $appPath;
112
 
113
    /**
114
     * The custom database path defined by the developer.
115
     *
116
     * @var string
117
     */
118
    protected $databasePath;
119
 
120
    /**
121
     * The custom language file path defined by the developer.
122
     *
123
     * @var string
124
     */
125
    protected $langPath;
126
 
127
    /**
128
     * The custom storage path defined by the developer.
129
     *
130
     * @var string
131
     */
132
    protected $storagePath;
133
 
134
    /**
135
     * The custom environment path defined by the developer.
136
     *
137
     * @var string
138
     */
139
    protected $environmentPath;
140
 
141
    /**
142
     * The environment file to load during bootstrapping.
143
     *
144
     * @var string
145
     */
146
    protected $environmentFile = '.env';
147
 
148
    /**
149
     * Indicates if the application is running in the console.
150
     *
151
     * @var bool|null
152
     */
153
    protected $isRunningInConsole;
154
 
155
    /**
156
     * The application namespace.
157
     *
158
     * @var string
159
     */
160
    protected $namespace;
161
 
162
    /**
163
     * The prefixes of absolute cache paths for use during normalization.
164
     *
165
     * @var string[]
166
     */
167
    protected $absoluteCachePathPrefixes = ['/', '\\'];
168
 
169
    /**
170
     * Create a new Illuminate application instance.
171
     *
172
     * @param  string|null  $basePath
173
     * @return void
174
     */
175
    public function __construct($basePath = null)
176
    {
177
        if ($basePath) {
178
            $this->setBasePath($basePath);
179
        }
180
 
181
        $this->registerBaseBindings();
182
        $this->registerBaseServiceProviders();
183
        $this->registerCoreContainerAliases();
184
    }
185
 
186
    /**
187
     * Get the version number of the application.
188
     *
189
     * @return string
190
     */
191
    public function version()
192
    {
193
        return static::VERSION;
194
    }
195
 
196
    /**
197
     * Register the basic bindings into the container.
198
     *
199
     * @return void
200
     */
201
    protected function registerBaseBindings()
202
    {
203
        static::setInstance($this);
204
 
205
        $this->instance('app', $this);
206
 
207
        $this->instance(Container::class, $this);
208
        $this->singleton(Mix::class);
209
 
210
        $this->singleton(PackageManifest::class, function () {
211
            return new PackageManifest(
212
                new Filesystem, $this->basePath(), $this->getCachedPackagesPath()
213
            );
214
        });
215
    }
216
 
217
    /**
218
     * Register all of the base service providers.
219
     *
220
     * @return void
221
     */
222
    protected function registerBaseServiceProviders()
223
    {
224
        $this->register(new EventServiceProvider($this));
225
        $this->register(new LogServiceProvider($this));
226
        $this->register(new RoutingServiceProvider($this));
227
    }
228
 
229
    /**
230
     * Run the given array of bootstrap classes.
231
     *
232
     * @param  string[]  $bootstrappers
233
     * @return void
234
     */
235
    public function bootstrapWith(array $bootstrappers)
236
    {
237
        $this->hasBeenBootstrapped = true;
238
 
239
        foreach ($bootstrappers as $bootstrapper) {
240
            $this['events']->dispatch('bootstrapping: '.$bootstrapper, [$this]);
241
 
242
            $this->make($bootstrapper)->bootstrap($this);
243
 
244
            $this['events']->dispatch('bootstrapped: '.$bootstrapper, [$this]);
245
        }
246
    }
247
 
248
    /**
249
     * Register a callback to run after loading the environment.
250
     *
251
     * @param  \Closure  $callback
252
     * @return void
253
     */
254
    public function afterLoadingEnvironment(Closure $callback)
255
    {
256
        $this->afterBootstrapping(
257
            LoadEnvironmentVariables::class, $callback
258
        );
259
    }
260
 
261
    /**
262
     * Register a callback to run before a bootstrapper.
263
     *
264
     * @param  string  $bootstrapper
265
     * @param  \Closure  $callback
266
     * @return void
267
     */
268
    public function beforeBootstrapping($bootstrapper, Closure $callback)
269
    {
270
        $this['events']->listen('bootstrapping: '.$bootstrapper, $callback);
271
    }
272
 
273
    /**
274
     * Register a callback to run after a bootstrapper.
275
     *
276
     * @param  string  $bootstrapper
277
     * @param  \Closure  $callback
278
     * @return void
279
     */
280
    public function afterBootstrapping($bootstrapper, Closure $callback)
281
    {
282
        $this['events']->listen('bootstrapped: '.$bootstrapper, $callback);
283
    }
284
 
285
    /**
286
     * Determine if the application has been bootstrapped before.
287
     *
288
     * @return bool
289
     */
290
    public function hasBeenBootstrapped()
291
    {
292
        return $this->hasBeenBootstrapped;
293
    }
294
 
295
    /**
296
     * Set the base path for the application.
297
     *
298
     * @param  string  $basePath
299
     * @return $this
300
     */
301
    public function setBasePath($basePath)
302
    {
303
        $this->basePath = rtrim($basePath, '\/');
304
 
305
        $this->bindPathsInContainer();
306
 
307
        return $this;
308
    }
309
 
310
    /**
311
     * Bind all of the application paths in the container.
312
     *
313
     * @return void
314
     */
315
    protected function bindPathsInContainer()
316
    {
317
        $this->instance('path', $this->path());
318
        $this->instance('path.base', $this->basePath());
319
        $this->instance('path.config', $this->configPath());
320
        $this->instance('path.public', $this->publicPath());
321
        $this->instance('path.storage', $this->storagePath());
322
        $this->instance('path.database', $this->databasePath());
323
        $this->instance('path.resources', $this->resourcePath());
324
        $this->instance('path.bootstrap', $this->bootstrapPath());
325
 
326
        $this->useLangPath(value(function () {
327
            if (is_dir($directory = $this->resourcePath('lang'))) {
328
                return $directory;
329
            }
330
 
331
            return $this->basePath('lang');
332
        }));
333
    }
334
 
335
    /**
336
     * Get the path to the application "app" directory.
337
     *
338
     * @param  string  $path
339
     * @return string
340
     */
341
    public function path($path = '')
342
    {
343
        $appPath = $this->appPath ?: $this->basePath.DIRECTORY_SEPARATOR.'app';
344
 
345
        return $appPath.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
346
    }
347
 
348
    /**
349
     * Set the application directory.
350
     *
351
     * @param  string  $path
352
     * @return $this
353
     */
354
    public function useAppPath($path)
355
    {
356
        $this->appPath = $path;
357
 
358
        $this->instance('path', $path);
359
 
360
        return $this;
361
    }
362
 
363
    /**
364
     * Get the base path of the Laravel installation.
365
     *
366
     * @param  string  $path
367
     * @return string
368
     */
369
    public function basePath($path = '')
370
    {
371
        return $this->basePath.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
372
    }
373
 
374
    /**
375
     * Get the path to the bootstrap directory.
376
     *
377
     * @param  string  $path
378
     * @return string
379
     */
380
    public function bootstrapPath($path = '')
381
    {
382
        return $this->basePath.DIRECTORY_SEPARATOR.'bootstrap'.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
383
    }
384
 
385
    /**
386
     * Get the path to the application configuration files.
387
     *
388
     * @param  string  $path
389
     * @return string
390
     */
391
    public function configPath($path = '')
392
    {
393
        return $this->basePath.DIRECTORY_SEPARATOR.'config'.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
394
    }
395
 
396
    /**
397
     * Get the path to the database directory.
398
     *
399
     * @param  string  $path
400
     * @return string
401
     */
402
    public function databasePath($path = '')
403
    {
404
        return ($this->databasePath ?: $this->basePath.DIRECTORY_SEPARATOR.'database').($path != '' ? DIRECTORY_SEPARATOR.$path : '');
405
    }
406
 
407
    /**
408
     * Set the database directory.
409
     *
410
     * @param  string  $path
411
     * @return $this
412
     */
413
    public function useDatabasePath($path)
414
    {
415
        $this->databasePath = $path;
416
 
417
        $this->instance('path.database', $path);
418
 
419
        return $this;
420
    }
421
 
422
    /**
423
     * Get the path to the language files.
424
     *
425
     * @param  string  $path
426
     * @return string
427
     */
428
    public function langPath($path = '')
429
    {
430
        return $this->langPath.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
431
    }
432
 
433
    /**
434
     * Set the language file directory.
435
     *
436
     * @param  string  $path
437
     * @return $this
438
     */
439
    public function useLangPath($path)
440
    {
441
        $this->langPath = $path;
442
 
443
        $this->instance('path.lang', $path);
444
 
445
        return $this;
446
    }
447
 
448
    /**
449
     * Get the path to the public / web directory.
450
     *
451
     * @return string
452
     */
453
    public function publicPath()
454
    {
455
        return $this->basePath.DIRECTORY_SEPARATOR.'public';
456
    }
457
 
458
    /**
459
     * Get the path to the storage directory.
460
     *
461
     * @param  string  $path
462
     * @return string
463
     */
464
    public function storagePath($path = '')
465
    {
466
        return ($this->storagePath ?: $this->basePath.DIRECTORY_SEPARATOR.'storage')
467
                            .($path != '' ? DIRECTORY_SEPARATOR.$path : '');
468
    }
469
 
470
    /**
471
     * Set the storage directory.
472
     *
473
     * @param  string  $path
474
     * @return $this
475
     */
476
    public function useStoragePath($path)
477
    {
478
        $this->storagePath = $path;
479
 
480
        $this->instance('path.storage', $path);
481
 
482
        return $this;
483
    }
484
 
485
    /**
486
     * Get the path to the resources directory.
487
     *
488
     * @param  string  $path
489
     * @return string
490
     */
491
    public function resourcePath($path = '')
492
    {
493
        return $this->basePath.DIRECTORY_SEPARATOR.'resources'.($path != '' ? DIRECTORY_SEPARATOR.$path : '');
494
    }
495
 
496
    /**
497
     * Get the path to the views directory.
498
     *
499
     * This method returns the first configured path in the array of view paths.
500
     *
501
     * @param  string  $path
502
     * @return string
503
     */
504
    public function viewPath($path = '')
505
    {
506
        $basePath = $this['config']->get('view.paths')[0];
507
 
508
        return rtrim($basePath, DIRECTORY_SEPARATOR).($path != '' ? DIRECTORY_SEPARATOR.$path : '');
509
    }
510
 
511
    /**
512
     * Get the path to the environment file directory.
513
     *
514
     * @return string
515
     */
516
    public function environmentPath()
517
    {
518
        return $this->environmentPath ?: $this->basePath;
519
    }
520
 
521
    /**
522
     * Set the directory for the environment file.
523
     *
524
     * @param  string  $path
525
     * @return $this
526
     */
527
    public function useEnvironmentPath($path)
528
    {
529
        $this->environmentPath = $path;
530
 
531
        return $this;
532
    }
533
 
534
    /**
535
     * Set the environment file to be loaded during bootstrapping.
536
     *
537
     * @param  string  $file
538
     * @return $this
539
     */
540
    public function loadEnvironmentFrom($file)
541
    {
542
        $this->environmentFile = $file;
543
 
544
        return $this;
545
    }
546
 
547
    /**
548
     * Get the environment file the application is using.
549
     *
550
     * @return string
551
     */
552
    public function environmentFile()
553
    {
554
        return $this->environmentFile ?: '.env';
555
    }
556
 
557
    /**
558
     * Get the fully qualified path to the environment file.
559
     *
560
     * @return string
561
     */
562
    public function environmentFilePath()
563
    {
564
        return $this->environmentPath().DIRECTORY_SEPARATOR.$this->environmentFile();
565
    }
566
 
567
    /**
568
     * Get or check the current application environment.
569
     *
570
     * @param  string|array  $environments
571
     * @return string|bool
572
     */
573
    public function environment(...$environments)
574
    {
575
        if (count($environments) > 0) {
576
            $patterns = is_array($environments[0]) ? $environments[0] : $environments;
577
 
578
            return Str::is($patterns, $this['env']);
579
        }
580
 
581
        return $this['env'];
582
    }
583
 
584
    /**
585
     * Determine if the application is in the local environment.
586
     *
587
     * @return bool
588
     */
589
    public function isLocal()
590
    {
591
        return $this['env'] === 'local';
592
    }
593
 
594
    /**
595
     * Determine if the application is in the production environment.
596
     *
597
     * @return bool
598
     */
599
    public function isProduction()
600
    {
601
        return $this['env'] === 'production';
602
    }
603
 
604
    /**
605
     * Detect the application's current environment.
606
     *
607
     * @param  \Closure  $callback
608
     * @return string
609
     */
610
    public function detectEnvironment(Closure $callback)
611
    {
612
        $args = $_SERVER['argv'] ?? null;
613
 
614
        return $this['env'] = (new EnvironmentDetector)->detect($callback, $args);
615
    }
616
 
617
    /**
618
     * Determine if the application is running in the console.
619
     *
620
     * @return bool
621
     */
622
    public function runningInConsole()
623
    {
624
        if ($this->isRunningInConsole === null) {
625
            $this->isRunningInConsole = Env::get('APP_RUNNING_IN_CONSOLE') ?? (\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg');
626
        }
627
 
628
        return $this->isRunningInConsole;
629
    }
630
 
631
    /**
632
     * Determine if the application is running unit tests.
633
     *
634
     * @return bool
635
     */
636
    public function runningUnitTests()
637
    {
638
        return $this->bound('env') && $this['env'] === 'testing';
639
    }
640
 
641
    /**
642
     * Determine if the application is running with debug mode enabled.
643
     *
644
     * @return bool
645
     */
646
    public function hasDebugModeEnabled()
647
    {
648
        return (bool) $this['config']->get('app.debug');
649
    }
650
 
651
    /**
652
     * Register all of the configured providers.
653
     *
654
     * @return void
655
     */
656
    public function registerConfiguredProviders()
657
    {
658
        $providers = Collection::make($this->make('config')->get('app.providers'))
659
                        ->partition(function ($provider) {
660
                            return str_starts_with($provider, 'Illuminate\\');
661
                        });
662
 
663
        $providers->splice(1, 0, [$this->make(PackageManifest::class)->providers()]);
664
 
665
        (new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))
666
                    ->load($providers->collapse()->toArray());
667
    }
668
 
669
    /**
670
     * Register a service provider with the application.
671
     *
672
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
673
     * @param  bool  $force
674
     * @return \Illuminate\Support\ServiceProvider
675
     */
676
    public function register($provider, $force = false)
677
    {
678
        if (($registered = $this->getProvider($provider)) && ! $force) {
679
            return $registered;
680
        }
681
 
682
        // If the given "provider" is a string, we will resolve it, passing in the
683
        // application instance automatically for the developer. This is simply
684
        // a more convenient way of specifying your service provider classes.
685
        if (is_string($provider)) {
686
            $provider = $this->resolveProvider($provider);
687
        }
688
 
689
        $provider->register();
690
 
691
        // If there are bindings / singletons set as properties on the provider we
692
        // will spin through them and register them with the application, which
693
        // serves as a convenience layer while registering a lot of bindings.
694
        if (property_exists($provider, 'bindings')) {
695
            foreach ($provider->bindings as $key => $value) {
696
                $this->bind($key, $value);
697
            }
698
        }
699
 
700
        if (property_exists($provider, 'singletons')) {
701
            foreach ($provider->singletons as $key => $value) {
702
                $key = is_int($key) ? $value : $key;
703
 
704
                $this->singleton($key, $value);
705
            }
706
        }
707
 
708
        $this->markAsRegistered($provider);
709
 
710
        // If the application has already booted, we will call this boot method on
711
        // the provider class so it has an opportunity to do its boot logic and
712
        // will be ready for any usage by this developer's application logic.
713
        if ($this->isBooted()) {
714
            $this->bootProvider($provider);
715
        }
716
 
717
        return $provider;
718
    }
719
 
720
    /**
721
     * Get the registered service provider instance if it exists.
722
     *
723
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
724
     * @return \Illuminate\Support\ServiceProvider|null
725
     */
726
    public function getProvider($provider)
727
    {
728
        return array_values($this->getProviders($provider))[0] ?? null;
729
    }
730
 
731
    /**
732
     * Get the registered service provider instances if any exist.
733
     *
734
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
735
     * @return array
736
     */
737
    public function getProviders($provider)
738
    {
739
        $name = is_string($provider) ? $provider : get_class($provider);
740
 
741
        return Arr::where($this->serviceProviders, function ($value) use ($name) {
742
            return $value instanceof $name;
743
        });
744
    }
745
 
746
    /**
747
     * Resolve a service provider instance from the class name.
748
     *
749
     * @param  string  $provider
750
     * @return \Illuminate\Support\ServiceProvider
751
     */
752
    public function resolveProvider($provider)
753
    {
754
        return new $provider($this);
755
    }
756
 
757
    /**
758
     * Mark the given provider as registered.
759
     *
760
     * @param  \Illuminate\Support\ServiceProvider  $provider
761
     * @return void
762
     */
763
    protected function markAsRegistered($provider)
764
    {
765
        $this->serviceProviders[] = $provider;
766
 
767
        $this->loadedProviders[get_class($provider)] = true;
768
    }
769
 
770
    /**
771
     * Load and boot all of the remaining deferred providers.
772
     *
773
     * @return void
774
     */
775
    public function loadDeferredProviders()
776
    {
777
        // We will simply spin through each of the deferred providers and register each
778
        // one and boot them if the application has booted. This should make each of
779
        // the remaining services available to this application for immediate use.
780
        foreach ($this->deferredServices as $service => $provider) {
781
            $this->loadDeferredProvider($service);
782
        }
783
 
784
        $this->deferredServices = [];
785
    }
786
 
787
    /**
788
     * Load the provider for a deferred service.
789
     *
790
     * @param  string  $service
791
     * @return void
792
     */
793
    public function loadDeferredProvider($service)
794
    {
795
        if (! $this->isDeferredService($service)) {
796
            return;
797
        }
798
 
799
        $provider = $this->deferredServices[$service];
800
 
801
        // If the service provider has not already been loaded and registered we can
802
        // register it with the application and remove the service from this list
803
        // of deferred services, since it will already be loaded on subsequent.
804
        if (! isset($this->loadedProviders[$provider])) {
805
            $this->registerDeferredProvider($provider, $service);
806
        }
807
    }
808
 
809
    /**
810
     * Register a deferred provider and service.
811
     *
812
     * @param  string  $provider
813
     * @param  string|null  $service
814
     * @return void
815
     */
816
    public function registerDeferredProvider($provider, $service = null)
817
    {
818
        // Once the provider that provides the deferred service has been registered we
819
        // will remove it from our local list of the deferred services with related
820
        // providers so that this container does not try to resolve it out again.
821
        if ($service) {
822
            unset($this->deferredServices[$service]);
823
        }
824
 
825
        $this->register($instance = new $provider($this));
826
 
827
        if (! $this->isBooted()) {
828
            $this->booting(function () use ($instance) {
829
                $this->bootProvider($instance);
830
            });
831
        }
832
    }
833
 
834
    /**
835
     * Resolve the given type from the container.
836
     *
837
     * @param  string  $abstract
838
     * @param  array  $parameters
839
     * @return mixed
840
     */
841
    public function make($abstract, array $parameters = [])
842
    {
843
        $this->loadDeferredProviderIfNeeded($abstract = $this->getAlias($abstract));
844
 
845
        return parent::make($abstract, $parameters);
846
    }
847
 
848
    /**
849
     * Resolve the given type from the container.
850
     *
851
     * @param  string  $abstract
852
     * @param  array  $parameters
853
     * @param  bool  $raiseEvents
854
     * @return mixed
855
     */
856
    protected function resolve($abstract, $parameters = [], $raiseEvents = true)
857
    {
858
        $this->loadDeferredProviderIfNeeded($abstract = $this->getAlias($abstract));
859
 
860
        return parent::resolve($abstract, $parameters, $raiseEvents);
861
    }
862
 
863
    /**
864
     * Load the deferred provider if the given type is a deferred service and the instance has not been loaded.
865
     *
866
     * @param  string  $abstract
867
     * @return void
868
     */
869
    protected function loadDeferredProviderIfNeeded($abstract)
870
    {
871
        if ($this->isDeferredService($abstract) && ! isset($this->instances[$abstract])) {
872
            $this->loadDeferredProvider($abstract);
873
        }
874
    }
875
 
876
    /**
877
     * Determine if the given abstract type has been bound.
878
     *
879
     * @param  string  $abstract
880
     * @return bool
881
     */
882
    public function bound($abstract)
883
    {
884
        return $this->isDeferredService($abstract) || parent::bound($abstract);
885
    }
886
 
887
    /**
888
     * Determine if the application has booted.
889
     *
890
     * @return bool
891
     */
892
    public function isBooted()
893
    {
894
        return $this->booted;
895
    }
896
 
897
    /**
898
     * Boot the application's service providers.
899
     *
900
     * @return void
901
     */
902
    public function boot()
903
    {
904
        if ($this->isBooted()) {
905
            return;
906
        }
907
 
908
        // Once the application has booted we will also fire some "booted" callbacks
909
        // for any listeners that need to do work after this initial booting gets
910
        // finished. This is useful when ordering the boot-up processes we run.
911
        $this->fireAppCallbacks($this->bootingCallbacks);
912
 
913
        array_walk($this->serviceProviders, function ($p) {
914
            $this->bootProvider($p);
915
        });
916
 
917
        $this->booted = true;
918
 
919
        $this->fireAppCallbacks($this->bootedCallbacks);
920
    }
921
 
922
    /**
923
     * Boot the given service provider.
924
     *
925
     * @param  \Illuminate\Support\ServiceProvider  $provider
926
     * @return void
927
     */
928
    protected function bootProvider(ServiceProvider $provider)
929
    {
930
        $provider->callBootingCallbacks();
931
 
932
        if (method_exists($provider, 'boot')) {
933
            $this->call([$provider, 'boot']);
934
        }
935
 
936
        $provider->callBootedCallbacks();
937
    }
938
 
939
    /**
940
     * Register a new boot listener.
941
     *
942
     * @param  callable  $callback
943
     * @return void
944
     */
945
    public function booting($callback)
946
    {
947
        $this->bootingCallbacks[] = $callback;
948
    }
949
 
950
    /**
951
     * Register a new "booted" listener.
952
     *
953
     * @param  callable  $callback
954
     * @return void
955
     */
956
    public function booted($callback)
957
    {
958
        $this->bootedCallbacks[] = $callback;
959
 
960
        if ($this->isBooted()) {
961
            $callback($this);
962
        }
963
    }
964
 
965
    /**
966
     * Call the booting callbacks for the application.
967
     *
968
     * @param  callable[]  $callbacks
969
     * @return void
970
     */
971
    protected function fireAppCallbacks(array &$callbacks)
972
    {
973
        $index = 0;
974
 
975
        while ($index < count($callbacks)) {
976
            $callbacks[$index]($this);
977
 
978
            $index++;
979
        }
980
    }
981
 
982
    /**
983
     * {@inheritdoc}
984
     *
985
     * @return \Symfony\Component\HttpFoundation\Response
986
     */
987
    public function handle(SymfonyRequest $request, int $type = self::MAIN_REQUEST, bool $catch = true): SymfonyResponse
988
    {
989
        return $this[HttpKernelContract::class]->handle(Request::createFromBase($request));
990
    }
991
 
992
    /**
993
     * Determine if middleware has been disabled for the application.
994
     *
995
     * @return bool
996
     */
997
    public function shouldSkipMiddleware()
998
    {
999
        return $this->bound('middleware.disable') &&
1000
               $this->make('middleware.disable') === true;
1001
    }
1002
 
1003
    /**
1004
     * Get the path to the cached services.php file.
1005
     *
1006
     * @return string
1007
     */
1008
    public function getCachedServicesPath()
1009
    {
1010
        return $this->normalizeCachePath('APP_SERVICES_CACHE', 'cache/services.php');
1011
    }
1012
 
1013
    /**
1014
     * Get the path to the cached packages.php file.
1015
     *
1016
     * @return string
1017
     */
1018
    public function getCachedPackagesPath()
1019
    {
1020
        return $this->normalizeCachePath('APP_PACKAGES_CACHE', 'cache/packages.php');
1021
    }
1022
 
1023
    /**
1024
     * Determine if the application configuration is cached.
1025
     *
1026
     * @return bool
1027
     */
1028
    public function configurationIsCached()
1029
    {
1030
        return is_file($this->getCachedConfigPath());
1031
    }
1032
 
1033
    /**
1034
     * Get the path to the configuration cache file.
1035
     *
1036
     * @return string
1037
     */
1038
    public function getCachedConfigPath()
1039
    {
1040
        return $this->normalizeCachePath('APP_CONFIG_CACHE', 'cache/config.php');
1041
    }
1042
 
1043
    /**
1044
     * Determine if the application routes are cached.
1045
     *
1046
     * @return bool
1047
     */
1048
    public function routesAreCached()
1049
    {
1050
        return $this['files']->exists($this->getCachedRoutesPath());
1051
    }
1052
 
1053
    /**
1054
     * Get the path to the routes cache file.
1055
     *
1056
     * @return string
1057
     */
1058
    public function getCachedRoutesPath()
1059
    {
1060
        return $this->normalizeCachePath('APP_ROUTES_CACHE', 'cache/routes-v7.php');
1061
    }
1062
 
1063
    /**
1064
     * Determine if the application events are cached.
1065
     *
1066
     * @return bool
1067
     */
1068
    public function eventsAreCached()
1069
    {
1070
        return $this['files']->exists($this->getCachedEventsPath());
1071
    }
1072
 
1073
    /**
1074
     * Get the path to the events cache file.
1075
     *
1076
     * @return string
1077
     */
1078
    public function getCachedEventsPath()
1079
    {
1080
        return $this->normalizeCachePath('APP_EVENTS_CACHE', 'cache/events.php');
1081
    }
1082
 
1083
    /**
1084
     * Normalize a relative or absolute path to a cache file.
1085
     *
1086
     * @param  string  $key
1087
     * @param  string  $default
1088
     * @return string
1089
     */
1090
    protected function normalizeCachePath($key, $default)
1091
    {
1092
        if (is_null($env = Env::get($key))) {
1093
            return $this->bootstrapPath($default);
1094
        }
1095
 
1096
        return Str::startsWith($env, $this->absoluteCachePathPrefixes)
1097
                ? $env
1098
                : $this->basePath($env);
1099
    }
1100
 
1101
    /**
1102
     * Add new prefix to list of absolute path prefixes.
1103
     *
1104
     * @param  string  $prefix
1105
     * @return $this
1106
     */
1107
    public function addAbsoluteCachePathPrefix($prefix)
1108
    {
1109
        $this->absoluteCachePathPrefixes[] = $prefix;
1110
 
1111
        return $this;
1112
    }
1113
 
1114
    /**
1115
     * Get an instance of the maintenance mode manager implementation.
1116
     *
1117
     * @return \Illuminate\Contracts\Foundation\MaintenanceMode
1118
     */
1119
    public function maintenanceMode()
1120
    {
1121
        return $this->make(MaintenanceModeContract::class);
1122
    }
1123
 
1124
    /**
1125
     * Determine if the application is currently down for maintenance.
1126
     *
1127
     * @return bool
1128
     */
1129
    public function isDownForMaintenance()
1130
    {
1131
        return $this->maintenanceMode()->active();
1132
    }
1133
 
1134
    /**
1135
     * Throw an HttpException with the given data.
1136
     *
1137
     * @param  int  $code
1138
     * @param  string  $message
1139
     * @param  array  $headers
1140
     * @return never
1141
     *
1142
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
1143
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
1144
     */
1145
    public function abort($code, $message = '', array $headers = [])
1146
    {
1147
        if ($code == 404) {
1148
            throw new NotFoundHttpException($message);
1149
        }
1150
 
1151
        throw new HttpException($code, $message, null, $headers);
1152
    }
1153
 
1154
    /**
1155
     * Register a terminating callback with the application.
1156
     *
1157
     * @param  callable|string  $callback
1158
     * @return $this
1159
     */
1160
    public function terminating($callback)
1161
    {
1162
        $this->terminatingCallbacks[] = $callback;
1163
 
1164
        return $this;
1165
    }
1166
 
1167
    /**
1168
     * Terminate the application.
1169
     *
1170
     * @return void
1171
     */
1172
    public function terminate()
1173
    {
1174
        $index = 0;
1175
 
1176
        while ($index < count($this->terminatingCallbacks)) {
1177
            $this->call($this->terminatingCallbacks[$index]);
1178
 
1179
            $index++;
1180
        }
1181
    }
1182
 
1183
    /**
1184
     * Get the service providers that have been loaded.
1185
     *
1186
     * @return array
1187
     */
1188
    public function getLoadedProviders()
1189
    {
1190
        return $this->loadedProviders;
1191
    }
1192
 
1193
    /**
1194
     * Determine if the given service provider is loaded.
1195
     *
1196
     * @param  string  $provider
1197
     * @return bool
1198
     */
1199
    public function providerIsLoaded(string $provider)
1200
    {
1201
        return isset($this->loadedProviders[$provider]);
1202
    }
1203
 
1204
    /**
1205
     * Get the application's deferred services.
1206
     *
1207
     * @return array
1208
     */
1209
    public function getDeferredServices()
1210
    {
1211
        return $this->deferredServices;
1212
    }
1213
 
1214
    /**
1215
     * Set the application's deferred services.
1216
     *
1217
     * @param  array  $services
1218
     * @return void
1219
     */
1220
    public function setDeferredServices(array $services)
1221
    {
1222
        $this->deferredServices = $services;
1223
    }
1224
 
1225
    /**
1226
     * Add an array of services to the application's deferred services.
1227
     *
1228
     * @param  array  $services
1229
     * @return void
1230
     */
1231
    public function addDeferredServices(array $services)
1232
    {
1233
        $this->deferredServices = array_merge($this->deferredServices, $services);
1234
    }
1235
 
1236
    /**
1237
     * Determine if the given service is a deferred service.
1238
     *
1239
     * @param  string  $service
1240
     * @return bool
1241
     */
1242
    public function isDeferredService($service)
1243
    {
1244
        return isset($this->deferredServices[$service]);
1245
    }
1246
 
1247
    /**
1248
     * Configure the real-time facade namespace.
1249
     *
1250
     * @param  string  $namespace
1251
     * @return void
1252
     */
1253
    public function provideFacades($namespace)
1254
    {
1255
        AliasLoader::setFacadeNamespace($namespace);
1256
    }
1257
 
1258
    /**
1259
     * Get the current application locale.
1260
     *
1261
     * @return string
1262
     */
1263
    public function getLocale()
1264
    {
1265
        return $this['config']->get('app.locale');
1266
    }
1267
 
1268
    /**
1269
     * Get the current application locale.
1270
     *
1271
     * @return string
1272
     */
1273
    public function currentLocale()
1274
    {
1275
        return $this->getLocale();
1276
    }
1277
 
1278
    /**
1279
     * Get the current application fallback locale.
1280
     *
1281
     * @return string
1282
     */
1283
    public function getFallbackLocale()
1284
    {
1285
        return $this['config']->get('app.fallback_locale');
1286
    }
1287
 
1288
    /**
1289
     * Set the current application locale.
1290
     *
1291
     * @param  string  $locale
1292
     * @return void
1293
     */
1294
    public function setLocale($locale)
1295
    {
1296
        $this['config']->set('app.locale', $locale);
1297
 
1298
        $this['translator']->setLocale($locale);
1299
 
1300
        $this['events']->dispatch(new LocaleUpdated($locale));
1301
    }
1302
 
1303
    /**
1304
     * Set the current application fallback locale.
1305
     *
1306
     * @param  string  $fallbackLocale
1307
     * @return void
1308
     */
1309
    public function setFallbackLocale($fallbackLocale)
1310
    {
1311
        $this['config']->set('app.fallback_locale', $fallbackLocale);
1312
 
1313
        $this['translator']->setFallback($fallbackLocale);
1314
    }
1315
 
1316
    /**
1317
     * Determine if the application locale is the given locale.
1318
     *
1319
     * @param  string  $locale
1320
     * @return bool
1321
     */
1322
    public function isLocale($locale)
1323
    {
1324
        return $this->getLocale() == $locale;
1325
    }
1326
 
1327
    /**
1328
     * Register the core class aliases in the container.
1329
     *
1330
     * @return void
1331
     */
1332
    public function registerCoreContainerAliases()
1333
    {
1334
        foreach ([
1335
            'app' => [self::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
1336
            'auth' => [\Illuminate\Auth\AuthManager::class, \Illuminate\Contracts\Auth\Factory::class],
1337
            'auth.driver' => [\Illuminate\Contracts\Auth\Guard::class],
1338
            'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class],
1339
            'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class],
1340
            'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class, \Psr\SimpleCache\CacheInterface::class],
1341
            'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
1342
            'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
1343
            'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
1344
            'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
1345
            'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
1346
            'db.schema' => [\Illuminate\Database\Schema\Builder::class],
1347
            'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class],
1348
            'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
1349
            'files' => [\Illuminate\Filesystem\Filesystem::class],
1350
            'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
1351
            'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
1352
            'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
1353
            'hash' => [\Illuminate\Hashing\HashManager::class],
1354
            'hash.driver' => [\Illuminate\Contracts\Hashing\Hasher::class],
1355
            'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class],
1356
            'log' => [\Illuminate\Log\LogManager::class, \Psr\Log\LoggerInterface::class],
1357
            'mail.manager' => [\Illuminate\Mail\MailManager::class, \Illuminate\Contracts\Mail\Factory::class],
1358
            'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
1359
            'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class],
1360
            'auth.password.broker' => [\Illuminate\Auth\Passwords\PasswordBroker::class, \Illuminate\Contracts\Auth\PasswordBroker::class],
1361
            'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
1362
            'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
1363
            'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
1364
            'redirect' => [\Illuminate\Routing\Redirector::class],
1365
            'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
1366
            'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class],
1367
            'request' => [\Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
1368
            'router' => [\Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
1369
            'session' => [\Illuminate\Session\SessionManager::class],
1370
            'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
1371
            'url' => [\Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
1372
            'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
1373
            'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
1374
        ] as $key => $aliases) {
1375
            foreach ($aliases as $alias) {
1376
                $this->alias($key, $alias);
1377
            }
1378
        }
1379
    }
1380
 
1381
    /**
1382
     * Flush the container of all bindings and resolved instances.
1383
     *
1384
     * @return void
1385
     */
1386
    public function flush()
1387
    {
1388
        parent::flush();
1389
 
1390
        $this->buildStack = [];
1391
        $this->loadedProviders = [];
1392
        $this->bootedCallbacks = [];
1393
        $this->bootingCallbacks = [];
1394
        $this->deferredServices = [];
1395
        $this->reboundCallbacks = [];
1396
        $this->serviceProviders = [];
1397
        $this->resolvingCallbacks = [];
1398
        $this->terminatingCallbacks = [];
1399
        $this->beforeResolvingCallbacks = [];
1400
        $this->afterResolvingCallbacks = [];
1401
        $this->globalBeforeResolvingCallbacks = [];
1402
        $this->globalResolvingCallbacks = [];
1403
        $this->globalAfterResolvingCallbacks = [];
1404
    }
1405
 
1406
    /**
1407
     * Get the application namespace.
1408
     *
1409
     * @return string
1410
     *
1411
     * @throws \RuntimeException
1412
     */
1413
    public function getNamespace()
1414
    {
1415
        if (! is_null($this->namespace)) {
1416
            return $this->namespace;
1417
        }
1418
 
1419
        $composer = json_decode(file_get_contents($this->basePath('composer.json')), true);
1420
 
1421
        foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
1422
            foreach ((array) $path as $pathChoice) {
1423
                if (realpath($this->path()) === realpath($this->basePath($pathChoice))) {
1424
                    return $this->namespace = $namespace;
1425
                }
1426
            }
1427
        }
1428
 
1429
        throw new RuntimeException('Unable to detect application namespace.');
1430
    }
1431
}