4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Context\Reader;
13 use Behat\Behat\Context\Environment\ContextEnvironment;
16 * Proxies call to another reader and caches callees for a length of an entire suite.
18 * @author Konstantin Kudryashov <ever.zet@gmail.com>
20 final class ContextReaderCachedPerSuite implements ContextReader
29 private $cachedCallees = array();
34 * @param ContextReader $childReader
36 public function __construct(ContextReader $childReader)
38 $this->childReader = $childReader;
44 public function readContextCallees(ContextEnvironment $environment, $contextClass)
46 $key = $this->generateCacheKey($environment, $contextClass);
48 if (isset($this->cachedCallees[$key])) {
49 return $this->cachedCallees[$key];
52 return $this->cachedCallees[$key] = $this->childReader->readContextCallees(
53 $environment, $contextClass
58 * Generates cache key.
60 * @param ContextEnvironment $environment
61 * @param string $contextClass
65 private function generateCacheKey(ContextEnvironment $environment, $contextClass)
67 return $environment->getSuite()->getName() . $contextClass;