user_saml/tests/integration/vendor/behat/behat/src/Behat/Behat/Output/Node/EventListener/Flow/FireOnlySiblingsListener.php
Arthur Schiwon 3435d5093a
update behat and deps
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
2022-04-07 17:00:47 +02:00

76 lines
1.8 KiB
PHP

<?php
/*
* This file is part of the Behat.
* (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\Behat\Output\Node\EventListener\Flow;
use Behat\Testwork\Event\Event;
use Behat\Testwork\Output\Formatter;
use Behat\Testwork\Output\Node\EventListener\EventListener;
/**
* Behat fire only siblings listener.
*
* This listener catches all events, but proxies them to further listeners only if they
* live inside specific event lifecycle (between BEFORE and AFTER events).
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class FireOnlySiblingsListener implements EventListener
{
/**
* @var string
*/
private $beforeEventName;
/**
* @var string
*/
private $afterEventName;
/**
* @var EventListener
*/
private $descendant;
/**
* @var bool
*/
private $inContext = false;
/**
* Initializes listener.
*
* @param string $beforeEventName
* @param string $afterEventName
* @param EventListener $descendant
*/
public function __construct($beforeEventName, $afterEventName, EventListener $descendant)
{
$this->beforeEventName = $beforeEventName;
$this->afterEventName = $afterEventName;
$this->descendant = $descendant;
}
/**
* {@inheritdoc}
*/
public function listenEvent(Formatter $formatter, Event $event, $eventName)
{
if ($this->beforeEventName === $eventName) {
$this->inContext = true;
}
if ($this->inContext) {
$this->descendant->listenEvent($formatter, $event, $eventName);
}
if ($this->afterEventName === $eventName) {
$this->inContext = false;
}
}
}