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)
 Gets an asset by name. More...
 
 has ($name)
 Checks if the current asset manager has a certain asset. More...
 
 getNames ()
 Returns an array of asset names. More...
 
 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.

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.

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

+ 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.

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

References $loader.

◆ get()

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

Gets an asset by name.

Parameters
string$nameThe asset name
Returns
AssetInterface The asset
Exceptions

InvalidArgumentException If there is no asset by that name

Reimplemented from Assetic\AssetManager.

Definition at line 168 of file LazyAssetManager.php.

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.
get($resource)
Loads and returns the value for the supplied cache key.
Definition: ConfigCache.php:75
if(!is_array($argv)) $options

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

+ 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

InvalidArgumentException If there is no formula by that name

Definition at line 117 of file LazyAssetManager.php.

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 }
sprintf('%.4f', $callTime)

References Assetic\Factory\LazyAssetManager\load(), and sprintf.

+ 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 ( )

Returns an array of asset names.

Returns
array An array of asset names

Reimplemented from Assetic\AssetManager.

Definition at line 192 of file LazyAssetManager.php.

193 {
194 if (!$this->loaded) {
195 $this->load();
196 }
197
198 return array_unique(array_merge(parent::getNames(), array_keys($this->formulae)));
199 }

References Assetic\Factory\LazyAssetManager\load().

+ 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.

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

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

◆ has()

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

Checks if the current asset manager has a certain asset.

Parameters
string$namean asset name
Returns
Boolean True if the asset has been set, false if not

Reimplemented from Assetic\AssetManager.

Definition at line 183 of file LazyAssetManager.php.

184 {
185 if (!$this->loaded) {
186 $this->load();
187 }
188
189 return isset($this->formulae[$name]) || parent::has($name);
190 }

References Assetic\Factory\LazyAssetManager\load().

+ 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.

100 {
101 if (!$this->loaded) {
102 $this->load();
103 }
104
105 return isset($this->formulae[$name]);
106 }

References Assetic\Factory\LazyAssetManager\load().

+ 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

LogicException If a resource has been added to an invalid loader

Definition at line 146 of file LazyAssetManager.php.

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 }

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

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

+ Here is the call graph for this function:
+ 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.

60 {
61 $this->loaders[$alias] = $loader;
62 $this->loaded = false;
63 }

References $loader.

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

+ 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: