Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / EventListener / Flow / FireOnlySiblingsListener.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Output\Node\EventListener\Flow;
12
13 use Behat\Testwork\Output\Formatter;
14 use Behat\Testwork\Output\Node\EventListener\EventListener;
15 use Symfony\Component\EventDispatcher\Event;
16
17 /**
18  * Behat fire only siblings listener.
19  *
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).
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 class FireOnlySiblingsListener implements EventListener
26 {
27     /**
28      * @var string
29      */
30     private $beforeEventName;
31     /**
32      * @var string
33      */
34     private $afterEventName;
35     /**
36      * @var EventListener
37      */
38     private $descendant;
39     /**
40      * @var Boolean
41      */
42     private $inContext = false;
43
44     /**
45      * Initializes listener.
46      *
47      * @param string        $beforeEventName
48      * @param string        $afterEventName
49      * @param EventListener $descendant
50      */
51     public function __construct($beforeEventName, $afterEventName, EventListener $descendant)
52     {
53         $this->beforeEventName = $beforeEventName;
54         $this->afterEventName = $afterEventName;
55         $this->descendant = $descendant;
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     public function listenEvent(Formatter $formatter, Event $event, $eventName)
62     {
63         if ($this->beforeEventName === $eventName) {
64             $this->inContext = true;
65         }
66
67         if ($this->inContext) {
68             $this->descendant->listenEvent($formatter, $event, $eventName);
69         }
70
71         if ($this->afterEventName === $eventName) {
72             $this->inContext = false;
73         }
74     }
75 }