PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/laravel/framework/src/Illuminate/Foundation/Application.php

https://gitlab.com/Pasantias/pasantiasASLG
PHP | 1122 lines | 477 code | 144 blank | 501 comment | 24 complexity | 3025d8946c861bfc857b30b8ad94cf97 MD5 | raw file
  1. <?php
  2. namespace Illuminate\Foundation;
  3. use Closure;
  4. use RuntimeException;
  5. use Illuminate\Support\Arr;
  6. use Illuminate\Support\Str;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Container\Container;
  9. use Illuminate\Filesystem\Filesystem;
  10. use Illuminate\Support\ServiceProvider;
  11. use Illuminate\Events\EventServiceProvider;
  12. use Illuminate\Routing\RoutingServiceProvider;
  13. use Symfony\Component\HttpKernel\HttpKernelInterface;
  14. use Symfony\Component\HttpKernel\Exception\HttpException;
  15. use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. use Illuminate\Contracts\Foundation\Application as ApplicationContract;
  18. class Application extends Container implements ApplicationContract, HttpKernelInterface
  19. {
  20. /**
  21. * The Laravel framework version.
  22. *
  23. * @var string
  24. */
  25. const VERSION = '5.1.35 (LTS)';
  26. /**
  27. * The base path for the Laravel installation.
  28. *
  29. * @var string
  30. */
  31. protected $basePath;
  32. /**
  33. * Indicates if the application has been bootstrapped before.
  34. *
  35. * @var bool
  36. */
  37. protected $hasBeenBootstrapped = false;
  38. /**
  39. * Indicates if the application has "booted".
  40. *
  41. * @var bool
  42. */
  43. protected $booted = false;
  44. /**
  45. * The array of booting callbacks.
  46. *
  47. * @var array
  48. */
  49. protected $bootingCallbacks = [];
  50. /**
  51. * The array of booted callbacks.
  52. *
  53. * @var array
  54. */
  55. protected $bootedCallbacks = [];
  56. /**
  57. * The array of terminating callbacks.
  58. *
  59. * @var array
  60. */
  61. protected $terminatingCallbacks = [];
  62. /**
  63. * All of the registered service providers.
  64. *
  65. * @var array
  66. */
  67. protected $serviceProviders = [];
  68. /**
  69. * The names of the loaded service providers.
  70. *
  71. * @var array
  72. */
  73. protected $loadedProviders = [];
  74. /**
  75. * The deferred services and their providers.
  76. *
  77. * @var array
  78. */
  79. protected $deferredServices = [];
  80. /**
  81. * A custom callback used to configure Monolog.
  82. *
  83. * @var callable|null
  84. */
  85. protected $monologConfigurator;
  86. /**
  87. * The custom database path defined by the developer.
  88. *
  89. * @var string
  90. */
  91. protected $databasePath;
  92. /**
  93. * The custom storage path defined by the developer.
  94. *
  95. * @var string
  96. */
  97. protected $storagePath;
  98. /**
  99. * The custom environment path defined by the developer.
  100. *
  101. * @var string
  102. */
  103. protected $environmentPath;
  104. /**
  105. * The environment file to load during bootstrapping.
  106. *
  107. * @var string
  108. */
  109. protected $environmentFile = '.env';
  110. /**
  111. * The application namespace.
  112. *
  113. * @var string
  114. */
  115. protected $namespace = null;
  116. /**
  117. * Create a new Illuminate application instance.
  118. *
  119. * @param string|null $basePath
  120. * @return void
  121. */
  122. public function __construct($basePath = null)
  123. {
  124. $this->registerBaseBindings();
  125. $this->registerBaseServiceProviders();
  126. $this->registerCoreContainerAliases();
  127. if ($basePath) {
  128. $this->setBasePath($basePath);
  129. }
  130. }
  131. /**
  132. * Get the version number of the application.
  133. *
  134. * @return string
  135. */
  136. public function version()
  137. {
  138. return static::VERSION;
  139. }
  140. /**
  141. * Register the basic bindings into the container.
  142. *
  143. * @return void
  144. */
  145. protected function registerBaseBindings()
  146. {
  147. static::setInstance($this);
  148. $this->instance('app', $this);
  149. $this->instance('Illuminate\Container\Container', $this);
  150. }
  151. /**
  152. * Register all of the base service providers.
  153. *
  154. * @return void
  155. */
  156. protected function registerBaseServiceProviders()
  157. {
  158. $this->register(new EventServiceProvider($this));
  159. $this->register(new RoutingServiceProvider($this));
  160. }
  161. /**
  162. * Run the given array of bootstrap classes.
  163. *
  164. * @param array $bootstrappers
  165. * @return void
  166. */
  167. public function bootstrapWith(array $bootstrappers)
  168. {
  169. $this->hasBeenBootstrapped = true;
  170. foreach ($bootstrappers as $bootstrapper) {
  171. $this['events']->fire('bootstrapping: '.$bootstrapper, [$this]);
  172. $this->make($bootstrapper)->bootstrap($this);
  173. $this['events']->fire('bootstrapped: '.$bootstrapper, [$this]);
  174. }
  175. }
  176. /**
  177. * Register a callback to run after loading the environment.
  178. *
  179. * @param \Closure $callback
  180. * @return void
  181. */
  182. public function afterLoadingEnvironment(Closure $callback)
  183. {
  184. return $this->afterBootstrapping(
  185. 'Illuminate\Foundation\Bootstrap\DetectEnvironment', $callback
  186. );
  187. }
  188. /**
  189. * Register a callback to run before a bootstrapper.
  190. *
  191. * @param string $bootstrapper
  192. * @param Closure $callback
  193. * @return void
  194. */
  195. public function beforeBootstrapping($bootstrapper, Closure $callback)
  196. {
  197. $this['events']->listen('bootstrapping: '.$bootstrapper, $callback);
  198. }
  199. /**
  200. * Register a callback to run after a bootstrapper.
  201. *
  202. * @param string $bootstrapper
  203. * @param Closure $callback
  204. * @return void
  205. */
  206. public function afterBootstrapping($bootstrapper, Closure $callback)
  207. {
  208. $this['events']->listen('bootstrapped: '.$bootstrapper, $callback);
  209. }
  210. /**
  211. * Determine if the application has been bootstrapped before.
  212. *
  213. * @return bool
  214. */
  215. public function hasBeenBootstrapped()
  216. {
  217. return $this->hasBeenBootstrapped;
  218. }
  219. /**
  220. * Set the base path for the application.
  221. *
  222. * @param string $basePath
  223. * @return $this
  224. */
  225. public function setBasePath($basePath)
  226. {
  227. $this->basePath = rtrim($basePath, '\/');
  228. $this->bindPathsInContainer();
  229. return $this;
  230. }
  231. /**
  232. * Bind all of the application paths in the container.
  233. *
  234. * @return void
  235. */
  236. protected function bindPathsInContainer()
  237. {
  238. $this->instance('path', $this->path());
  239. foreach (['base', 'config', 'database', 'lang', 'public', 'storage'] as $path) {
  240. $this->instance('path.'.$path, $this->{$path.'Path'}());
  241. }
  242. }
  243. /**
  244. * Get the path to the application "app" directory.
  245. *
  246. * @return string
  247. */
  248. public function path()
  249. {
  250. return $this->basePath.DIRECTORY_SEPARATOR.'app';
  251. }
  252. /**
  253. * Get the base path of the Laravel installation.
  254. *
  255. * @return string
  256. */
  257. public function basePath()
  258. {
  259. return $this->basePath;
  260. }
  261. /**
  262. * Get the path to the application configuration files.
  263. *
  264. * @return string
  265. */
  266. public function configPath()
  267. {
  268. return $this->basePath.DIRECTORY_SEPARATOR.'config';
  269. }
  270. /**
  271. * Get the path to the database directory.
  272. *
  273. * @return string
  274. */
  275. public function databasePath()
  276. {
  277. return $this->databasePath ?: $this->basePath.DIRECTORY_SEPARATOR.'database';
  278. }
  279. /**
  280. * Set the database directory.
  281. *
  282. * @param string $path
  283. * @return $this
  284. */
  285. public function useDatabasePath($path)
  286. {
  287. $this->databasePath = $path;
  288. $this->instance('path.database', $path);
  289. return $this;
  290. }
  291. /**
  292. * Get the path to the language files.
  293. *
  294. * @return string
  295. */
  296. public function langPath()
  297. {
  298. return $this->basePath.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'lang';
  299. }
  300. /**
  301. * Get the path to the public / web directory.
  302. *
  303. * @return string
  304. */
  305. public function publicPath()
  306. {
  307. return $this->basePath.DIRECTORY_SEPARATOR.'public';
  308. }
  309. /**
  310. * Get the path to the storage directory.
  311. *
  312. * @return string
  313. */
  314. public function storagePath()
  315. {
  316. return $this->storagePath ?: $this->basePath.DIRECTORY_SEPARATOR.'storage';
  317. }
  318. /**
  319. * Set the storage directory.
  320. *
  321. * @param string $path
  322. * @return $this
  323. */
  324. public function useStoragePath($path)
  325. {
  326. $this->storagePath = $path;
  327. $this->instance('path.storage', $path);
  328. return $this;
  329. }
  330. /**
  331. * Get the path to the environment file directory.
  332. *
  333. * @return string
  334. */
  335. public function environmentPath()
  336. {
  337. return $this->environmentPath ?: $this->basePath;
  338. }
  339. /**
  340. * Set the directory for the environment file.
  341. *
  342. * @param string $path
  343. * @return $this
  344. */
  345. public function useEnvironmentPath($path)
  346. {
  347. $this->environmentPath = $path;
  348. return $this;
  349. }
  350. /**
  351. * Set the environment file to be loaded during bootstrapping.
  352. *
  353. * @param string $file
  354. * @return $this
  355. */
  356. public function loadEnvironmentFrom($file)
  357. {
  358. $this->environmentFile = $file;
  359. return $this;
  360. }
  361. /**
  362. * Get the environment file the application is using.
  363. *
  364. * @return string
  365. */
  366. public function environmentFile()
  367. {
  368. return $this->environmentFile ?: '.env';
  369. }
  370. /**
  371. * Get or check the current application environment.
  372. *
  373. * @param mixed
  374. * @return string
  375. */
  376. public function environment()
  377. {
  378. if (func_num_args() > 0) {
  379. $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
  380. foreach ($patterns as $pattern) {
  381. if (Str::is($pattern, $this['env'])) {
  382. return true;
  383. }
  384. }
  385. return false;
  386. }
  387. return $this['env'];
  388. }
  389. /**
  390. * Determine if application is in local environment.
  391. *
  392. * @return bool
  393. */
  394. public function isLocal()
  395. {
  396. return $this['env'] == 'local';
  397. }
  398. /**
  399. * Detect the application's current environment.
  400. *
  401. * @param \Closure $callback
  402. * @return string
  403. */
  404. public function detectEnvironment(Closure $callback)
  405. {
  406. $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null;
  407. return $this['env'] = (new EnvironmentDetector())->detect($callback, $args);
  408. }
  409. /**
  410. * Determine if we are running in the console.
  411. *
  412. * @return bool
  413. */
  414. public function runningInConsole()
  415. {
  416. return php_sapi_name() == 'cli';
  417. }
  418. /**
  419. * Determine if we are running unit tests.
  420. *
  421. * @return bool
  422. */
  423. public function runningUnitTests()
  424. {
  425. return $this['env'] == 'testing';
  426. }
  427. /**
  428. * Register all of the configured providers.
  429. *
  430. * @return void
  431. */
  432. public function registerConfiguredProviders()
  433. {
  434. $manifestPath = $this->getCachedServicesPath();
  435. (new ProviderRepository($this, new Filesystem, $manifestPath))
  436. ->load($this->config['app.providers']);
  437. }
  438. /**
  439. * Register a service provider with the application.
  440. *
  441. * @param \Illuminate\Support\ServiceProvider|string $provider
  442. * @param array $options
  443. * @param bool $force
  444. * @return \Illuminate\Support\ServiceProvider
  445. */
  446. public function register($provider, $options = [], $force = false)
  447. {
  448. if (($registered = $this->getProvider($provider)) && ! $force) {
  449. return $registered;
  450. }
  451. // If the given "provider" is a string, we will resolve it, passing in the
  452. // application instance automatically for the developer. This is simply
  453. // a more convenient way of specifying your service provider classes.
  454. if (is_string($provider)) {
  455. $provider = $this->resolveProviderClass($provider);
  456. }
  457. $provider->register();
  458. // Once we have registered the service we will iterate through the options
  459. // and set each of them on the application so they will be available on
  460. // the actual loading of the service objects and for developer usage.
  461. foreach ($options as $key => $value) {
  462. $this[$key] = $value;
  463. }
  464. $this->markAsRegistered($provider);
  465. // If the application has already booted, we will call this boot method on
  466. // the provider class so it has an opportunity to do its boot logic and
  467. // will be ready for any usage by the developer's application logics.
  468. if ($this->booted) {
  469. $this->bootProvider($provider);
  470. }
  471. return $provider;
  472. }
  473. /**
  474. * Get the registered service provider instance if it exists.
  475. *
  476. * @param \Illuminate\Support\ServiceProvider|string $provider
  477. * @return \Illuminate\Support\ServiceProvider|null
  478. */
  479. public function getProvider($provider)
  480. {
  481. $name = is_string($provider) ? $provider : get_class($provider);
  482. return Arr::first($this->serviceProviders, function ($key, $value) use ($name) {
  483. return $value instanceof $name;
  484. });
  485. }
  486. /**
  487. * Resolve a service provider instance from the class name.
  488. *
  489. * @param string $provider
  490. * @return \Illuminate\Support\ServiceProvider
  491. */
  492. public function resolveProviderClass($provider)
  493. {
  494. return new $provider($this);
  495. }
  496. /**
  497. * Mark the given provider as registered.
  498. *
  499. * @param \Illuminate\Support\ServiceProvider $provider
  500. * @return void
  501. */
  502. protected function markAsRegistered($provider)
  503. {
  504. $this['events']->fire($class = get_class($provider), [$provider]);
  505. $this->serviceProviders[] = $provider;
  506. $this->loadedProviders[$class] = true;
  507. }
  508. /**
  509. * Load and boot all of the remaining deferred providers.
  510. *
  511. * @return void
  512. */
  513. public function loadDeferredProviders()
  514. {
  515. // We will simply spin through each of the deferred providers and register each
  516. // one and boot them if the application has booted. This should make each of
  517. // the remaining services available to this application for immediate use.
  518. foreach ($this->deferredServices as $service => $provider) {
  519. $this->loadDeferredProvider($service);
  520. }
  521. $this->deferredServices = [];
  522. }
  523. /**
  524. * Load the provider for a deferred service.
  525. *
  526. * @param string $service
  527. * @return void
  528. */
  529. public function loadDeferredProvider($service)
  530. {
  531. if (! isset($this->deferredServices[$service])) {
  532. return;
  533. }
  534. $provider = $this->deferredServices[$service];
  535. // If the service provider has not already been loaded and registered we can
  536. // register it with the application and remove the service from this list
  537. // of deferred services, since it will already be loaded on subsequent.
  538. if (! isset($this->loadedProviders[$provider])) {
  539. $this->registerDeferredProvider($provider, $service);
  540. }
  541. }
  542. /**
  543. * Register a deferred provider and service.
  544. *
  545. * @param string $provider
  546. * @param string $service
  547. * @return void
  548. */
  549. public function registerDeferredProvider($provider, $service = null)
  550. {
  551. // Once the provider that provides the deferred service has been registered we
  552. // will remove it from our local list of the deferred services with related
  553. // providers so that this container does not try to resolve it out again.
  554. if ($service) {
  555. unset($this->deferredServices[$service]);
  556. }
  557. $this->register($instance = new $provider($this));
  558. if (! $this->booted) {
  559. $this->booting(function () use ($instance) {
  560. $this->bootProvider($instance);
  561. });
  562. }
  563. }
  564. /**
  565. * Resolve the given type from the container.
  566. *
  567. * (Overriding Container::make)
  568. *
  569. * @param string $abstract
  570. * @param array $parameters
  571. * @return mixed
  572. */
  573. public function make($abstract, array $parameters = [])
  574. {
  575. $abstract = $this->getAlias($abstract);
  576. if (isset($this->deferredServices[$abstract])) {
  577. $this->loadDeferredProvider($abstract);
  578. }
  579. return parent::make($abstract, $parameters);
  580. }
  581. /**
  582. * Determine if the given abstract type has been bound.
  583. *
  584. * (Overriding Container::bound)
  585. *
  586. * @param string $abstract
  587. * @return bool
  588. */
  589. public function bound($abstract)
  590. {
  591. return isset($this->deferredServices[$abstract]) || parent::bound($abstract);
  592. }
  593. /**
  594. * Determine if the application has booted.
  595. *
  596. * @return bool
  597. */
  598. public function isBooted()
  599. {
  600. return $this->booted;
  601. }
  602. /**
  603. * Boot the application's service providers.
  604. *
  605. * @return void
  606. */
  607. public function boot()
  608. {
  609. if ($this->booted) {
  610. return;
  611. }
  612. // Once the application has booted we will also fire some "booted" callbacks
  613. // for any listeners that need to do work after this initial booting gets
  614. // finished. This is useful when ordering the boot-up processes we run.
  615. $this->fireAppCallbacks($this->bootingCallbacks);
  616. array_walk($this->serviceProviders, function ($p) {
  617. $this->bootProvider($p);
  618. });
  619. $this->booted = true;
  620. $this->fireAppCallbacks($this->bootedCallbacks);
  621. }
  622. /**
  623. * Boot the given service provider.
  624. *
  625. * @param \Illuminate\Support\ServiceProvider $provider
  626. * @return mixed
  627. */
  628. protected function bootProvider(ServiceProvider $provider)
  629. {
  630. if (method_exists($provider, 'boot')) {
  631. return $this->call([$provider, 'boot']);
  632. }
  633. }
  634. /**
  635. * Register a new boot listener.
  636. *
  637. * @param mixed $callback
  638. * @return void
  639. */
  640. public function booting($callback)
  641. {
  642. $this->bootingCallbacks[] = $callback;
  643. }
  644. /**
  645. * Register a new "booted" listener.
  646. *
  647. * @param mixed $callback
  648. * @return void
  649. */
  650. public function booted($callback)
  651. {
  652. $this->bootedCallbacks[] = $callback;
  653. if ($this->isBooted()) {
  654. $this->fireAppCallbacks([$callback]);
  655. }
  656. }
  657. /**
  658. * Call the booting callbacks for the application.
  659. *
  660. * @param array $callbacks
  661. * @return void
  662. */
  663. protected function fireAppCallbacks(array $callbacks)
  664. {
  665. foreach ($callbacks as $callback) {
  666. call_user_func($callback, $this);
  667. }
  668. }
  669. /**
  670. * {@inheritdoc}
  671. */
  672. public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
  673. {
  674. return $this['Illuminate\Contracts\Http\Kernel']->handle(Request::createFromBase($request));
  675. }
  676. /**
  677. * Determine if middleware has been disabled for the application.
  678. *
  679. * @return bool
  680. */
  681. public function shouldSkipMiddleware()
  682. {
  683. return $this->bound('middleware.disable') &&
  684. $this->make('middleware.disable') === true;
  685. }
  686. /**
  687. * Determine if the application configuration is cached.
  688. *
  689. * @return bool
  690. */
  691. public function configurationIsCached()
  692. {
  693. return $this['files']->exists($this->getCachedConfigPath());
  694. }
  695. /**
  696. * Get the path to the configuration cache file.
  697. *
  698. * @return string
  699. */
  700. public function getCachedConfigPath()
  701. {
  702. return $this->basePath().'/bootstrap/cache/config.php';
  703. }
  704. /**
  705. * Determine if the application routes are cached.
  706. *
  707. * @return bool
  708. */
  709. public function routesAreCached()
  710. {
  711. return $this['files']->exists($this->getCachedRoutesPath());
  712. }
  713. /**
  714. * Get the path to the routes cache file.
  715. *
  716. * @return string
  717. */
  718. public function getCachedRoutesPath()
  719. {
  720. return $this->basePath().'/bootstrap/cache/routes.php';
  721. }
  722. /**
  723. * Get the path to the cached "compiled.php" file.
  724. *
  725. * @return string
  726. */
  727. public function getCachedCompilePath()
  728. {
  729. return $this->basePath().'/bootstrap/cache/compiled.php';
  730. }
  731. /**
  732. * Get the path to the cached services.json file.
  733. *
  734. * @return string
  735. */
  736. public function getCachedServicesPath()
  737. {
  738. return $this->basePath().'/bootstrap/cache/services.json';
  739. }
  740. /**
  741. * Determine if the application is currently down for maintenance.
  742. *
  743. * @return bool
  744. */
  745. public function isDownForMaintenance()
  746. {
  747. return file_exists($this->storagePath().'/framework/down');
  748. }
  749. /**
  750. * Throw an HttpException with the given data.
  751. *
  752. * @param int $code
  753. * @param string $message
  754. * @param array $headers
  755. * @return void
  756. *
  757. * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  758. */
  759. public function abort($code, $message = '', array $headers = [])
  760. {
  761. if ($code == 404) {
  762. throw new NotFoundHttpException($message);
  763. }
  764. throw new HttpException($code, $message, null, $headers);
  765. }
  766. /**
  767. * Register a terminating callback with the application.
  768. *
  769. * @param \Closure $callback
  770. * @return $this
  771. */
  772. public function terminating(Closure $callback)
  773. {
  774. $this->terminatingCallbacks[] = $callback;
  775. return $this;
  776. }
  777. /**
  778. * Terminate the application.
  779. *
  780. * @return void
  781. */
  782. public function terminate()
  783. {
  784. foreach ($this->terminatingCallbacks as $terminating) {
  785. $this->call($terminating);
  786. }
  787. }
  788. /**
  789. * Get the service providers that have been loaded.
  790. *
  791. * @return array
  792. */
  793. public function getLoadedProviders()
  794. {
  795. return $this->loadedProviders;
  796. }
  797. /**
  798. * Get the application's deferred services.
  799. *
  800. * @return array
  801. */
  802. public function getDeferredServices()
  803. {
  804. return $this->deferredServices;
  805. }
  806. /**
  807. * Set the application's deferred services.
  808. *
  809. * @param array $services
  810. * @return void
  811. */
  812. public function setDeferredServices(array $services)
  813. {
  814. $this->deferredServices = $services;
  815. }
  816. /**
  817. * Add an array of services to the application's deferred services.
  818. *
  819. * @param array $services
  820. * @return void
  821. */
  822. public function addDeferredServices(array $services)
  823. {
  824. $this->deferredServices = array_merge($this->deferredServices, $services);
  825. }
  826. /**
  827. * Determine if the given service is a deferred service.
  828. *
  829. * @param string $service
  830. * @return bool
  831. */
  832. public function isDeferredService($service)
  833. {
  834. return isset($this->deferredServices[$service]);
  835. }
  836. /**
  837. * Define a callback to be used to configure Monolog.
  838. *
  839. * @param callable $callback
  840. * @return $this
  841. */
  842. public function configureMonologUsing(callable $callback)
  843. {
  844. $this->monologConfigurator = $callback;
  845. return $this;
  846. }
  847. /**
  848. * Determine if the application has a custom Monolog configurator.
  849. *
  850. * @return bool
  851. */
  852. public function hasMonologConfigurator()
  853. {
  854. return ! is_null($this->monologConfigurator);
  855. }
  856. /**
  857. * Get the custom Monolog configurator for the application.
  858. *
  859. * @return callable
  860. */
  861. public function getMonologConfigurator()
  862. {
  863. return $this->monologConfigurator;
  864. }
  865. /**
  866. * Get the current application locale.
  867. *
  868. * @return string
  869. */
  870. public function getLocale()
  871. {
  872. return $this['config']->get('app.locale');
  873. }
  874. /**
  875. * Set the current application locale.
  876. *
  877. * @param string $locale
  878. * @return void
  879. */
  880. public function setLocale($locale)
  881. {
  882. $this['config']->set('app.locale', $locale);
  883. $this['translator']->setLocale($locale);
  884. $this['events']->fire('locale.changed', [$locale]);
  885. }
  886. /**
  887. * Register the core class aliases in the container.
  888. *
  889. * @return void
  890. */
  891. public function registerCoreContainerAliases()
  892. {
  893. $aliases = [
  894. 'app' => ['Illuminate\Foundation\Application', 'Illuminate\Contracts\Container\Container', 'Illuminate\Contracts\Foundation\Application'],
  895. 'auth' => 'Illuminate\Auth\AuthManager',
  896. 'auth.driver' => ['Illuminate\Auth\Guard', 'Illuminate\Contracts\Auth\Guard'],
  897. 'auth.password.tokens' => 'Illuminate\Auth\Passwords\TokenRepositoryInterface',
  898. 'blade.compiler' => 'Illuminate\View\Compilers\BladeCompiler',
  899. 'cache' => ['Illuminate\Cache\CacheManager', 'Illuminate\Contracts\Cache\Factory'],
  900. 'cache.store' => ['Illuminate\Cache\Repository', 'Illuminate\Contracts\Cache\Repository'],
  901. 'config' => ['Illuminate\Config\Repository', 'Illuminate\Contracts\Config\Repository'],
  902. 'cookie' => ['Illuminate\Cookie\CookieJar', 'Illuminate\Contracts\Cookie\Factory', 'Illuminate\Contracts\Cookie\QueueingFactory'],
  903. 'encrypter' => ['Illuminate\Encryption\Encrypter', 'Illuminate\Contracts\Encryption\Encrypter'],
  904. 'db' => 'Illuminate\Database\DatabaseManager',
  905. 'db.connection' => ['Illuminate\Database\Connection', 'Illuminate\Database\ConnectionInterface'],
  906. 'events' => ['Illuminate\Events\Dispatcher', 'Illuminate\Contracts\Events\Dispatcher'],
  907. 'files' => 'Illuminate\Filesystem\Filesystem',
  908. 'filesystem' => ['Illuminate\Filesystem\FilesystemManager', 'Illuminate\Contracts\Filesystem\Factory'],
  909. 'filesystem.disk' => 'Illuminate\Contracts\Filesystem\Filesystem',
  910. 'filesystem.cloud' => 'Illuminate\Contracts\Filesystem\Cloud',
  911. 'hash' => 'Illuminate\Contracts\Hashing\Hasher',
  912. 'translator' => ['Illuminate\Translation\Translator', 'Symfony\Component\Translation\TranslatorInterface'],
  913. 'log' => ['Illuminate\Log\Writer', 'Illuminate\Contracts\Logging\Log', 'Psr\Log\LoggerInterface'],
  914. 'mailer' => ['Illuminate\Mail\Mailer', 'Illuminate\Contracts\Mail\Mailer', 'Illuminate\Contracts\Mail\MailQueue'],
  915. 'auth.password' => ['Illuminate\Auth\Passwords\PasswordBroker', 'Illuminate\Contracts\Auth\PasswordBroker'],
  916. 'queue' => ['Illuminate\Queue\QueueManager', 'Illuminate\Contracts\Queue\Factory', 'Illuminate\Contracts\Queue\Monitor'],
  917. 'queue.connection' => 'Illuminate\Contracts\Queue\Queue',
  918. 'redirect' => 'Illuminate\Routing\Redirector',
  919. 'redis' => ['Illuminate\Redis\Database', 'Illuminate\Contracts\Redis\Database'],
  920. 'request' => 'Illuminate\Http\Request',
  921. 'router' => ['Illuminate\Routing\Router', 'Illuminate\Contracts\Routing\Registrar'],
  922. 'session' => 'Illuminate\Session\SessionManager',
  923. 'session.store' => ['Illuminate\Session\Store', 'Symfony\Component\HttpFoundation\Session\SessionInterface'],
  924. 'url' => ['Illuminate\Routing\UrlGenerator', 'Illuminate\Contracts\Routing\UrlGenerator'],
  925. 'validator' => ['Illuminate\Validation\Factory', 'Illuminate\Contracts\Validation\Factory'],
  926. 'view' => ['Illuminate\View\Factory', 'Illuminate\Contracts\View\Factory'],
  927. ];
  928. foreach ($aliases as $key => $aliases) {
  929. foreach ((array) $aliases as $alias) {
  930. $this->alias($key, $alias);
  931. }
  932. }
  933. }
  934. /**
  935. * Flush the container of all bindings and resolved instances.
  936. *
  937. * @return void
  938. */
  939. public function flush()
  940. {
  941. parent::flush();
  942. $this->loadedProviders = [];
  943. }
  944. /**
  945. * Get the used kernel object.
  946. *
  947. * @return \Illuminate\Contracts\Console\Kernel|\Illuminate\Contracts\Http\Kernel
  948. */
  949. protected function getKernel()
  950. {
  951. $kernelContract = $this->runningInConsole()
  952. ? 'Illuminate\Contracts\Console\Kernel'
  953. : 'Illuminate\Contracts\Http\Kernel';
  954. return $this->make($kernelContract);
  955. }
  956. /**
  957. * Get the application namespace.
  958. *
  959. * @return string
  960. *
  961. * @throws \RuntimeException
  962. */
  963. public function getNamespace()
  964. {
  965. if (! is_null($this->namespace)) {
  966. return $this->namespace;
  967. }
  968. $composer = json_decode(file_get_contents(base_path('composer.json')), true);
  969. foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
  970. foreach ((array) $path as $pathChoice) {
  971. if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) {
  972. return $this->namespace = $namespace;
  973. }
  974. }
  975. }
  976. throw new RuntimeException('Unable to detect application namespace.');
  977. }
  978. }