Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Snippet / Generator / CachedContextIdentifier.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\Snippet\Generator;
12
13 use Behat\Behat\Context\Environment\ContextEnvironment;
14
15 /**
16  * Decorates actual identifier and caches its answers per suite.
17  *
18  * @author Konstantin Kudryashov <ever.zet@gmail.com>
19  */
20 final class CachedContextIdentifier implements TargetContextIdentifier
21 {
22     /**
23      * @var TargetContextIdentifier
24      */
25     private $decoratedIdentifier;
26     /**
27      * @var array
28      */
29     private $contextClasses = array();
30
31     /**
32      * Initialise the identifier.
33      *
34      * @param TargetContextIdentifier $identifier
35      */
36     public function __construct(TargetContextIdentifier $identifier)
37     {
38         $this->decoratedIdentifier = $identifier;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function guessTargetContextClass(ContextEnvironment $environment)
45     {
46         $suiteKey = $environment->getSuite()->getName();
47
48         if (array_key_exists($suiteKey, $this->contextClasses)) {
49             return $this->contextClasses[$suiteKey];
50         }
51
52         return $this->contextClasses[$suiteKey] = $this->decoratedIdentifier->guessTargetContextClass($environment);
53     }
54 }