ibrostudio / laravel-artisan-command-pool
Simplify and organize Artisan commands executed programmatically
1.1.0
2025-05-28 06:44 UTC
Requires
- php: ^8.4
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-data: ^4.15
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
Installation
You can install the package via composer:
composer require ibrostudio/laravel-artisan-command-pool
Each command in the pool has to return a Illuminate\Console\Command int state (Command::SUCCESS or Command::FAILURE)
Run statically
use IBroStudio\CommandPool\CommandPool; CommandPool::pool([ Command1::class, Command2::class, ])->run()
With command arguments (passed to each command in pool):
use IBroStudio\CommandPool\CommandPool; CommandPool::pool([ Command1::class, Command2::class, ])->runWith(['name' => 'Name'])
With different arguments for each command in pool:
use IBroStudio\CommandPool\CommandPool; CommandPool::pool([ Command1::class => ['name' => 'Name'], Command2::class => ['title' => 'Title'], ])->run()
or
use IBroStudio\CommandPool\CommandPool; CommandPool::pool([ Command1::class, Command2::class => ['title' => 'Title'], ])->runWith(['name' => 'Name'])
Run from another command
use IBroStudio\CommandPool\Concerns\HasCommandPool; class MyContractorCommand extends Command { use HasCommandPool; public function handle(): int { return $this->commandPool([ Command1::class, Command2::class, ])->run(); //or return $this->commandPool([ Command1::class, Command2::class => ['title' => 'tata'], ])->runWith(['name' => $this->argument('name')]); }
Run conditionally
Add a runIf
key with a closure returning a boolean:
use IBroStudio\CommandPool\CommandPool; CommandPool::pool([ Command1::class => ['runIf' => fn (): bool => false], Command2::class, ])->run() // will run only Command2
Credits
License
The MIT License (MIT). Please see License File for more information.