Skip to content
Closed
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
24 changes: 18 additions & 6 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,32 @@ protected function commands(): void
Artisan::starting(
function ($artisan) use ($toRemoveCommands) {
$reflectionClass = new ReflectionClass(Artisan::class);
$commands = collect($artisan->all())

$commandsProperty = $reflectionClass->getParentClass()->getProperty('commands');
$commands = collect($commandsProperty->getValue($artisan))
->filter(
function ($command) use ($toRemoveCommands) {
return ! in_array(get_class($command), $toRemoveCommands, true);
}
)
->toArray();

$property = $reflectionClass->getParentClass()
->getProperty('commands');
$commandsProperty->setAccessible(true);
$commandsProperty->setValue($artisan, $commands);
$commandsProperty->setAccessible(false);

$commandMapProperty = $reflectionClass->getProperty('commandMap');
$commandMap = collect($commandMapProperty->getValue($artisan))
->filter(
function ($command) use ($toRemoveCommands) {
return ! in_array($command, $toRemoveCommands, true);
}
)
->toArray();

$property->setAccessible(true);
$property->setValue($artisan, $commands);
$property->setAccessible(false);
$commandMapProperty->setAccessible(true);
$commandMapProperty->setValue($artisan, $commandMap);
$commandMapProperty->setAccessible(false);
}
);

Expand Down
2 changes: 2 additions & 0 deletions tests/Application/app/Commands/FakeDefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'fake:default')]
class FakeDefaultCommand extends Command
{
protected $name = 'fake:default';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'fake:environmentValue')]
class FakeEnvironmentValueCommand extends Command
{
protected $name = 'fake:environmentValue';
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/app/Commands/FakeFooCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'fake:foo')]
class FakeFooCommand extends Command
{
protected $signature = 'fake:foo {foo? : The bar}';
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/app/Commands/FakeRemovedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'fake:removed')]
class FakeRemovedCommand extends Command
{
protected $name = 'fake:removed';
Expand Down