Skip to content

Commit

Permalink
[9.x] Lazy load Laravel commands (#34925)
Browse files Browse the repository at this point in the history
* [9.x] Lazy load commands shipped with Laravel

* Lazy load migration commands
  • Loading branch information
paras-malhotra authored Oct 22, 2020
1 parent d70fd4f commit 82b212c
Show file tree
Hide file tree
Showing 71 changed files with 769 additions and 200 deletions.
9 changes: 9 additions & 0 deletions src/Illuminate/Auth/Console/ClearResetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class ClearResetsCommand extends Command
*/
protected $signature = 'auth:clear-resets {name? : The name of the password broker}';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'auth:clear-resets';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Cache/Console/CacheTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class CacheTableCommand extends Command
*/
protected $name = 'cache:table';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'cache:table';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Cache/Console/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class ClearCommand extends Command
*/
protected $name = 'cache:clear';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'cache:clear';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Cache/Console/ForgetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class ForgetCommand extends Command
*/
protected $signature = 'cache:forget {key : The key to remove} {store? : The store to remove the key from}';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'cache:forget';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class ScheduleFinishCommand extends Command
*/
protected $signature = 'schedule:finish {id} {code=0}';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'schedule:finish';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class ScheduleRunCommand extends Command
*/
protected $name = 'schedule:run';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'schedule:run';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class ScheduleWorkCommand extends Command
*/
protected $name = 'schedule:work';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'schedule:work';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Database/Console/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class DumpCommand extends Command
{--path= : The path where the schema dump file should be stored}
{--prune : Delete all existing migration files}';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'schema:dump';

/**
* The console command description.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class FactoryMakeCommand extends GeneratorCommand
*/
protected $name = 'make:factory';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'make:factory';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Database/Console/Seeds/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class SeedCommand extends Command
*/
protected $name = 'db:seed';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'db:seed';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Database/Console/Seeds/SeederMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class SeederMakeCommand extends GeneratorCommand
*/
protected $name = 'make:seeder';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'make:seeder';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Database/Console/WipeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class WipeCommand extends Command
*/
protected $name = 'db:wipe';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'db:wipe';

/**
* The console command description.
*
Expand Down
36 changes: 16 additions & 20 deletions src/Illuminate/Database/MigrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class MigrationServiceProvider extends ServiceProvider implements DeferrableProv
* @var array
*/
protected $commands = [
'Migrate' => 'command.migrate',
'MigrateFresh' => 'command.migrate.fresh',
'MigrateInstall' => 'command.migrate.install',
'MigrateRefresh' => 'command.migrate.refresh',
'MigrateReset' => 'command.migrate.reset',
'MigrateRollback' => 'command.migrate.rollback',
'MigrateStatus' => 'command.migrate.status',
'MigrateMake' => 'command.migrate.make',
'Migrate' => MigrateCommand::class,
'MigrateFresh' => FreshCommand::class,
'MigrateInstall' => InstallCommand::class,
'MigrateRefresh' => RefreshCommand::class,
'MigrateReset' => ResetCommand::class,
'MigrateRollback' => RollbackCommand::class,
'MigrateStatus' => StatusCommand::class,
'MigrateMake' => MigrateMakeCommand::class,
];

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ protected function registerCommands(array $commands)
*/
protected function registerMigrateCommand()
{
$this->app->singleton('command.migrate', function ($app) {
$this->app->singleton(MigrateCommand::class, function ($app) {
return new MigrateCommand($app['migrator'], $app[Dispatcher::class]);
});
}
Expand All @@ -128,9 +128,7 @@ protected function registerMigrateCommand()
*/
protected function registerMigrateFreshCommand()
{
$this->app->singleton('command.migrate.fresh', function () {
return new FreshCommand;
});
$this->app->singleton(FreshCommand::class);
}

/**
Expand All @@ -140,7 +138,7 @@ protected function registerMigrateFreshCommand()
*/
protected function registerMigrateInstallCommand()
{
$this->app->singleton('command.migrate.install', function ($app) {
$this->app->singleton(InstallCommand::class, function ($app) {
return new InstallCommand($app['migration.repository']);
});
}
Expand All @@ -152,7 +150,7 @@ protected function registerMigrateInstallCommand()
*/
protected function registerMigrateMakeCommand()
{
$this->app->singleton('command.migrate.make', function ($app) {
$this->app->singleton(MigrateMakeCommand::class, function ($app) {
// Once we have the migration creator registered, we will create the command
// and inject the creator. The creator is responsible for the actual file
// creation of the migrations, and may be extended by these developers.
Expand All @@ -171,9 +169,7 @@ protected function registerMigrateMakeCommand()
*/
protected function registerMigrateRefreshCommand()
{
$this->app->singleton('command.migrate.refresh', function () {
return new RefreshCommand;
});
$this->app->singleton(RefreshCommand::class);
}

/**
Expand All @@ -183,7 +179,7 @@ protected function registerMigrateRefreshCommand()
*/
protected function registerMigrateResetCommand()
{
$this->app->singleton('command.migrate.reset', function ($app) {
$this->app->singleton(ResetCommand::class, function ($app) {
return new ResetCommand($app['migrator']);
});
}
Expand All @@ -195,7 +191,7 @@ protected function registerMigrateResetCommand()
*/
protected function registerMigrateRollbackCommand()
{
$this->app->singleton('command.migrate.rollback', function ($app) {
$this->app->singleton(RollbackCommand::class, function ($app) {
return new RollbackCommand($app['migrator']);
});
}
Expand All @@ -207,7 +203,7 @@ protected function registerMigrateRollbackCommand()
*/
protected function registerMigrateStatusCommand()
{
$this->app->singleton('command.migrate.status', function ($app) {
$this->app->singleton(StatusCommand::class, function ($app) {
return new StatusCommand($app['migrator']);
});
}
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/CastMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class CastMakeCommand extends GeneratorCommand
*/
protected $name = 'make:cast';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'make:cast';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/ChannelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class ChannelMakeCommand extends GeneratorCommand
*/
protected $name = 'make:channel';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'make:channel';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/ClearCompiledCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class ClearCompiledCommand extends Command
*/
protected $name = 'clear-compiled';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'clear-compiled';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/ComponentMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class ComponentMakeCommand extends GeneratorCommand
*/
protected $name = 'make:component';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'make:component';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/ConfigCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class ConfigCacheCommand extends Command
*/
protected $name = 'config:cache';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'config:cache';

/**
* The console command description.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Console/ConfigClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class ConfigClearCommand extends Command
*/
protected $name = 'config:clear';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'config:clear';

/**
* The console command description.
*
Expand Down
Loading

0 comments on commit 82b212c

Please sign in to comment.