X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FEventDispatcher%2FCli%2FSigintController.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FEventDispatcher%2FCli%2FSigintController.php;h=24a639c9c9c624eb1f7f2cbbc50c5dae014f3762;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Cli/SigintController.php b/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Cli/SigintController.php new file mode 100644 index 000000000..24a639c9c --- /dev/null +++ b/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Cli/SigintController.php @@ -0,0 +1,70 @@ + + * + * 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 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 + */ +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() + { + $this->eventDispatcher->dispatch(ExerciseCompleted::AFTER, new AfterExerciseAborted()); + + exit(1); + } +}