ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Asset\AssetCollection Class Reference

A collection of assets. More...

+ Inheritance diagram for Assetic\Asset\AssetCollection:
+ Collaboration diagram for Assetic\Asset\AssetCollection:

Public Member Functions

 __construct ($assets=array(), $filters=array(), $sourceRoot=null, array $vars=array())
 Constructor. More...
 
 __clone ()
 
 all ()
 Returns all child assets. More...
 
 add (AssetInterface $asset)
 Adds an asset to the current collection. More...
 
 removeLeaf (AssetInterface $needle, $graceful=false)
 Removes a leaf. More...
 
 replaceLeaf (AssetInterface $needle, AssetInterface $replacement, $graceful=false)
 Replaces an existing leaf with a new one. More...
 
 ensureFilter (FilterInterface $filter)
 Ensures the current asset includes the supplied filter. More...
 
 getFilters ()
 Returns an array of filters currently applied. More...
 
 clearFilters ()
 Clears all filters from the current asset. More...
 
 load (FilterInterface $additionalFilter=null)
 Loads the asset into memory and applies load filters. More...
 
 dump (FilterInterface $additionalFilter=null)
 Applies dump filters and returns the asset as a string. More...
 
 getContent ()
 Returns the loaded content of the current asset. More...
 
 setContent ($content)
 Sets the content of the current asset. More...
 
 getSourceRoot ()
 Returns an absolute path or URL to the source asset's root directory. More...
 
 getSourcePath ()
 Returns the relative path for the source asset. More...
 
 getSourceDirectory ()
 Returns the asset's source directory. More...
 
 getTargetPath ()
 Returns the URL for the current asset. More...
 
 setTargetPath ($targetPath)
 Sets the URL for the current asset. More...
 
 getLastModified ()
 Returns the highest last-modified value of all assets in the current collection. More...
 
 getIterator ()
 Returns an iterator for looping recursively over unique leaves. More...
 
 getVars ()
 Returns an array of variable names for this asset. More...
 
 setValues (array $values)
 Sets the values for the asset's variables. More...
 
 getValues ()
 Returns the current values for this asset. More...
 

Private Attributes

 $assets
 
 $filters
 
 $sourceRoot
 
 $targetPath
 
 $content
 
 $clones
 
 $vars
 
 $values
 

Detailed Description

A collection of assets.

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 AssetCollection.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Asset\AssetCollection::__construct (   $assets = array(),
  $filters = array(),
  $sourceRoot = null,
array  $vars = array() 
)

Constructor.

Parameters
array$assetsAssets for the current collection
array$filtersFilters for the current collection
string$sourceRootThe root directory
array$vars

Definition at line 43 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$assets, Assetic\Asset\AssetCollection\$filters, Assetic\Asset\AssetCollection\$sourceRoot, Assetic\Asset\AssetCollection\$vars, Assetic\Asset\AssetCollection\add(), and array.

44  {
45  $this->assets = array();
46  foreach ($assets as $asset) {
47  $this->add($asset);
48  }
49 
50  $this->filters = new FilterCollection($filters);
51  $this->sourceRoot = $sourceRoot;
52  $this->clones = new \SplObjectStorage();
53  $this->vars = $vars;
54  $this->values = array();
55  }
add(AssetInterface $asset)
Adds an asset to the current collection.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

Assetic\Asset\AssetCollection::__clone ( )

Definition at line 57 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$filters.

58  {
59  $this->filters = clone $this->filters;
60  $this->clones = new \SplObjectStorage();
61  }

◆ add()

Assetic\Asset\AssetCollection::add ( AssetInterface  $asset)

Adds an asset to the current collection.

Parameters
AssetInterface$assetAn asset

Implements Assetic\Asset\AssetCollectionInterface.

Definition at line 68 of file AssetCollection.php.

Referenced by Assetic\Asset\AssetCollection\__construct(), and Assetic\Asset\GlobAsset\initialize().

69  {
70  $this->assets[] = $asset;
71  }
+ Here is the caller graph for this function:

◆ all()

Assetic\Asset\AssetCollection::all ( )

Returns all child assets.

Returns
array An array of AssetInterface objects

Implements Assetic\Asset\AssetCollectionInterface.

Definition at line 63 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$assets.

64  {
65  return $this->assets;
66  }

◆ clearFilters()

Assetic\Asset\AssetCollection::clearFilters ( )

Clears all filters from the current asset.

Implements Assetic\Asset\AssetInterface.

Definition at line 128 of file AssetCollection.php.

129  {
130  $this->filters->clear();
131  $this->clones = new \SplObjectStorage();
132  }

◆ dump()

Assetic\Asset\AssetCollection::dump ( FilterInterface  $additionalFilter = null)

Applies dump filters and returns the asset as a string.

You may provide an additional filter to apply during dump.

Dumping an asset should not change its state.

If the current asset has not been loaded yet, it should be automatically loaded at this time.

Parameters
FilterInterface$additionalFilterAn additional filter
Returns
string The filtered content of the current asset

Implements Assetic\Asset\AssetInterface.

Definition at line 146 of file AssetCollection.php.

References array.

147  {
148  // loop through leaves and dump each asset
149  $parts = array();
150  foreach ($this as $asset) {
151  $parts[] = $asset->dump($additionalFilter);
152  }
153 
154  return implode("\n", $parts);
155  }
Create styles array
The data for the language used.

◆ ensureFilter()

Assetic\Asset\AssetCollection::ensureFilter ( FilterInterface  $filter)

Ensures the current asset includes the supplied filter.

Parameters
FilterInterface$filterA filter

Implements Assetic\Asset\AssetInterface.

Definition at line 118 of file AssetCollection.php.

119  {
120  $this->filters->ensure($filter);
121  }

◆ getContent()

Assetic\Asset\AssetCollection::getContent ( )

Returns the loaded content of the current asset.

Returns
string The content

Implements Assetic\Asset\AssetInterface.

Definition at line 157 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$content.

158  {
159  return $this->content;
160  }

◆ getFilters()

Assetic\Asset\AssetCollection::getFilters ( )

Returns an array of filters currently applied.

Returns
array An array of filters

Implements Assetic\Asset\AssetInterface.

Definition at line 123 of file AssetCollection.php.

124  {
125  return $this->filters->all();
126  }

◆ getIterator()

Assetic\Asset\AssetCollection::getIterator ( )

Returns an iterator for looping recursively over unique leaves.

Definition at line 215 of file AssetCollection.php.

216  {
217  return new \RecursiveIteratorIterator(new AssetCollectionFilterIterator(new AssetCollectionIterator($this, $this->clones)));
218  }

◆ getLastModified()

Assetic\Asset\AssetCollection::getLastModified ( )

Returns the highest last-modified value of all assets in the current collection.

Returns
integer|null A UNIX timestamp

Implements Assetic\Asset\AssetInterface.

Definition at line 195 of file AssetCollection.php.

196  {
197  if (!count($this->assets)) {
198  return;
199  }
200 
201  $mtime = 0;
202  foreach ($this as $asset) {
203  $assetMtime = $asset->getLastModified();
204  if ($assetMtime > $mtime) {
205  $mtime = $assetMtime;
206  }
207  }
208 
209  return $mtime;
210  }

◆ getSourceDirectory()

Assetic\Asset\AssetCollection::getSourceDirectory ( )

Returns the asset's source directory.

The source directory is the directory the asset was located in and can be used to resolve references relative to an asset.

Returns
string|null The asset's source directory

Implements Assetic\Asset\AssetInterface.

Definition at line 176 of file AssetCollection.php.

177  {
178  }

◆ getSourcePath()

Assetic\Asset\AssetCollection::getSourcePath ( )

Returns the relative path for the source asset.

This value can be combined with the asset's source root (if both are non-null) to get something compatible with file_get_contents().

For example:

  • 'js/main.js'
  • 'main.js'
  • null
Returns
string|null The source asset path

Implements Assetic\Asset\AssetInterface.

Definition at line 172 of file AssetCollection.php.

173  {
174  }

◆ getSourceRoot()

Assetic\Asset\AssetCollection::getSourceRoot ( )

Returns an absolute path or URL to the source asset's root directory.

This value should be an absolute path to a directory in the filesystem, an absolute URL with no path, or null.

For example:

Returns
string|null The asset's root

Implements Assetic\Asset\AssetInterface.

Definition at line 167 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$sourceRoot.

Referenced by Assetic\Asset\GlobAsset\initialize().

168  {
169  return $this->sourceRoot;
170  }
+ Here is the caller graph for this function:

◆ getTargetPath()

Assetic\Asset\AssetCollection::getTargetPath ( )

Returns the URL for the current asset.

Returns
string|null A web URL where the asset will be dumped

Implements Assetic\Asset\AssetInterface.

Definition at line 180 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$targetPath.

181  {
182  return $this->targetPath;
183  }

◆ getValues()

Assetic\Asset\AssetCollection::getValues ( )

Returns the current values for this asset.

Returns
array an array of strings

Implements Assetic\Asset\AssetInterface.

Definition at line 234 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$values.

Referenced by Assetic\Asset\GlobAsset\initialize().

235  {
236  return $this->values;
237  }
+ Here is the caller graph for this function:

◆ getVars()

Assetic\Asset\AssetCollection::getVars ( )

Returns an array of variable names for this asset.

Returns
array

Implements Assetic\Asset\AssetInterface.

Definition at line 220 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$vars.

Referenced by Assetic\Asset\GlobAsset\initialize().

221  {
222  return $this->vars;
223  }
+ Here is the caller graph for this function:

◆ load()

Assetic\Asset\AssetCollection::load ( FilterInterface  $additionalFilter = null)

Loads the asset into memory and applies load filters.

You may provide an additional filter to apply during load.

Parameters
FilterInterface$additionalFilterAn additional filter

Implements Assetic\Asset\AssetInterface.

Definition at line 134 of file AssetCollection.php.

References array.

135  {
136  // loop through leaves and load each asset
137  $parts = array();
138  foreach ($this as $asset) {
139  $asset->load($additionalFilter);
140  $parts[] = $asset->getContent();
141  }
142 
143  $this->content = implode("\n", $parts);
144  }
Create styles array
The data for the language used.

◆ removeLeaf()

Assetic\Asset\AssetCollection::removeLeaf ( AssetInterface  $leaf,
  $graceful = false 
)

Removes a leaf.

Parameters
AssetInterface$leafThe leaf to remove
Boolean$gracefulWhether the failure should return false or throw an exception
Returns
Boolean Whether the asset has been found
Exceptions

Implements Assetic\Asset\AssetCollectionInterface.

Definition at line 73 of file AssetCollection.php.

References array, and Assetic\Asset\AssetCollectionInterface\removeLeaf().

74  {
75  foreach ($this->assets as $i => $asset) {
76  $clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
77  if (in_array($needle, array($asset, $clone), true)) {
78  unset($this->clones[$asset], $this->assets[$i]);
79 
80  return true;
81  }
82 
83  if ($asset instanceof AssetCollectionInterface && $asset->removeLeaf($needle, true)) {
84  return true;
85  }
86  }
87 
88  if ($graceful) {
89  return false;
90  }
91 
92  throw new \InvalidArgumentException('Leaf not found.');
93  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ replaceLeaf()

Assetic\Asset\AssetCollection::replaceLeaf ( AssetInterface  $needle,
AssetInterface  $replacement,
  $graceful = false 
)

Replaces an existing leaf with a new one.

Parameters
AssetInterface$needleThe current asset to replace
AssetInterface$replacementThe new asset
Boolean$gracefulWhether the failure should return false or throw an exception
Returns
Boolean Whether the asset has been found
Exceptions

Implements Assetic\Asset\AssetCollectionInterface.

Definition at line 95 of file AssetCollection.php.

References array, and Assetic\Asset\AssetCollectionInterface\replaceLeaf().

96  {
97  foreach ($this->assets as $i => $asset) {
98  $clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
99  if (in_array($needle, array($asset, $clone), true)) {
100  unset($this->clones[$asset]);
101  $this->assets[$i] = $replacement;
102 
103  return true;
104  }
105 
106  if ($asset instanceof AssetCollectionInterface && $asset->replaceLeaf($needle, $replacement, true)) {
107  return true;
108  }
109  }
110 
111  if ($graceful) {
112  return false;
113  }
114 
115  throw new \InvalidArgumentException('Leaf not found.');
116  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ setContent()

Assetic\Asset\AssetCollection::setContent (   $content)

Sets the content of the current asset.

Filters can use this method to change the content of the asset.

Parameters
string$contentThe asset content

Implements Assetic\Asset\AssetInterface.

Definition at line 162 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$content.

163  {
164  $this->content = $content;
165  }

◆ setTargetPath()

Assetic\Asset\AssetCollection::setTargetPath (   $targetPath)

Sets the URL for the current asset.

Parameters
string$targetPathA web URL where the asset will be dumped

Implements Assetic\Asset\AssetInterface.

Definition at line 185 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$targetPath.

186  {
187  $this->targetPath = $targetPath;
188  }

◆ setValues()

Assetic\Asset\AssetCollection::setValues ( array  $values)

Sets the values for the asset's variables.

Parameters
array$values

Implements Assetic\Asset\AssetInterface.

Definition at line 225 of file AssetCollection.php.

References Assetic\Asset\AssetCollection\$values.

226  {
227  $this->values = $values;
228 
229  foreach ($this as $asset) {
230  $asset->setValues(array_intersect_key($values, array_flip($asset->getVars())));
231  }
232  }

Field Documentation

◆ $assets

Assetic\Asset\AssetCollection::$assets
private

◆ $clones

Assetic\Asset\AssetCollection::$clones
private

Definition at line 31 of file AssetCollection.php.

◆ $content

Assetic\Asset\AssetCollection::$content
private

◆ $filters

Assetic\Asset\AssetCollection::$filters
private

◆ $sourceRoot

Assetic\Asset\AssetCollection::$sourceRoot
private

◆ $targetPath

Assetic\Asset\AssetCollection::$targetPath
private

◆ $values

Assetic\Asset\AssetCollection::$values
private

◆ $vars

Assetic\Asset\AssetCollection::$vars
private

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