4 * This file is part of the Behat.
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\Behat\Output\Node\EventListener\Flow;
13 use Behat\Testwork\Output\Formatter;
14 use Behat\Testwork\Output\Node\EventListener\EventListener;
15 use Symfony\Component\EventDispatcher\Event;
18 * Behat fire only siblings listener.
20 * This listener catches all events, but proxies them to further listeners only if they
21 * live inside specific event lifecycle (between BEFORE and AFTER events).
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 class FireOnlySiblingsListener implements EventListener
30 private $beforeEventName;
34 private $afterEventName;
42 private $inContext = false;
45 * Initializes listener.
47 * @param string $beforeEventName
48 * @param string $afterEventName
49 * @param EventListener $descendant
51 public function __construct($beforeEventName, $afterEventName, EventListener $descendant)
53 $this->beforeEventName = $beforeEventName;
54 $this->afterEventName = $afterEventName;
55 $this->descendant = $descendant;
61 public function listenEvent(Formatter $formatter, Event $event, $eventName)
63 if ($this->beforeEventName === $eventName) {
64 $this->inContext = true;
67 if ($this->inContext) {
68 $this->descendant->listenEvent($formatter, $event, $eventName);
71 if ($this->afterEventName === $eventName) {
72 $this->inContext = false;