Skip to content

Commit b217505

Browse files
authored
Update events.rst
1 parent 4b01042 commit b217505

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

components/console/events.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,43 @@ Listeners receive a
147147
// changes the exit code
148148
$event->setExitCode(128);
149149
});
150-
150+
151151
.. tip::
152152

153153
This event is also dispatched when an exception is thrown by the command.
154154
It is then dispatched just after the ``ConsoleEvents::ERROR`` event.
155155
The exit code received in this case is the exception code.
156+
157+
.. _console-events-signal:
158+
159+
The ``ConsoleEvents::SIGNAL`` Event
160+
--------------------------------------
161+
162+
**Typical Purposes**: To perform some actions after the command execution was interrupted.
163+
164+
After the command has been interrupted, the ``ConsoleEvents::SIGNAL`` event is
165+
dispatched. It can be used to do any actions
166+
(to log or profile commands / to perform some cleanup tasks when quitting a command).
167+
168+
Listeners receive a
169+
:class:`Symfony\\Component\\Console\\Event\\ConsoleSignalEvent` event::
170+
171+
use Symfony\Component\Console\ConsoleEvents;
172+
use Symfony\Component\Console\Event\ConsoleSignalEvent;
173+
174+
$dispatcher->addListener(ConsoleEvents::SIGNAL, function (ConsoleSignalEvent $event) {
175+
176+
// gets the signal number
177+
$signal = $event->getHandlingSignal();
178+
179+
if (\SIGINT === $signal) {
180+
echo "bye bye!";
181+
}
182+
});
183+
184+
.. versionadded:: 5.2
185+
186+
The ``ConsoleEvents::SIGNAL`` event was introduced in Symfony 5.2.
187+
156188

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

0 commit comments

Comments
 (0)