Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / EventDispatcher / Cli / SigintController.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\EventDispatcher\Cli;
12
13 use Behat\Testwork\Cli\Controller;
14 use Behat\Testwork\EventDispatcher\Event\AfterExerciseAborted;
15 use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted;
16 use Symfony\Component\Console\Command\Command;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Output\OutputInterface;
19 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
21 /**
22  * Aborts exercise on SIGINT signal.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 final class SigintController implements Controller
27 {
28     /**
29      * @var EventDispatcherInterface
30      */
31     private $eventDispatcher;
32
33     /**
34      * Initializes controller.
35      *
36      * @param EventDispatcherInterface $eventDispatcher
37      */
38     public function __construct(EventDispatcherInterface $eventDispatcher)
39     {
40         $this->eventDispatcher = $eventDispatcher;
41     }
42
43     /**
44      * {@inheritdoc}
45      */
46     public function configure(Command $command)
47     {
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     public function execute(InputInterface $input, OutputInterface $output)
54     {
55         if (function_exists('pcntl_signal')) {
56             declare(ticks = 1);
57             pcntl_signal(SIGINT, array($this, 'abortExercise'));
58         }
59     }
60
61     /**
62      * Dispatches AFTER exercise event and exits program.
63      */
64     public function abortExercise()
65     {
66         $this->eventDispatcher->dispatch(ExerciseCompleted::AFTER, new AfterExerciseAborted());
67
68         exit(1);
69     }
70 }