4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\EventDispatcher\Cli;
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;
22 * Aborts exercise on SIGINT signal.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 final class SigintController implements Controller
29 * @var EventDispatcherInterface
31 private $eventDispatcher;
34 * Initializes controller.
36 * @param EventDispatcherInterface $eventDispatcher
38 public function __construct(EventDispatcherInterface $eventDispatcher)
40 $this->eventDispatcher = $eventDispatcher;
46 public function configure(Command $command)
53 public function execute(InputInterface $input, OutputInterface $output)
55 if (function_exists('pcntl_signal')) {
57 pcntl_signal(SIGINT, array($this, 'abortExercise'));
62 * Dispatches AFTER exercise event and exits program.
64 public function abortExercise()
66 $this->eventDispatcher->dispatch(ExerciseCompleted::AFTER, new AfterExerciseAborted());