regnerisch/laravel-command-hooks

2.0.0 2022-09-20 18:25 UTC

This package is auto-updated.

Last update: 2024-04-22 10:38:57 UTC


README

This package adds a before and after hook to Laravels command class.

Usage

The methods are only called if they are defined inside you class. If you do not need them, do not implement them. Returning a none zero value inside you before method will exit the execution immediately. Neither handle/ __invoke nor the after method will be called. The after method will get the exit code of the executed handle/ __invoke method, you can manipulate the exit code inside the after method and overwrite it by returning you own exit code. Returning null or nothing will keep the original exit code.

use \Regnerisch\LaravelCommandHooks\Command;

class MyCustomCommand extends Command
{
    protected function before(): ?int
    {
        // Do something before the command
        
        return $code;
    }
    
    protected function after(int $code): ?int
    {
        // Do something after the command
        
        return $code;
    }
    
    // ...
}

Contributors

License

ISC