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

Represents an asset loaded from a file. More...

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

Public Member Functions

 __construct ($source, $filters=array(), $sourceRoot=null, $sourcePath=null, array $vars=array())
 Constructor. More...
 
 load (FilterInterface $additionalFilter=null)
 Loads the asset into memory and applies load filters. More...
 
 getLastModified ()
 Returns the time the current asset was last modified. More...
 
- Public Member Functions inherited from Assetic\Asset\BaseAsset
 __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...
 

Private Attributes

 $source
 

Additional Inherited Members

- Protected Member Functions inherited from Assetic\Asset\BaseAsset
 doLoad ($content, FilterInterface $additionalFilter=null)
 Encapsulates asset loading logic. More...
 

Detailed Description

Represents an asset loaded from a file.

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

Definition at line 22 of file FileAsset.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
string$sourceAn absolute path
array$filtersAn array of filters
string$sourceRootThe source asset root directory
string$sourcePathThe source asset path
array$vars
Exceptions

Definition at line 37 of file FileAsset.php.

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

38  {
39  if (null === $sourceRoot) {
40  $sourceRoot = dirname($source);
41  if (null === $sourcePath) {
42  $sourcePath = basename($source);
43  }
44  } elseif (null === $sourcePath) {
45  if (0 !== strpos($source, $sourceRoot)) {
46  throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot));
47  }
48 
49  $sourcePath = substr($source, strlen($sourceRoot) + 1);
50  }
51 
52  $this->source = $source;
53 
54  parent::__construct($filters, $sourceRoot, $sourcePath, $vars);
55  }

Member Function Documentation

◆ getLastModified()

Assetic\Asset\FileAsset::getLastModified ( )

Returns the time the current asset was last modified.

Returns
integer|null A UNIX timestamp

Implements Assetic\Asset\AssetInterface.

Definition at line 68 of file FileAsset.php.

References Assetic\Asset\FileAsset\$source, Assetic\Asset\BaseAsset\getValues(), Assetic\Asset\BaseAsset\getVars(), and Assetic\Util\VarUtils\resolve().

69  {
70  $source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());
71 
72  if (!is_file($source)) {
73  throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
74  }
75 
76  return filemtime($source);
77  }
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177
+ Here is the call graph for this function:

◆ load()

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

References Assetic\Asset\FileAsset\$source, Assetic\Asset\BaseAsset\doLoad(), Assetic\Asset\BaseAsset\getValues(), Assetic\Asset\BaseAsset\getVars(), and Assetic\Util\VarUtils\resolve().

58  {
59  $source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());
60 
61  if (!is_file($source)) {
62  throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
63  }
64 
65  $this->doLoad(file_get_contents($source), $additionalFilter);
66  }
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
doLoad($content, FilterInterface $additionalFilter=null)
Encapsulates asset loading logic.
Definition: BaseAsset.php:84
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177
+ Here is the call graph for this function:

Field Documentation

◆ $source

Assetic\Asset\FileAsset::$source
private

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