ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
12namespace Assetic\Asset;
13
16
22class 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}
sprintf('%.4f', $callTime)
A base abstract asset.
Definition: BaseAsset.php:26
doLoad($content, FilterInterface $additionalFilter=null)
Encapsulates asset loading logic.
Definition: BaseAsset.php:84
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
Represents an asset loaded from a file.
Definition: FileAsset.php:23
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
Definition: FileAsset.php:57
__construct($source, $filters=array(), $sourceRoot=null, $sourcePath=null, array $vars=array())
Constructor.
Definition: FileAsset.php:37
getLastModified()
Returns the time the current asset was last modified.
Definition: FileAsset.php:68
Variable utilities.
Definition: VarUtils.php:20
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
An exception for terminatinating execution or to throw for unit testing.
A filter manipulates an asset at load and dump.