Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function registerEventProvider()
*/
public static function configure(string $basePath)
{
return new ApplicationBuilder((new static)->setBasePath($basePath));
return (new ApplicationBuilder((new static)->setBasePath($basePath)))->withProviders();
}

/**
Expand All @@ -258,6 +258,7 @@ public function setBasePath($basePath)

$this->instance('path.base', $basePath);
$this->instance('path', $basePath.'/app');
$this->instance('path.bootstrap', $basePath.'/bootstrap');
$this->instance('path.config', $basePath.'/config');
$this->instance('path.public', $basePath.'/public');
$this->instance('path.storage', $basePath.'/storage');
Expand Down Expand Up @@ -1170,6 +1171,46 @@ public function getEnvironmentVariablesLoader()
return new FileEnvironmentVariablesLoader(new Filesystem, $this['path.base']);
}

/**
* Get the path to the bootstrap directory.
*
* @param string $path
* @return string
*/
public function bootstrapPath($path = '')
{
return $this['path.bootstrap'].($path != '' ? DIRECTORY_SEPARATOR.$path : '');
}

/**
* Get the path to the service provider list in the bootstrap directory.
*
* @return string
*/
public function getBootstrapProvidersPath()
{
return $this->bootstrapPath('providers.php');
}

/**
* Register all of the configured providers.
*
* As in v13, the framework's own providers register before the others, each group in
* its configured order.
*
* @return void
*/
public function registerConfiguredProviders()
{
$providers = $this['config']->get('app.providers', array());

$framework = array_filter($providers, fn ($provider) => str_starts_with($provider, 'Illuminate\\'));

$this->getProviderRepository()->load($this, array_merge(
array_values($framework), array_values(array_diff_key($providers, $framework))
));
}

/**
* Get the service provider repository instance.
*
Expand Down
28 changes: 28 additions & 0 deletions src/Illuminate/Foundation/Bootstrap/RegisterFacades.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Illuminate\Foundation\Bootstrap;

use Illuminate\Foundation\AliasLoader;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Facade;

/**
* ponytail: v13's RegisterFacades bootstrapper, without the package manifest's aliases,
* which come with the flip. The start script runs it. Remove at the flip.
*/
class RegisterFacades {

/**
* Bootstrap the given application.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
Facade::clearResolvedInstances();

Facade::setFacadeApplication($app);

AliasLoader::getInstance($app->make('config')->get('app.aliases', array()))->register();
}

}
95 changes: 95 additions & 0 deletions src/Illuminate/Foundation/Bootstrap/RegisterProviders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php namespace Illuminate\Foundation\Bootstrap;

use Illuminate\Foundation\Application;

/**
* ponytail: v13's RegisterProviders bootstrapper, without the config cache check and the
* framework's default providers, which come with the flip. The start script runs it.
* Remove at the flip.
*/
class RegisterProviders {

/**
* The service providers that should be merged before registration.
*
* @var array
*/
protected static $merge = array();

/**
* The path to the bootstrap provider configuration file.
*
* @var string|null
*/
protected static $bootstrapProviderPath;

/**
* Bootstrap the given application.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
$this->mergeAdditionalProviders($app);

$app->registerConfiguredProviders();
}

/**
* Merge the additional configured providers into the configuration.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function mergeAdditionalProviders(Application $app)
{
if (static::$bootstrapProviderPath && file_exists(static::$bootstrapProviderPath))
{
$packageProviders = require static::$bootstrapProviderPath;

foreach ($packageProviders as $index => $provider)
{
if ( ! class_exists($provider))
{
unset($packageProviders[$index]);
}
}
}

$app->make('config')->set('app.providers', array_merge(
$app->make('config')->get('app.providers', array()),
static::$merge,
array_values($packageProviders ?? array())
));
}

/**
* Merge the given providers into the provider configuration before registration.
*
* @param array $providers
* @param string|null $bootstrapProviderPath
* @return void
*/
public static function merge(array $providers, ?string $bootstrapProviderPath = null)
{
static::$bootstrapProviderPath = $bootstrapProviderPath;

static::$merge = array_values(array_filter(array_unique(
array_merge(static::$merge, $providers)
)));
}

/**
* Flush the bootstrapper's global state.
*
* @return void
*/
public static function flushState()
{
static::$bootstrapProviderPath = null;

static::$merge = array();
}

}
21 changes: 21 additions & 0 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Illuminate\Foundation\Configuration;

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\RegisterProviders;

/**
* ponytail: the part of v13's ApplicationBuilder that the app's bootstrap/app.php uses,
Expand Down Expand Up @@ -39,6 +40,26 @@ public function withMiddleware(?callable $callback = null)
return $this;
}

/**
* Register additional service providers.
*
* As in v13, they register after the configured providers, followed by those listed in
* bootstrap/providers.php.
*
* @param array $providers
* @param bool $withBootstrapProviders
* @return $this
*/
public function withProviders(array $providers = [], bool $withBootstrapProviders = true)
{
RegisterProviders::merge(
$providers,
$withBootstrapProviders ? $this->app->getBootstrapProvidersPath() : null
);

return $this;
}

/**
* Register additional Artisan commands with the application.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/ProviderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function freshManifest(array $providers)
{
list($eager, $deferred) = array(array(), array());

return compact('providers', 'eager', 'deferred');
return compact('providers', 'eager', 'deferred') + $this->default;
}

/**
Expand Down
95 changes: 14 additions & 81 deletions src/Illuminate/Foundation/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
*/

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Env;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Config\EnvironmentVariables;
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
use Illuminate\Foundation\Bootstrap\RegisterFacades;
use Illuminate\Foundation\Bootstrap\RegisterProviders;

/*
|--------------------------------------------------------------------------
Expand All @@ -63,21 +63,6 @@

$app->instance('app', $app);

/*
|--------------------------------------------------------------------------
| Load The Illuminate Facades
|--------------------------------------------------------------------------
|
| The facades provide a terser static interface over the various parts
| of the application, allowing their methods to be accessed through
| a mixtures of magic methods and facade derivatives. It's slick.
|
*/

Facade::clearResolvedInstances();

Facade::setFacadeApplication($app);

/*
|--------------------------------------------------------------------------
| Register Facade Aliases To Full Classes
Expand Down Expand Up @@ -142,22 +127,17 @@

if ($env != 'testing') ini_set('display_errors', 'Off');

$config = $app['config']['app'];

/*
|--------------------------------------------------------------------------
| Register The Alias Loader
| Register The Facades
|--------------------------------------------------------------------------
|
| The alias loader is responsible for lazy loading the class aliases setup
| for the application. We will only register it if the "config" service
| is bound in the application since it contains the alias definitions.
| v13's RegisterFacades points the facades at this application and
| registers the class aliases from the app.aliases configuration.
|
*/

$aliases = $config['aliases'];

AliasLoader::getInstance($aliases)->register();
$app->make(RegisterFacades::class)->bootstrap($app);

/*
|--------------------------------------------------------------------------
Expand All @@ -174,76 +154,29 @@

/*
|--------------------------------------------------------------------------
| Register The Core Service Providers
| Register The Service Providers
|--------------------------------------------------------------------------
|
| The Illuminate core service providers register all of the core pieces
| of the Illuminate framework including session, caching, encryption
| and more. It's simply a convenient wrapper for the registration.
| v13's RegisterProviders registers the app.providers configuration, then
| the providers given to withProviders() and those in bootstrap/providers.php.
|
*/

$providers = $config['providers'];

$app->getProviderRepository()->load($app, $providers);
$app->make(RegisterProviders::class)->bootstrap($app);

/*
|--------------------------------------------------------------------------
| Register Booted Start Files
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Once the application has been booted there are several "start" files
| we will want to include. We'll register our "booted" handler here
| so the files are included after the application gets booted up.
| Once the application has booted, the routes load from app/routes.php.
| v13 has no app/start files, so the start script no longer loads them.
|
*/

$app->booted(function() use ($app, $env)
$app->booted(function() use ($app)
{

/*
|--------------------------------------------------------------------------
| Load The Application Start Script
|--------------------------------------------------------------------------
|
| The start scripts gives this application the opportunity to override
| any of the existing IoC bindings, as well as register its own new
| bindings for things like repositories, etc. We'll load it here.
|
*/

$path = $app['path'].'/start/global.php';

if (file_exists($path)) require $path;

/*
|--------------------------------------------------------------------------
| Load The Environment Start Script
|--------------------------------------------------------------------------
|
| The environment start script is only loaded if it exists for the app
| environment currently active, which allows some actions to happen
| in one environment while not in the other, keeping things clean.
|
*/

$path = $app['path']."/start/{$env}.php";

if (file_exists($path)) require $path;

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| The Application routes are kept separate from the application starting
| just to keep the file a little cleaner. We'll go ahead and load in
| all of the routes now and return the application to the callers.
|
*/

$routes = $app['path'].'/routes.php';

if (file_exists($routes)) require $routes;

});
Loading
Loading