X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FReader%2FContextReaderCachedPerContext.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FReader%2FContextReaderCachedPerContext.php;h=8a51662e23869954efb9fdb6cdffe28350c9e5e8;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerContext.php b/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerContext.php new file mode 100644 index 000000000..8a51662e2 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Context/Reader/ContextReaderCachedPerContext.php @@ -0,0 +1,54 @@ + + * + * 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 context callees for a length of an entire exercise. + * + * @author Konstantin Kudryashov + */ +final class ContextReaderCachedPerContext 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) + { + if (isset($this->cachedCallees[$contextClass])) { + return $this->cachedCallees[$contextClass]; + } + + return $this->cachedCallees[$contextClass] = $this->childReader->readContextCallees( + $environment, $contextClass + ); + } +}