Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Reader / ContextReaderCachedPerSuite.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\Reader;
12
13 use Behat\Behat\Context\Environment\ContextEnvironment;
14
15 /**
16  * Proxies call to another reader and caches callees for a length of an entire suite.
17  *
18  * @author Konstantin Kudryashov <ever.zet@gmail.com>
19  */
20 final class ContextReaderCachedPerSuite implements ContextReader
21 {
22     /**
23      * @var ContextReader
24      */
25     private $childReader;
26     /**
27      * @var array[]
28      */
29     private $cachedCallees = array();
30
31     /**
32      * Initializes reader.
33      *
34      * @param ContextReader $childReader
35      */
36     public function __construct(ContextReader $childReader)
37     {
38         $this->childReader = $childReader;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function readContextCallees(ContextEnvironment $environment, $contextClass)
45     {
46         $key = $this->generateCacheKey($environment, $contextClass);
47
48         if (isset($this->cachedCallees[$key])) {
49             return $this->cachedCallees[$key];
50         }
51
52         return $this->cachedCallees[$key] = $this->childReader->readContextCallees(
53             $environment, $contextClass
54         );
55     }
56
57     /**
58      * Generates cache key.
59      *
60      * @param ContextEnvironment $environment
61      * @param string             $contextClass
62      *
63      * @return string
64      */
65     private function generateCacheKey(ContextEnvironment $environment, $contextClass)
66     {
67         return $environment->getSuite()->getName() . $contextClass;
68     }
69 }