I want to run a method when every single console command is run, How do I create a listener for all console commands in lumen?
I tried by creating a listener for ConsoleCommandEvent
, this event is fired in \Symfony\Component\Console\Application::doRunCommand
, but event dispatcher has not been attached (read the comment above the method:
If an event dispatcher has been attached to the application, events are also dispatched during the life-cycle of the command.)
Update Using this event: Illuminate\Console\Events\ArtisanStarting
might help to do the job, but it is a different event. By doing so any time that you run php artisan
your code will be executed whether you run an actual command or not.
In Laravel you can listen to the CommandStarting
event which is also available in illuminate/console
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With