Source of file ValueContainer.php
Size: 1,809 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Extension/Twig/ValueContainer.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 OpenSky Project Inc * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Assetic\Extension\Twig; use Assetic\ValueSupplierInterface; /** * Container for values initialized lazily from a ValueSupplierInterface. * * @author Christophe Coevoet <stof@notk.org> */ class ValueContainer implements \ArrayAccess, \IteratorAggregate, \Countable { private $values; private $valueSupplier; public function __construct(ValueSupplierInterface $valueSupplier) { $this->valueSupplier = $valueSupplier; } public function offsetExists($offset) { $this->initialize(); return array_key_exists($offset, $this->values); } public function offsetGet($offset) { $this->initialize(); if (!array_key_exists($offset, $this->values)) { throw new \OutOfRangeException(sprintf('The variable "%s" does not exist.', $offset)); } return $this->values[$offset]; } public function offsetSet($offset, $value) { throw new \BadMethodCallException('The ValueContainer is read-only.'); } public function offsetUnset($offset) { throw new \BadMethodCallException('The ValueContainer is read-only.'); } public function getIterator() { $this->initialize(); return new \ArrayIterator($this->values); } public function count() { $this->initialize(); return count($this->values); } private function initialize() { if (null === $this->values) { $this->values = $this->valueSupplier->getValues(); } } } |