File: //usr/local/wp/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Cli/SigintController.php
<?php
/*
* This file is part of the Behat Testwork.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Behat\Testwork\EventDispatcher\Cli;
use Behat\Testwork\Cli\Controller;
use Behat\Testwork\EventDispatcher\Event\AfterExerciseAborted;
use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted;
use Behat\Testwork\EventDispatcher\TestworkEventDispatcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Aborts exercise on SIGINT signal.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
final class SigintController implements Controller
{
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* Initializes controller.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public function configure(Command $command)
{
}
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
if (function_exists('pcntl_signal')) {
declare(ticks = 1);
pcntl_signal(SIGINT, array($this, 'abortExercise'));
}
}
/**
* Dispatches AFTER exercise event and exits program.
*/
public function abortExercise()
{
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
$this->eventDispatcher->dispatch(new AfterExerciseAborted(), ExerciseCompleted::AFTER);
} else {
$this->eventDispatcher->dispatch(ExerciseCompleted::AFTER, new AfterExerciseAborted());
}
exit(1);
}
}