hexafuchs / laravel-dynamic-artisan-commands
Library for dynamic replacement of artisan commands
Fund package maintenance!
Hexafuchs
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
README
This package aims to deliver a universal interface to replace artisan commands. Sadly, the original package leaves not much possibility to do this. I wanted to create something that does not crash when others want to overwrite these commands as well and is reusable.
Warning
Please note that this library is in an early alpha stage. Any feedback is welcome. Currently, I am primarily worried if the order of the providers could prevent the commands from being registered. Please feel free to open issues or create discussions.
Installation
You can install the package via composer:
composer require hexafuchs/laravel-dynamic-artisan-commands
Usage
Within your register()
method, add the following snippet. (If you use the spatie package helper, overwrite the
registeringPackage()
function)
DynamicArtisanServiceProvider::registerCommand('CommandName', CommandNameCommand::class, NewCommandNameCommand::class, false);
The first argument is the name of the command. If your command goes like command:name
, you should write this in
UpperCamelCase notation, i.e. CommandName
. Have a look at \Illuminate\Foundation\Providers\ArtisanServiceProvider
for a list of all existing command names.
If you want to overwrite an existing command, the second argument is the original command class and the third argument is either your new command class that extends the original command class, or a closure that initializes an object of your new command class.
If you want to create a new command instead, the second argument is your command class, and the third argument is either null or a closure that initializes an object of your command class.
The fourth argument is used to define a dev command instead of a normal command. I left this possibility in here, note that there seems to be no functional difference between these types. Most likely they are only used for semantic separation of commands.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.