8000 minor #15717 [Console] Add docs for ConsoleSignalEvent (sfmok) · symfony/symfony-docs@87113d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87113d8

Browse files
committed
minor #15717 [Console] Add docs for ConsoleSignalEvent (sfmok)
This PR was squashed before being merged into the 5.3 branch. Discussion ---------- [Console] Add docs for ConsoleSignalEvent Define the new console event `ConsoleSignalEvent` in console component docs Commits ------- bbb1d8d [Console] Add docs for ConsoleSignalEvent
2 parents 68d5fa6 + bbb1d8d commit 87113d8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

components/console/events.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,36 @@ Listeners receive a
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+
158+
The ``ConsoleEvents::SIGNAL`` Event
159+
-----------------------------------
160+
161+
**Typical Purposes**: To perform some actions after the command execution was interrupted.
162+
163+
After the command has been interrupted, the ``ConsoleEvents::SIGNAL`` event is
164+
dispatched. It can be used to do any actions
165+
(to log or profile commands / to perform some cleanup tasks when quitting a command).
166+
167+
Listeners receive a
168+
:class:`Symfony\\Component\\Console\\Event\\ConsoleSignalEvent` event::
169+
170+
use Symfony\Component\Console\ConsoleEvents;
171+
use Symfony\Component\Console\Event\ConsoleSignalEvent;
172+
173+
$dispatcher->addListener(ConsoleEvents::SIGNAL, function (ConsoleSignalEvent $event) {
174+
175+
// gets the signal number
176+
$signal = $event->getHandlingSignal();
177+
178+
if (\SIGINT === $signal) {
179+
echo "bye bye!";
180+
}
181+
});
182+
183+
.. versionadded:: 5.2
184+
185+
The ``ConsoleSignalEvent`` class was introduced in Symfony 5.2.
186+
156187

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

0 commit comments

Comments
 (0)
0