ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
FileAsset.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Assetic package, an OpenSky project.
5  *
6  * (c) 2010-2014 OpenSky Project Inc
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Assetic\Asset;
13 
16 
22 class FileAsset extends BaseAsset
23 {
24  private $source;
25 
37  public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
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  }
56 
57  public function load(FilterInterface $additionalFilter = null)
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  }
67 
68  public function getLastModified()
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  }
78 }
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
A base abstract asset.
Definition: BaseAsset.php:25
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
Definition: FileAsset.php:57
doLoad($content, FilterInterface $additionalFilter=null)
Encapsulates asset loading logic.
Definition: BaseAsset.php:84
__construct($source, $filters=array(), $sourceRoot=null, $sourcePath=null, array $vars=array())
Constructor.
Definition: FileAsset.php:37
Represents an asset loaded from a file.
Definition: FileAsset.php:22
A filter manipulates an asset at load and dump.
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
Create styles array
The data for the language used.
getLastModified()
Returns the time the current asset was last modified.
Definition: FileAsset.php:68
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177