Skip to content

Commit 628d39f

Browse files
authored
[9.x] Improve command name handling (#41595)
* Improve command name handling * Remove attributes
1 parent dddc27f commit 628d39f

File tree

75 files changed

+35
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+35
-148
lines changed

src/Illuminate/Auth/Console/ClearResetsCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Illuminate\Auth\Console;
44

55
use Illuminate\Console\Command;
6-
use Symfony\Component\Console\Attribute\AsCommand;
76

8-
#[AsCommand(name: 'auth:clear-resets')]
97
class ClearResetsCommand extends Command
108
{
119
/**

src/Illuminate/Cache/Console/CacheTableCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
77
use Illuminate\Support\Composer;
8-
use Symfony\Component\Console\Attribute\AsCommand;
98

10-
#[AsCommand(name: 'cache:table')]
119
class CacheTableCommand extends Command
1210
{
1311
/**

src/Illuminate/Cache/Console/ClearCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
use Illuminate\Cache\CacheManager;
66
use Illuminate\Console\Command;
77
use Illuminate\Filesystem\Filesystem;
8-
use Symfony\Component\Console\Attribute\AsCommand;
98
use Symfony\Component\Console\Input\InputArgument;
109
use Symfony\Component\Console\Input\InputOption;
1110

12-
#[AsCommand(name: 'cache:clear')]
1311
class ClearCommand extends Command
1412
{
1513
/**

src/Illuminate/Cache/Console/ForgetCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use Illuminate\Cache\CacheManager;
66
use Illuminate\Console\Command;
7-
use Symfony\Component\Console\Attribute\AsCommand;
87

9-
#[AsCommand(name: 'cache:forget')]
108
class ForgetCommand extends Command
119
{
1210
/**

src/Illuminate/Console/Command.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Console;
44

55
use Illuminate\Support\Traits\Macroable;
6+
use ReflectionClass;
67
use Symfony\Component\Console\Command\Command as SymfonyCommand;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
@@ -86,6 +87,40 @@ public function __construct()
8687
}
8788
}
8889

90+
/**
91+
* Return the command name.
92+
*
93+
* @return string|null
94+
*/
95+
public static function getDefaultName(): ?string
96+
{
97+
$class = static::class;
98+
99+
$signature = (new ReflectionClass($class))->getDefaultProperties()['signature'] ?? null;
100+
101+
if (isset($signature)) {
102+
return Parser::parse($signature)[0];
103+
}
104+
105+
$name = (new ReflectionClass($class))->getDefaultProperties()['name'] ?? null;
106+
107+
return $name ?: parent::getDefaultName();
108+
}
109+
110+
/**
111+
* Return the command description.
112+
*
113+
* @return string|null
114+
*/
115+
public static function getDefaultDescription(): ?string
116+
{
117+
$class = static::class;
118+
119+
$description = (new ReflectionClass($class))->getDefaultProperties()['description'] ?? null;
120+
121+
return $description ?: parent::getDefaultDescription();
122+
}
123+
89124
/**
90125
* Configure the console command using a fluent definition.
91126
*

src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Console\Events\ScheduledBackgroundTaskFinished;
77
use Illuminate\Contracts\Events\Dispatcher;
8-
use Symfony\Component\Console\Attribute\AsCommand;
98

10-
#[AsCommand(name: 'schedule:finish')]
119
class ScheduleFinishCommand extends Command
1210
{
1311
/**

src/Illuminate/Console/Scheduling/ScheduleRunCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
use Illuminate\Contracts\Debug\ExceptionHandler;
1111
use Illuminate\Contracts\Events\Dispatcher;
1212
use Illuminate\Support\Facades\Date;
13-
use Symfony\Component\Console\Attribute\AsCommand;
1413
use Throwable;
1514

16-
#[AsCommand(name: 'schedule:run')]
1715
class ScheduleRunCommand extends Command
1816
{
1917
/**

src/Illuminate/Console/Scheduling/ScheduleTestCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use Illuminate\Console\Application;
66
use Illuminate\Console\Command;
7-
use Symfony\Component\Console\Attribute\AsCommand;
87

9-
#[AsCommand(name: 'schedule:test')]
108
class ScheduleTestCommand extends Command
119
{
1210
/**

src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Carbon;
7-
use Symfony\Component\Console\Attribute\AsCommand;
87
use Symfony\Component\Process\Process;
98

10-
#[AsCommand(name: 'schedule:work')]
119
class ScheduleWorkCommand extends Command
1210
{
1311
/**

src/Illuminate/Database/Console/DumpCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
use Illuminate\Database\Events\SchemaDumped;
1010
use Illuminate\Filesystem\Filesystem;
1111
use Illuminate\Support\Facades\Config;
12-
use Symfony\Component\Console\Attribute\AsCommand;
1312

14-
#[AsCommand(name: 'schema:dump')]
1513
class DumpCommand extends Command
1614
{
1715
/**

0 commit comments

Comments
 (0)