|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Assetic package, an OpenSky project. |
|
|
5 |
* |
|
|
6 |
* (c) 2010-2011 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 |
|
|
|
14 |
use Assetic\Filter\FilterInterface; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* Represents an asset loaded from a file. |
|
|
18 |
* |
|
|
19 |
* @author Kris Wallsmith <kris.wallsmith@gmail.com> |
|
|
20 |
*/ |
|
|
21 |
class FileAsset extends BaseAsset |
|
|
22 |
{ |
|
|
23 |
private $source; |
|
|
24 |
|
|
|
25 |
/** |
|
|
26 |
* Constructor. |
|
|
27 |
* |
|
|
28 |
* @param string $source An absolute path |
|
|
29 |
* @param array $filters An array of filters |
|
|
30 |
* @param string $sourceRoot The source asset root directory |
|
|
31 |
* @param string $sourcePath The source asset path |
|
|
32 |
* |
|
|
33 |
* @throws InvalidArgumentException If the supplied root doesn't match the source when guessing the path |
|
|
34 |
*/ |
|
|
35 |
public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null) |
|
|
36 |
{ |
|
|
37 |
if (null === $sourceRoot) { |
|
|
38 |
$sourceRoot = dirname($source); |
|
|
39 |
if (null === $sourcePath) { |
|
|
40 |
$sourcePath = basename($source); |
|
|
41 |
} |
|
|
42 |
} elseif (null === $sourcePath) { |
|
|
43 |
if (0 !== strpos($source, $sourceRoot)) { |
|
|
44 |
throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot)); |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
$sourcePath = substr($source, strlen($sourceRoot) + 1); |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
$this->source = $source; |
|
|
51 |
|
|
|
52 |
parent::__construct($filters, $sourceRoot, $sourcePath); |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
public function load(FilterInterface $additionalFilter = null) |
|
|
56 |
{ |
|
|
57 |
$this->doLoad(file_get_contents($this->source), $additionalFilter); |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
public function getLastModified() |
|
|
61 |
{ |
|
|
62 |
return filemtime($this->source); |
|
|
63 |
} |
|
|
64 |
} |