- How do I install and set up Command Chaining Bundle in Laravel?
- Run `composer require akmaks/command-chaining-bundle`, then create a YAML config file at `config/packages/akmaks_command_chaining.yaml` to define your command chains. Each chain must reference a master command and its dependent commands. Finally, implement `CommandChainingInterface` in your commands, marking the master with `isMasterCommand(): true`.
- Which Laravel versions support this package?
- The bundle is compatible with Laravel 8+ due to its dependency on Symfony 5.2+. If you’re using Laravel 7 or older, you may need to manually integrate Symfony Console or use polyfills, as the package hard-codes Symfony 5.2.x.
- Can I chain commands conditionally (e.g., skip a step if a previous one fails)?
- No, this package only supports linear execution. If a command in the chain fails, the entire chain halts. For conditional logic, you’ll need to extend the bundle or handle failures programmatically within your commands.
- How do I debug a failed command chain in production?
- The bundle provides verbose logs showing which commands execute and their order. For deeper debugging, check Laravel’s log files or add custom error handling in your commands. Failed commands will display an error message with the exact point of failure.
- Does this package work with Laravel queues or async execution?
- No, the package enforces synchronous execution. Commands run sequentially in the same process. For async workflows, consider Laravel queues or alternatives like Symfony’s Workflow Component.
- What’s the best way to test command chains?
- Test chains by mocking dependencies and validating output/state changes after each command. Use Laravel’s `Artisan::call()` in unit tests to simulate chain execution. Edge cases like command failures or input dependencies should be explicitly tested.
- Can I dynamically generate command chains at runtime instead of using YAML?
- No, the package relies on static YAML configuration for chains. For dynamic chains, you’d need to build custom logic around the bundle or use a different approach like Laravel’s service providers or event listeners.
- How do I handle input arguments or flags for chained commands?
- The master command’s arguments are passed to all chained commands. Ensure your commands are designed to handle shared input, such as `--force` flags. Custom input handling for individual commands requires manual logic within each command class.
- Are there alternatives to this package for Laravel command chaining?
- For simple chaining, you could use shell scripts or custom Laravel Artisan commands with manual sequencing. For more advanced workflows, consider Symfony’s Workflow Component or Laravel Queues (though they lack built-in chaining).
- Will this package work with Symfony 6.x or Laravel 9+?
- The package is locked to Symfony 5.2.x, so it may not work out-of-the-box with newer versions. However, the MIT license allows forking and updating dependencies. Test thoroughly if upgrading, as breaking changes in Symfony could affect compatibility.