package and depencies
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace Illuminate\Console;
|
||||
|
||||
use Illuminate\Console\View\Components\Factory;
|
||||
use Illuminate\Contracts\Console\Isolatable;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Command extends SymfonyCommand
|
||||
@@ -12,6 +15,7 @@ class Command extends SymfonyCommand
|
||||
use Concerns\CallsCommands,
|
||||
Concerns\HasParameters,
|
||||
Concerns\InteractsWithIO,
|
||||
Concerns\InteractsWithSignals,
|
||||
Macroable;
|
||||
|
||||
/**
|
||||
@@ -38,7 +42,7 @@ class Command extends SymfonyCommand
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
@@ -75,7 +79,11 @@ class Command extends SymfonyCommand
|
||||
// Once we have constructed the command, we'll set the description and other
|
||||
// related properties of the command. If a signature wasn't used to build
|
||||
// the command we'll set the arguments and the options on this command.
|
||||
$this->setDescription((string) $this->description);
|
||||
if (! isset($this->description)) {
|
||||
$this->setDescription((string) static::getDefaultDescription());
|
||||
} else {
|
||||
$this->setDescription((string) $this->description);
|
||||
}
|
||||
|
||||
$this->setHelp((string) $this->help);
|
||||
|
||||
@@ -84,6 +92,10 @@ class Command extends SymfonyCommand
|
||||
if (! isset($this->signature)) {
|
||||
$this->specifyParameters();
|
||||
}
|
||||
|
||||
if ($this instanceof Isolatable) {
|
||||
$this->configureIsolation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +116,22 @@ class Command extends SymfonyCommand
|
||||
$this->getDefinition()->addOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the console command for isolation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureIsolation()
|
||||
{
|
||||
$this->getDefinition()->addOption(new InputOption(
|
||||
'isolated',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'Do not run the command if another instance of the command is already running',
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the console command.
|
||||
*
|
||||
@@ -111,15 +139,21 @@ class Command extends SymfonyCommand
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
public function run(InputInterface $input, OutputInterface $output)
|
||||
public function run(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->output = $this->laravel->make(
|
||||
OutputStyle::class, ['input' => $input, 'output' => $output]
|
||||
);
|
||||
|
||||
return parent::run(
|
||||
$this->input = $input, $this->output
|
||||
);
|
||||
$this->components = $this->laravel->make(Factory::class, ['output' => $this->output]);
|
||||
|
||||
try {
|
||||
return parent::run(
|
||||
$this->input = $input, $this->output
|
||||
);
|
||||
} finally {
|
||||
$this->untrap();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,9 +165,38 @@ class Command extends SymfonyCommand
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ($this instanceof Isolatable && $this->option('isolated') !== false &&
|
||||
! $this->commandIsolationMutex()->create($this)) {
|
||||
$this->comment(sprintf(
|
||||
'The [%s] command is already running.', $this->getName()
|
||||
));
|
||||
|
||||
return (int) (is_numeric($this->option('isolated'))
|
||||
? $this->option('isolated')
|
||||
: self::SUCCESS);
|
||||
}
|
||||
|
||||
$method = method_exists($this, 'handle') ? 'handle' : '__invoke';
|
||||
|
||||
return (int) $this->laravel->call([$this, $method]);
|
||||
try {
|
||||
return (int) $this->laravel->call([$this, $method]);
|
||||
} finally {
|
||||
if ($this instanceof Isolatable && $this->option('isolated') !== false) {
|
||||
$this->commandIsolationMutex()->forget($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a command isolation mutex instance for the command.
|
||||
*
|
||||
* @return \Illuminate\Console\CommandMutex
|
||||
*/
|
||||
protected function commandIsolationMutex()
|
||||
{
|
||||
return $this->laravel->bound(CommandMutex::class)
|
||||
? $this->laravel->make(CommandMutex::class)
|
||||
: $this->laravel->make(CacheCommandMutex::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,17 +229,15 @@ class Command extends SymfonyCommand
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden()
|
||||
public function isHidden(): bool
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function setHidden(bool $hidden)
|
||||
public function setHidden(bool $hidden = true): static
|
||||
{
|
||||
parent::setHidden($this->hidden = $hidden);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user