Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions en/core-libraries/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ Or using the ``events`` hook in your Application/Plugin class::
The ``Server.terminate`` event only works for PHP-FPM implementations which
support the ``fastcgi_finish_request`` function.

``Command.beforeExecute`` & ``Command.afterExecute``
----------------------------------------------------

.. versionadded:: 5.0.0
The ``Command.beforeExecute`` & ``Command.afterExecute`` events were added in 5.0

The ``Command.beforeExecute`` & ``Command.afterExecute`` events are triggered before and after
a command has been executed. Both events contain the ``args`` which are passed to the command
and the ``afterExecute`` event also contains the ``exitCode`` which is returned by the command.

You can listen to this event using an event manager instance::

use Cake\Event\EventManager;

EventManager::instance()->on('Command.beforeExecute', function ($event, $args) {
$command = $event->getSubject();
// Do stuff here
});

EventManager::instance()->on('Command.afterExecute', function ($event, $args, $result) {
$command = $event->getSubject();
// Do stuff here
});

Or using the ``events`` hook in your Application/Plugin class::

use Cake\Event\EventManagerInterface;

public function events(EventManagerInterface $eventManager): EventManagerInterface
{
$eventManager->on('Command.beforeExecute', function ($event, $args) {
$command = $event->getSubject();
// Do stuff here
});

$eventManager->on('Command.afterExecute', function ($event, $args, $result) {
$command = $event->getSubject();
// Do stuff here
});

return $eventManager;
}


.. _registering-event-listeners:

Registering Listeners
Expand Down