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

A base abstract asset. More...

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

Public Member Functions

 __construct ($filters=array(), $sourceRoot=null, $sourcePath=null, array $vars=array())
 Constructor. More...
 
 __clone ()
 
 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...
 
 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...
 
 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...
 
- Public Member Functions inherited from Assetic\Asset\AssetInterface
 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 time the current asset was last modified. 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...
 

Protected Member Functions

 doLoad ($content, FilterInterface $additionalFilter=null)
 Encapsulates asset loading logic. More...
 

Private Attributes

 $filters
 
 $sourceRoot
 
 $sourcePath
 
 $sourceDir
 
 $targetPath
 
 $content
 
 $loaded
 
 $vars
 
 $values
 

Detailed Description

A base abstract asset.

The methods load() and getLastModified() are left undefined, although a reusable doLoad() method is available to child classes.

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

Definition at line 25 of file BaseAsset.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Asset\BaseAsset::__construct (   $filters = array(),
  $sourceRoot = null,
  $sourcePath = null,
array  $vars = array() 
)

Constructor.

Parameters
array$filtersFilters for the asset
string$sourceRootThe root directory
string$sourcePathThe asset path
array$vars

Reimplemented in Assetic\Asset\HttpAsset.

Definition at line 45 of file BaseAsset.php.

46 {
47 $this->filters = new FilterCollection($filters);
48 $this->sourceRoot = $sourceRoot;
49 $this->sourcePath = $sourcePath;
50 if ($sourcePath && $sourceRoot) {
51 $this->sourceDir = dirname("$sourceRoot/$sourcePath");
52 }
53 $this->vars = $vars;
54 $this->values = array();
55 $this->loaded = false;
56 }

References Assetic\Asset\BaseAsset\$filters, Assetic\Asset\BaseAsset\$sourcePath, Assetic\Asset\BaseAsset\$sourceRoot, and Assetic\Asset\BaseAsset\$vars.

Member Function Documentation

◆ __clone()

Assetic\Asset\BaseAsset::__clone ( )

Definition at line 58 of file BaseAsset.php.

59 {
60 $this->filters = clone $this->filters;
61 }

References Assetic\Asset\BaseAsset\$filters.

◆ clearFilters()

Assetic\Asset\BaseAsset::clearFilters ( )

Clears all filters from the current asset.

Implements Assetic\Asset\AssetInterface.

Definition at line 73 of file BaseAsset.php.

74 {
75 $this->filters->clear();
76 }

◆ doLoad()

Assetic\Asset\BaseAsset::doLoad (   $content,
FilterInterface  $additionalFilter = null 
)
protected

Encapsulates asset loading logic.

Parameters
string$contentThe asset content
FilterInterface$additionalFilterAn additional filter

Definition at line 84 of file BaseAsset.php.

85 {
86 $filter = clone $this->filters;
87 if ($additionalFilter) {
88 $filter->ensure($additionalFilter);
89 }
90
91 $asset = clone $this;
92 $asset->setContent($content);
93
94 $filter->filterLoad($asset);
95 $this->content = $asset->getContent();
96
97 $this->loaded = true;
98 }

References Assetic\Asset\BaseAsset\$content, and Assetic\Asset\BaseAsset\$filters.

Referenced by Assetic\Asset\FileAsset\load(), Assetic\Asset\HttpAsset\load(), and Assetic\Asset\StringAsset\load().

+ Here is the caller graph for this function:

◆ dump()

Assetic\Asset\BaseAsset::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 100 of file BaseAsset.php.

101 {
102 if (!$this->loaded) {
103 $this->load();
104 }
105
106 $filter = clone $this->filters;
107 if ($additionalFilter) {
108 $filter->ensure($additionalFilter);
109 }
110
111 $asset = clone $this;
112 $filter->filterDump($asset);
113
114 return $asset->getContent();
115 }
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.

References Assetic\Asset\BaseAsset\$filters, and Assetic\Asset\AssetInterface\load().

+ Here is the call graph for this function:

◆ ensureFilter()

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

Ensures the current asset includes the supplied filter.

Parameters
FilterInterface$filterA filter

Implements Assetic\Asset\AssetInterface.

Definition at line 63 of file BaseAsset.php.

64 {
65 $this->filters->ensure($filter);
66 }

◆ getContent()

Assetic\Asset\BaseAsset::getContent ( )

Returns the loaded content of the current asset.

Returns
string The content

Implements Assetic\Asset\AssetInterface.

Definition at line 117 of file BaseAsset.php.

118 {
119 return $this->content;
120 }

References Assetic\Asset\BaseAsset\$content.

◆ getFilters()

Assetic\Asset\BaseAsset::getFilters ( )

Returns an array of filters currently applied.

Returns
array An array of filters

Implements Assetic\Asset\AssetInterface.

Definition at line 68 of file BaseAsset.php.

69 {
70 return $this->filters->all();
71 }

◆ getSourceDirectory()

Assetic\Asset\BaseAsset::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 137 of file BaseAsset.php.

138 {
139 return $this->sourceDir;
140 }

References Assetic\Asset\BaseAsset\$sourceDir.

◆ getSourcePath()

Assetic\Asset\BaseAsset::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 132 of file BaseAsset.php.

133 {
134 return $this->sourcePath;
135 }

References Assetic\Asset\BaseAsset\$sourcePath.

◆ getSourceRoot()

Assetic\Asset\BaseAsset::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 127 of file BaseAsset.php.

128 {
129 return $this->sourceRoot;
130 }

References Assetic\Asset\BaseAsset\$sourceRoot.

◆ getTargetPath()

Assetic\Asset\BaseAsset::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 142 of file BaseAsset.php.

143 {
144 return $this->targetPath;
145 }

References Assetic\Asset\BaseAsset\$targetPath.

◆ getValues()

Assetic\Asset\BaseAsset::getValues ( )

Returns the current values for this asset.

Returns
array an array of strings

Implements Assetic\Asset\AssetInterface.

Definition at line 177 of file BaseAsset.php.

178 {
179 return $this->values;
180 }

References Assetic\Asset\BaseAsset\$values.

Referenced by Assetic\Asset\FileAsset\getLastModified(), Assetic\Asset\FileAsset\load(), and Assetic\Asset\HttpAsset\load().

+ Here is the caller graph for this function:

◆ getVars()

Assetic\Asset\BaseAsset::getVars ( )

Returns an array of variable names for this asset.

Returns
array

Implements Assetic\Asset\AssetInterface.

Definition at line 160 of file BaseAsset.php.

161 {
162 return $this->vars;
163 }

References Assetic\Asset\BaseAsset\$vars.

Referenced by Assetic\Asset\FileAsset\getLastModified(), Assetic\Asset\FileAsset\load(), and Assetic\Asset\HttpAsset\load().

+ Here is the caller graph for this function:

◆ setContent()

Assetic\Asset\BaseAsset::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 122 of file BaseAsset.php.

123 {
124 $this->content = $content;
125 }

References Assetic\Asset\BaseAsset\$content.

◆ setTargetPath()

Assetic\Asset\BaseAsset::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 147 of file BaseAsset.php.

148 {
149 if ($this->vars) {
150 foreach ($this->vars as $var) {
151 if (false === strpos($targetPath, $var)) {
152 throw new \RuntimeException(sprintf('The asset target path "%s" must contain the variable "{%s}".', $targetPath, $var));
153 }
154 }
155 }
156
157 $this->targetPath = $targetPath;
158 }
sprintf('%.4f', $callTime)

References Assetic\Asset\BaseAsset\$targetPath, and sprintf.

◆ setValues()

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

Sets the values for the asset's variables.

Parameters
array$values

Implements Assetic\Asset\AssetInterface.

Definition at line 165 of file BaseAsset.php.

166 {
167 foreach ($values as $var => $v) {
168 if (!in_array($var, $this->vars, true)) {
169 throw new \InvalidArgumentException(sprintf('The asset with source path "%s" has no variable named "%s".', $this->sourcePath, $var));
170 }
171 }
172
173 $this->values = $values;
174 $this->loaded = false;
175 }

References Assetic\Asset\BaseAsset\$values, and sprintf.

Field Documentation

◆ $content

◆ $filters

◆ $loaded

Assetic\Asset\BaseAsset::$loaded
private

Definition at line 33 of file BaseAsset.php.

◆ $sourceDir

Assetic\Asset\BaseAsset::$sourceDir
private

Definition at line 30 of file BaseAsset.php.

Referenced by Assetic\Asset\BaseAsset\getSourceDirectory().

◆ $sourcePath

◆ $sourceRoot

◆ $targetPath

Assetic\Asset\BaseAsset::$targetPath
private

◆ $values

Assetic\Asset\BaseAsset::$values
private

◆ $vars


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