<?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.
*/namespaceAssetic\Extension\Twig;
useAssetic\ValueSupplierInterface;
/**
* Container for values initialized lazily from a ValueSupplierInterface.
*
* @author Christophe Coevoet <stof@notk.org>
*/class ValueContainerimplements \ArrayAccess, \IteratorAggregate, \Countable {
private $values;
private $valueSupplier;
public function__construct(ValueSupplierInterface $valueSupplier) {
$this->valueSupplier = $valueSupplier;
}
public functionoffsetExists($offset) {
$this
->initialize();
returnarray_key_exists($offset, $this->values);
}
public functionoffsetGet($offset) {
$this
->initialize();
if (!array_key_exists($offset, $this->values)) {
thrownew\OutOfRangeException(sprintf('The variable "%s" does not exist.', $offset));
}
return$this->values[$offset];
}
public functionoffsetSet($offset, $value) {
thrownew\BadMethodCallException('The ValueContainer is read-only.');
}
public functionoffsetUnset($offset) {
thrownew\BadMethodCallException('The ValueContainer is read-only.');
}
public functiongetIterator() {
$this
->initialize();
returnnew\ArrayIterator($this->values);
}
public functioncount() {
$this
->initialize();
returncount($this->values);
}
private functioninitialize() {
if (null === $this->values) {
$this->values = $this->valueSupplier
->getValues();
}
}
}