Skip to content

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell authored and victorvilella committed Oct 12, 2021
1 parent fa2f8f6 commit 35e3604
Showing 1 changed file with 173 additions and 52 deletions.
225 changes: 173 additions & 52 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Closure;
use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\Foundation\CachesConfiguration;
use Illuminate\Contracts\Foundation\CachesRoutes;
use Illuminate\Contracts\Http\Kernel as HttpKernelContract;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Filesystem\Filesystem;
Expand All @@ -24,14 +26,14 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class Application extends Container implements ApplicationContract, HttpKernelInterface
class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
{
/**
* The Laravel framework version.
*
* @var string
*/
const VERSION = '6.20.34';
const VERSION = '8.60.0';

/**
* The base path for the Laravel installation.
Expand Down Expand Up @@ -110,6 +112,13 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*/
protected $databasePath;

/**
* The custom language file path defined by the developer.
*
* @var string
*/
protected $langPath;

/**
* The custom storage path defined by the developer.
*
Expand Down Expand Up @@ -145,6 +154,13 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*/
protected $namespace;

/**
* The prefixes of absolute cache paths for use during normalization.
*
* @var string[]
*/
protected $absoluteCachePathPrefixes = ['/', '\\'];

/**
* Create a new Illuminate application instance.
*
Expand Down Expand Up @@ -186,9 +202,11 @@ protected function registerBaseBindings()
$this->instance(Container::class, $this);
$this->singleton(Mix::class);

$this->instance(PackageManifest::class, new PackageManifest(
new Filesystem, $this->basePath(), $this->getCachedPackagesPath()
));
$this->singleton(PackageManifest::class, function () {
return new PackageManifest(
new Filesystem, $this->basePath(), $this->getCachedPackagesPath()
);
});
}

/**
Expand Down Expand Up @@ -396,7 +414,30 @@ public function useDatabasePath($path)
*/
public function langPath()
{
return $this->resourcePath().DIRECTORY_SEPARATOR.'lang';
if ($this->langPath) {
return $this->langPath;
}

if (is_dir($path = $this->resourcePath().DIRECTORY_SEPARATOR.'lang')) {
return $path;
}

return $this->basePath().DIRECTORY_SEPARATOR.'lang';
}

/**
* Set the language file directory.
*
* @param string $path
* @return $this
*/
public function useLangPath($path)
{
$this->langPath = $path;

$this->instance('path.lang', $path);

return $this;
}

/**
Expand Down Expand Up @@ -445,6 +486,21 @@ public function resourcePath($path = '')
return $this->basePath.DIRECTORY_SEPARATOR.'resources'.($path ? DIRECTORY_SEPARATOR.$path : $path);
}

/**
* Get the path to the views directory.
*
* This method returns the first configured path in the array of view paths.
*
* @param string $path
* @return string
*/
public function viewPath($path = '')
{
$basePath = $this['config']->get('view.paths')[0];

return rtrim($basePath, DIRECTORY_SEPARATOR).($path ? DIRECTORY_SEPARATOR.$path : $path);
}

/**
* Get the path to the environment file directory.
*
Expand Down Expand Up @@ -519,7 +575,7 @@ public function environment(...$environments)
}

/**
* Determine if application is in local environment.
* Determine if the application is in the local environment.
*
* @return bool
*/
Expand All @@ -529,7 +585,7 @@ public function isLocal()
}

/**
* Determine if application is in production environment.
* Determine if the application is in the production environment.
*
* @return bool
*/
Expand Down Expand Up @@ -582,7 +638,7 @@ public function runningUnitTests()
*/
public function registerConfiguredProviders()
{
$providers = Collection::make($this->config['app.providers'])
$providers = Collection::make($this->make('config')->get('app.providers'))
->partition(function ($provider) {
return strpos($provider, 'Illuminate\\') === 0;
});
Expand Down Expand Up @@ -848,13 +904,17 @@ public function boot()
* Boot the given service provider.
*
* @param \Illuminate\Support\ServiceProvider $provider
* @return mixed
* @return void
*/
protected function bootProvider(ServiceProvider $provider)
{
$provider->callBootingCallbacks();

if (method_exists($provider, 'boot')) {
return $this->call([$provider, 'boot']);
$this->call([$provider, 'boot']);
}

$provider->callBootedCallbacks();
}

/**
Expand Down Expand Up @@ -899,7 +959,7 @@ protected function fireAppCallbacks(array $callbacks)
/**
* {@inheritdoc}
*/
public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
public function handle(SymfonyRequest $request, int $type = self::MASTER_REQUEST, bool $catch = true)
{
return $this[HttpKernelContract::class]->handle(Request::createFromBase($request));
}
Expand Down Expand Up @@ -942,7 +1002,7 @@ public function getCachedPackagesPath()
*/
public function configurationIsCached()
{
return file_exists($this->getCachedConfigPath());
return is_file($this->getCachedConfigPath());
}

/**
Expand Down Expand Up @@ -972,7 +1032,7 @@ public function routesAreCached()
*/
public function getCachedRoutesPath()
{
return $this->normalizeCachePath('APP_ROUTES_CACHE', 'cache/routes.php');
return $this->normalizeCachePath('APP_ROUTES_CACHE', 'cache/routes-v7.php');
}

/**
Expand Down Expand Up @@ -1008,11 +1068,24 @@ protected function normalizeCachePath($key, $default)
return $this->bootstrapPath($default);
}

return Str::startsWith($env, '/')
return Str::startsWith($env, $this->absoluteCachePathPrefixes)
? $env
: $this->basePath($env);
}

/**
* Add new prefix to list of absolute path prefixes.
*
* @param string $prefix
* @return $this
*/
public function addAbsoluteCachePathPrefix($prefix)
{
$this->absoluteCachePathPrefixes[] = $prefix;

return $this;
}

/**
* Determine if the application is currently down for maintenance.
*
Expand Down Expand Up @@ -1078,6 +1151,17 @@ public function getLoadedProviders()
return $this->loadedProviders;
}

/**
* Determine if the given service provider is loaded.
*
* @param string $provider
* @return bool
*/
public function providerIsLoaded(string $provider)
{
return isset($this->loadedProviders[$provider]);
}

/**
* Get the application's deferred services.
*
Expand Down Expand Up @@ -1142,6 +1226,26 @@ public function getLocale()
return $this['config']->get('app.locale');
}

/**
* Get the current application locale.
*
* @return string
*/
public function currentLocale()
{
return $this->getLocale();
}

/**
* Get the current application fallback locale.
*
* @return string
*/
public function getFallbackLocale()
{
return $this['config']->get('app.fallback_locale');
}

/**
* Set the current application locale.
*
Expand All @@ -1158,7 +1262,20 @@ public function setLocale($locale)
}

/**
* Determine if application locale is the given locale.
* Set the current application fallback locale.
*
* @param string $fallbackLocale
* @return void
*/
public function setFallbackLocale($fallbackLocale)
{
$this['config']->set('app.fallback_locale', $fallbackLocale);

$this['translator']->setFallback($fallbackLocale);
}

/**
* Determine if the application locale is the given locale.
*
* @param string $locale
* @return bool
Expand All @@ -1176,43 +1293,44 @@ public function isLocale($locale)
public function registerCoreContainerAliases()
{
foreach ([
'app' => [self::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
'auth' => [\Illuminate\Auth\AuthManager::class, \Illuminate\Contracts\Auth\Factory::class],
'auth.driver' => [\Illuminate\Contracts\Auth\Guard::class],
'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class],
'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class],
'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class, \Psr\SimpleCache\CacheInterface::class],
'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class],
'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
'files' => [\Illuminate\Filesystem\Filesystem::class],
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
'hash' => [\Illuminate\Hashing\HashManager::class],
'hash.driver' => [\Illuminate\Contracts\Hashing\Hasher::class],
'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class],
'log' => [\Illuminate\Log\LogManager::class, \Psr\Log\LoggerInterface::class],
'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class],
'app' => [self::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
'auth' => [\Illuminate\Auth\AuthManager::class, \Illuminate\Contracts\Auth\Factory::class],
'auth.driver' => [\Illuminate\Contracts\Auth\Guard::class],
'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class],
'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class],
'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class, \Psr\SimpleCache\CacheInterface::class],
'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class],
'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
'files' => [\Illuminate\Filesystem\Filesystem::class],
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
'hash' => [\Illuminate\Hashing\HashManager::class],
'hash.driver' => [\Illuminate\Contracts\Hashing\Hasher::class],
'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class],
'log' => [\Illuminate\Log\LogManager::class, \Psr\Log\LoggerInterface::class],
'mail.manager' => [\Illuminate\Mail\MailManager::class, \Illuminate\Contracts\Mail\Factory::class],
'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class],
'auth.password.broker' => [\Illuminate\Auth\Passwords\PasswordBroker::class, \Illuminate\Contracts\Auth\PasswordBroker::class],
'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'redirect' => [\Illuminate\Routing\Redirector::class],
'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class],
'request' => [\Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
'router' => [\Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
'session' => [\Illuminate\Session\SessionManager::class],
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
'url' => [\Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'redirect' => [\Illuminate\Routing\Redirector::class],
'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class],
'request' => [\Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
'router' => [\Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
'session' => [\Illuminate\Session\SessionManager::class],
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
'url' => [\Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
] as $key => $aliases) {
foreach ($aliases as $alias) {
$this->alias($key, $alias);
Expand All @@ -1238,8 +1356,11 @@ public function flush()
$this->serviceProviders = [];
$this->resolvingCallbacks = [];
$this->terminatingCallbacks = [];
$this->beforeResolvingCallbacks = [];
$this->afterResolvingCallbacks = [];
$this->globalBeforeResolvingCallbacks = [];
$this->globalResolvingCallbacks = [];
$this->globalAfterResolvingCallbacks = [];
}

/**
Expand Down

0 comments on commit 35e3604

Please sign in to comment.