X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FReader%2FContextReaderCachedPerSuite.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FReader%2FContextReaderCachedPerSuite.php;h=4a8bfd5c6f975621d1f6704fcbc7ee1b8fadac0f;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerSuite.php b/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerSuite.php new file mode 100644 index 000000000..4a8bfd5c6 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerSuite.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Context\Reader; + +use Behat\Behat\Context\Environment\ContextEnvironment; + +/** + * Proxies call to another reader and caches callees for a length of an entire suite. + * + * @author Konstantin Kudryashov + */ +final class ContextReaderCachedPerSuite implements ContextReader +{ + /** + * @var ContextReader + */ + private $childReader; + /** + * @var array[] + */ + private $cachedCallees = array(); + + /** + * Initializes reader. + * + * @param ContextReader $childReader + */ + public function __construct(ContextReader $childReader) + { + $this->childReader = $childReader; + } + + /** + * {@inheritdoc} + */ + public function readContextCallees(ContextEnvironment $environment, $contextClass) + { + $key = $this->generateCacheKey($environment, $contextClass); + + if (isset($this->cachedCallees[$key])) { + return $this->cachedCallees[$key]; + } + + return $this->cachedCallees[$key] = $this->childReader->readContextCallees( + $environment, $contextClass + ); + } + + /** + * Generates cache key. + * + * @param ContextEnvironment $environment + * @param string $contextClass + * + * @return string + */ + private function generateCacheKey(ContextEnvironment $environment, $contextClass) + { + return $environment->getSuite()->getName() . $contextClass; + } +}