PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / kriswallsmith / assetic / src / Assetic / Asset / FileAsset.php

FileAsset.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at vendor/kriswallsmith/assetic/src/Assetic/Asset/FileAsset.php

79 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
14 use Assetic\Filter\FilterInterface;
15 use Assetic\Util\VarUtils;
16
17 /**
18 * Represents an asset loaded from a file.
19 *
20 * @author Kris Wallsmith <[email protected]>
21 */
22 class FileAsset extends BaseAsset
23 {
24 private $source;
25
26 /**
27 * Constructor.
28 *
29 * @param string $source An absolute path
30 * @param array $filters An array of filters
31 * @param string $sourceRoot The source asset root directory
32 * @param string $sourcePath The source asset path
33 * @param array $vars
34 *
35 * @throws \InvalidArgumentException If the supplied root doesn't match the source when guessing the path
36 */
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 }
79