ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Factory\LazyAssetManager Class Reference

A lazy asset manager is a composition of a factory and many formula loaders. More...

+ Inheritance diagram for Assetic\Factory\LazyAssetManager:
+ Collaboration diagram for Assetic\Factory\LazyAssetManager:

Public Member Functions

 __construct (AssetFactory $factory, $loaders=array())
 Constructor. More...
 
 setLoader ($alias, FormulaLoaderInterface $loader)
 Adds a loader to the asset manager. More...
 
 addResource (ResourceInterface $resource, $loader)
 Adds a resource to the asset manager. More...
 
 getResources ()
 Returns an array of resources. More...
 
 hasFormula ($name)
 Checks for an asset formula. More...
 
 getFormula ($name)
 Returns an asset's formula. More...
 
 setFormula ($name, array $formula)
 Sets a formula on the asset manager. More...
 
 load ()
 Loads formulae from resources. More...
 
 get ($name)
 
 has ($name)
 
 getNames ()
 
 isDebug ()
 
 getLastModified (AssetInterface $asset)
 
- Public Member Functions inherited from Assetic\AssetManager
 get ($name)
 Gets an asset by name. More...
 
 has ($name)
 Checks if the current asset manager has a certain asset. More...
 
 set ($name, AssetInterface $asset)
 Registers an asset to the current asset manager. More...
 
 getNames ()
 Returns an array of asset names. More...
 
 clear ()
 Clears all assets. More...
 

Private Attributes

 $factory
 
 $loaders
 
 $resources
 
 $formulae
 
 $loaded
 
 $loading
 

Detailed Description

A lazy asset manager is a composition of a factory and many formula loaders.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 24 of file LazyAssetManager.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Factory\LazyAssetManager::__construct ( AssetFactory  $factory,
  $loaders = array() 
)

Constructor.

Parameters
AssetFactory$factoryThe asset factory
array$loadersAn array of loaders indexed by alias

Definition at line 39 of file LazyAssetManager.php.

References Assetic\Factory\LazyAssetManager\$factory, $loader, Assetic\Factory\LazyAssetManager\$loaders, array, and Assetic\Factory\LazyAssetManager\setLoader().

40  {
41  $this->factory = $factory;
42  $this->loaders = array();
43  $this->resources = array();
44  $this->formulae = array();
45  $this->loaded = false;
46  $this->loading = false;
47 
48  foreach ($loaders as $alias => $loader) {
49  $this->setLoader($alias, $loader);
50  }
51  }
setLoader($alias, FormulaLoaderInterface $loader)
Adds a loader to the asset manager.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ addResource()

Assetic\Factory\LazyAssetManager::addResource ( ResourceInterface  $resource,
  $loader 
)

Adds a resource to the asset manager.

Parameters
ResourceInterface$resourceA resource
string$loaderThe loader alias for this resource

Definition at line 71 of file LazyAssetManager.php.

References $loader.

72  {
73  $this->resources[$loader][] = $resource;
74  $this->loaded = false;
75  }

◆ get()

Assetic\Factory\LazyAssetManager::get (   $name)

Definition at line 168 of file LazyAssetManager.php.

References $options, and Assetic\Factory\LazyAssetManager\load().

169  {
170  if (!$this->loaded) {
171  $this->load();
172  }
173 
174  if (!parent::has($name) && isset($this->formulae[$name])) {
175  list($inputs, $filters, $options) = $this->formulae[$name];
176  $options['name'] = $name;
177  parent::set($name, $this->factory->createAsset($inputs, $filters, $options));
178  }
179 
180  return parent::get($name);
181  }
load()
Loads formulae from resources.
if(!is_array($argv)) $options
+ Here is the call graph for this function:

◆ getFormula()

Assetic\Factory\LazyAssetManager::getFormula (   $name)

Returns an asset's formula.

Parameters
string$nameAn asset name
Returns
array The formula
Exceptions

Definition at line 117 of file LazyAssetManager.php.

References Assetic\Factory\LazyAssetManager\load().

118  {
119  if (!$this->loaded) {
120  $this->load();
121  }
122 
123  if (!isset($this->formulae[$name])) {
124  throw new \InvalidArgumentException(sprintf('There is no "%s" formula.', $name));
125  }
126 
127  return $this->formulae[$name];
128  }
load()
Loads formulae from resources.
+ Here is the call graph for this function:

◆ getLastModified()

Assetic\Factory\LazyAssetManager::getLastModified ( AssetInterface  $asset)

Definition at line 206 of file LazyAssetManager.php.

207  {
208  return $this->factory->getLastModified($asset);
209  }

◆ getNames()

Assetic\Factory\LazyAssetManager::getNames ( )

Definition at line 192 of file LazyAssetManager.php.

References Assetic\Factory\LazyAssetManager\load().

193  {
194  if (!$this->loaded) {
195  $this->load();
196  }
197 
198  return array_unique(array_merge(parent::getNames(), array_keys($this->formulae)));
199  }
load()
Loads formulae from resources.
+ Here is the call graph for this function:

◆ getResources()

Assetic\Factory\LazyAssetManager::getResources ( )

Returns an array of resources.

Returns
array An array of resources

Definition at line 82 of file LazyAssetManager.php.

References $r, Assetic\Factory\LazyAssetManager\$resources, and array.

83  {
84  $resources = array();
85  foreach ($this->resources as $r) {
86  $resources = array_merge($resources, $r);
87  }
88 
89  return $resources;
90  }
$r
Definition: example_031.php:79
Create styles array
The data for the language used.

◆ has()

Assetic\Factory\LazyAssetManager::has (   $name)

Definition at line 183 of file LazyAssetManager.php.

References Assetic\Factory\LazyAssetManager\load().

184  {
185  if (!$this->loaded) {
186  $this->load();
187  }
188 
189  return isset($this->formulae[$name]) || parent::has($name);
190  }
load()
Loads formulae from resources.
+ Here is the call graph for this function:

◆ hasFormula()

Assetic\Factory\LazyAssetManager::hasFormula (   $name)

Checks for an asset formula.

Parameters
string$nameAn asset name
Returns
Boolean If there is a formula

Definition at line 99 of file LazyAssetManager.php.

References Assetic\Factory\LazyAssetManager\load().

100  {
101  if (!$this->loaded) {
102  $this->load();
103  }
104 
105  return isset($this->formulae[$name]);
106  }
load()
Loads formulae from resources.
+ Here is the call graph for this function:

◆ isDebug()

Assetic\Factory\LazyAssetManager::isDebug ( )

Definition at line 201 of file LazyAssetManager.php.

202  {
203  return $this->factory->isDebug();
204  }

◆ load()

Assetic\Factory\LazyAssetManager::load ( )

Loads formulae from resources.

Exceptions

Definition at line 146 of file LazyAssetManager.php.

References $loader, and Assetic\Factory\LazyAssetManager\$resources.

Referenced by Assetic\Factory\LazyAssetManager\get(), Assetic\Factory\LazyAssetManager\getFormula(), Assetic\Factory\LazyAssetManager\getNames(), Assetic\Factory\LazyAssetManager\has(), and Assetic\Factory\LazyAssetManager\hasFormula().

147  {
148  if ($this->loading) {
149  return;
150  }
151 
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));
154  }
155 
156  $this->loading = true;
157 
158  foreach ($this->resources as $loader => $resources) {
159  foreach ($resources as $resource) {
160  $this->formulae = array_replace($this->formulae, $this->loaders[$loader]->load($resource));
161  }
162  }
163 
164  $this->loaded = true;
165  $this->loading = false;
166  }
load()
Loads formulae from resources.
+ Here is the caller graph for this function:

◆ setFormula()

Assetic\Factory\LazyAssetManager::setFormula (   $name,
array  $formula 
)

Sets a formula on the asset manager.

Parameters
string$nameAn asset name
array$formulaA formula

Definition at line 136 of file LazyAssetManager.php.

137  {
138  $this->formulae[$name] = $formula;
139  }

◆ setLoader()

Assetic\Factory\LazyAssetManager::setLoader (   $alias,
FormulaLoaderInterface  $loader 
)

Adds a loader to the asset manager.

Parameters
string$aliasAn alias for the loader
FormulaLoaderInterface$loaderA loader

Definition at line 59 of file LazyAssetManager.php.

References $loader.

Referenced by Assetic\Factory\LazyAssetManager\__construct().

60  {
61  $this->loaders[$alias] = $loader;
62  $this->loaded = false;
63  }
+ Here is the caller graph for this function:

Field Documentation

◆ $factory

Assetic\Factory\LazyAssetManager::$factory
private

Definition at line 26 of file LazyAssetManager.php.

Referenced by Assetic\Factory\LazyAssetManager\__construct().

◆ $formulae

Assetic\Factory\LazyAssetManager::$formulae
private

Definition at line 29 of file LazyAssetManager.php.

◆ $loaded

Assetic\Factory\LazyAssetManager::$loaded
private

Definition at line 30 of file LazyAssetManager.php.

◆ $loaders

Assetic\Factory\LazyAssetManager::$loaders
private

Definition at line 27 of file LazyAssetManager.php.

Referenced by Assetic\Factory\LazyAssetManager\__construct().

◆ $loading

Assetic\Factory\LazyAssetManager::$loading
private

Definition at line 31 of file LazyAssetManager.php.

◆ $resources

Assetic\Factory\LazyAssetManager::$resources
private

The documentation for this class was generated from the following file: