Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Environment / Reader / ContextEnvironmentReader.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\Context\Environment\Reader;
12
13 use Behat\Behat\Context\Environment\ContextEnvironment;
14 use Behat\Behat\Context\Reader\ContextReader;
15 use Behat\Testwork\Call\Callee;
16 use Behat\Testwork\Environment\Environment;
17 use Behat\Testwork\Environment\Exception\EnvironmentReadException;
18 use Behat\Testwork\Environment\Reader\EnvironmentReader;
19
20 /**
21  * Reads context-based environment callees using registered context loaders.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class ContextEnvironmentReader implements EnvironmentReader
26 {
27     /**
28      * @var ContextReader[]
29      */
30     private $contextReaders = array();
31
32     /**
33      * Registers context loader.
34      *
35      * @param ContextReader $contextReader
36      */
37     public function registerContextReader(ContextReader $contextReader)
38     {
39         $this->contextReaders[] = $contextReader;
40     }
41
42     /**
43      * {@inheritdoc}
44      */
45     public function supportsEnvironment(Environment $environment)
46     {
47         return $environment instanceof ContextEnvironment;
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     public function readEnvironmentCallees(Environment $environment)
54     {
55         if (!$environment instanceof ContextEnvironment) {
56             throw new EnvironmentReadException(sprintf(
57                 'ContextEnvironmentReader does not support `%s` environment.',
58                 get_class($environment)
59             ), $environment);
60         }
61
62         $callees = array();
63         foreach ($environment->getContextClasses() as $contextClass) {
64             $callees = array_merge(
65                 $callees,
66                 $this->readContextCallees($environment, $contextClass)
67             );
68         }
69
70         return $callees;
71     }
72
73     /**
74      * Reads callees from a specific suite's context.
75      *
76      * @param ContextEnvironment $environment
77      * @param string             $contextClass
78      *
79      * @return Callee[]
80      */
81     private function readContextCallees(ContextEnvironment $environment, $contextClass)
82     {
83         $callees = array();
84         foreach ($this->contextReaders as $loader) {
85             $callees = array_merge(
86                 $callees,
87                 $loader->readContextCallees($environment, $contextClass)
88             );
89         }
90
91         return $callees;
92     }
93 }