Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / DefinitionRepository.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\Definition;
12
13 use Behat\Behat\Definition\Exception\RedundantStepException;
14 use Behat\Testwork\Environment\Environment;
15 use Behat\Testwork\Environment\EnvironmentManager;
16
17 /**
18  * Provides step definitions using environment manager.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class DefinitionRepository
23 {
24     /**
25      * @var EnvironmentManager
26      */
27     private $environmentManager;
28
29     /**
30      * Initializes repository.
31      *
32      * @param EnvironmentManager $environmentManager
33      */
34     public function __construct(EnvironmentManager $environmentManager)
35     {
36         $this->environmentManager = $environmentManager;
37     }
38
39     /**
40      * Returns all available definitions for a specific environment.
41      *
42      * @param Environment $environment
43      *
44      * @return Definition[]
45      *
46      * @throws RedundantStepException
47      */
48     public function getEnvironmentDefinitions(Environment $environment)
49     {
50         $patterns = array();
51         $definitions = array();
52
53         foreach ($this->environmentManager->readEnvironmentCallees($environment) as $callee) {
54             if (!$callee instanceof Definition) {
55                 continue;
56             }
57
58             $pattern = $callee->getPattern();
59             if (isset($patterns[$pattern])) {
60                 throw new RedundantStepException($callee, $patterns[$pattern]);
61             }
62
63             $patterns[$pattern] = $callee;
64
65             $definitions[] = $callee;
66         }
67
68         return $definitions;
69     }
70 }