Skip to content

[Console] Add docs for ConsoleSignalEvent #15717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2021
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
31 changes: 31 additions & 0 deletions components/console/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,36 @@ Listeners receive a
This event is also dispatched when an exception is thrown by the command.
It is then dispatched just after the ``ConsoleEvents::ERROR`` event.
The exit code received in this case is the exception code.


The ``ConsoleEvents::SIGNAL`` Event
-----------------------------------

**Typical Purposes**: To perform some actions after the command execution was interrupted.

After the command has been interrupted, the ``ConsoleEvents::SIGNAL`` event is
dispatched. It can be used to do any actions
(to log or profile commands / to perform some cleanup tasks when quitting a command).

Listeners receive a
:class:`Symfony\\Component\\Console\\Event\\ConsoleSignalEvent` event::

use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleSignalEvent;

$dispatcher->addListener(ConsoleEvents::SIGNAL, function (ConsoleSignalEvent $event) {

// gets the signal number
$signal = $event->getHandlingSignal();

if (\SIGINT === $signal) {
echo "bye bye!";
}
});

.. versionadded:: 5.2

The ``ConsoleSignalEvent`` class was introduced in Symfony 5.2.


.. _`reserved exit codes`: https://www.tldp.org/LDP/abs/html/exitcodes.html