42 $this->loaders =
array();
43 $this->resources =
array();
44 $this->formulae =
array();
45 $this->loaded =
false;
46 $this->loading =
false;
61 $this->loaders[$alias] =
$loader;
62 $this->loaded =
false;
73 $this->resources[
$loader][] = $resource;
74 $this->loaded =
false;
85 foreach ($this->resources as
$r) {
101 if (!$this->loaded) {
105 return isset($this->formulae[$name]);
119 if (!$this->loaded) {
123 if (!isset($this->formulae[$name])) {
124 throw new \InvalidArgumentException(sprintf(
'There is no "%s" formula.', $name));
127 return $this->formulae[$name];
138 $this->formulae[$name] = $formula;
148 if ($this->loading) {
152 if ($diff = array_diff(array_keys($this->resources), array_keys($this->loaders))) {
153 throw new \LogicException(
'The following loader(s) are not registered: '.implode(
', ', $diff));
156 $this->loading =
true;
160 $this->formulae = array_replace($this->formulae, $this->loaders[
$loader]->
load($resource));
164 $this->loaded =
true;
165 $this->loading =
false;
168 public function get($name)
170 if (!$this->loaded) {
174 if (!parent::has($name) && isset($this->formulae[$name])) {
175 list($inputs, $filters,
$options) = $this->formulae[$name];
177 parent::set($name, $this->factory->createAsset($inputs, $filters,
$options));
180 return parent::get($name);
183 public function has($name)
185 if (!$this->loaded) {
189 return isset($this->formulae[$name]) || parent::has($name);
194 if (!$this->loaded) {
198 return array_unique(array_merge(parent::getNames(), array_keys($this->formulae)));
203 return $this->factory->isDebug();
208 return $this->factory->getLastModified($asset);
addResource(ResourceInterface $resource, $loader)
Adds a resource to the asset manager.
setFormula($name, array $formula)
Sets a formula on the asset manager.
A lazy asset manager is a composition of a factory and many formula loaders.
load()
Loads formulae from resources.
getFormula($name)
Returns an asset's formula.
A resource is something formulae can be loaded from.
setLoader($alias, FormulaLoaderInterface $loader)
Adds a loader to the asset manager.
if(!is_array($argv)) $options
getResources()
Returns an array of resources.
hasFormula($name)
Checks for an asset formula.
An asset has a mutable URL and content and can be loaded and dumped.
Create styles array
The data for the language used.
getLastModified(AssetInterface $asset)
The asset factory creates asset objects.
__construct(AssetFactory $factory, $loaders=array())
Constructor.