diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b105ea0..2e9b102 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - php: ['8.0', '8.1', '8.2'] + php: ['8.1', '8.2'] steps: - name: Checkout diff --git a/composer.json b/composer.json index 8b4d060..cde0714 100644 --- a/composer.json +++ b/composer.json @@ -27,11 +27,10 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "illuminate/support": "^9.0|^10.0", "illuminate/console": "^9.0|^10.0", - "illuminate/filesystem": "^9.0|^10.0", - "regnerisch/laravel-command-hooks": "^2.0" + "illuminate/filesystem": "^9.0|^10.0" }, "extra": { "laravel": { diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 354615e..8bb73ce 100644 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -3,7 +3,10 @@ namespace AkrilliA\LaravelBeyond\Commands; use AkrilliA\LaravelBeyond\Contracts\Composer as ComposerContract; -use Regnerisch\LaravelCommandHooks\Command; +use Illuminate\Console\Command; +use Illuminate\Contracts\Console\Isolatable; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; abstract class BaseCommand extends Command { @@ -65,6 +68,46 @@ protected function checkVersionId(): int return 0; } + 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); + } + + $code = null; + + if (method_exists($this, 'before')) { + $code = $this->before(); + + if ($code) { + return (int) $code; + } + } + + $method = method_exists($this, 'handle') ? 'handle' : '__invoke'; + + try { + $originalCode = (int) $this->laravel->call([$this, $method]); + + if (method_exists($this, 'after')) { + $code = $this->after($originalCode); + } + + return is_null($code) ? $originalCode : (int) $code; + } finally { + if ($this instanceof Isolatable && $this->option('isolated') !== false) { + $this->commandIsolationMutex()->forget($this); + } + } + } + protected function getMissingPackages(): array { $composer = $this->getLaravel()->get(ComposerContract::class);