Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Environment / UninitializedContextEnvironment.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;
12
13 use Behat\Behat\Context\Environment\Handler\ContextEnvironmentHandler;
14 use Behat\Behat\Context\Exception\ContextNotFoundException;
15 use Behat\Behat\Context\Exception\WrongContextClassException;
16 use Behat\Testwork\Environment\StaticEnvironment;
17
18 /**
19  * Context environment based on a list of context classes.
20  *
21  * @see ContextEnvironmentHandler
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class UninitializedContextEnvironment extends StaticEnvironment implements ContextEnvironment
26 {
27     /**
28      * @var array[]
29      */
30     private $contextClasses = array();
31
32     /**
33      * Registers context class.
34      *
35      * @param string     $contextClass
36      * @param null|array $arguments
37      *
38      * @throws ContextNotFoundException   If class does not exist
39      * @throws WrongContextClassException if class does not implement Context interface
40      */
41     public function registerContextClass($contextClass, array $arguments = null)
42     {
43         if (!class_exists($contextClass)) {
44             throw new ContextNotFoundException(sprintf(
45                 '`%s` context class not found and can not be used.',
46                 $contextClass
47             ), $contextClass);
48         }
49
50         $reflClass = new \ReflectionClass($contextClass);
51
52         if (!$reflClass->implementsInterface('Behat\Behat\Context\Context')) {
53             throw new WrongContextClassException(sprintf(
54                 'Every context class must implement Behat Context interface, but `%s` does not.',
55                 $contextClass
56             ), $contextClass);
57         }
58
59         $this->contextClasses[$contextClass] = $arguments ? : array();
60     }
61
62     /**
63      * {@inheritdoc}
64      */
65     public function hasContexts()
66     {
67         return count($this->contextClasses) > 0;
68     }
69
70     /**
71      * {@inheritdoc}
72      */
73     public function getContextClasses()
74     {
75         return array_keys($this->contextClasses);
76     }
77
78     /**
79      * {@inheritdoc}
80      */
81     public function hasContextClass($class)
82     {
83         return isset($this->contextClasses[$class]);
84     }
85
86     /**
87      * Returns context classes with their arguments.
88      *
89      * @return array[]
90      */
91     public function getContextClassesWithArguments()
92     {
93         return $this->contextClasses;
94     }
95 }