Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Context / Reader / ContextReaderCachedPerContext.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 context callees for a length of an entire exercise.
17  *
18  * @author Konstantin Kudryashov <ever.zet@gmail.com>
19  */
20 final class ContextReaderCachedPerContext 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         if (isset($this->cachedCallees[$contextClass])) {
47             return $this->cachedCallees[$contextClass];
48         }
49
50         return $this->cachedCallees[$contextClass] = $this->childReader->readContextCallees(
51             $environment, $contextClass
52         );
53     }
54 }