PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
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 / HttpAsset.php

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

80 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 via an HTTP request.
19 *
20 * @author Kris Wallsmith <[email protected]>
21 */
22 class HttpAsset extends BaseAsset
23 {
24 private $sourceUrl;
25 private $ignoreErrors;
26
27 /**
28 * Constructor.
29 *
30 * @param string $sourceUrl The source URL
31 * @param array $filters An array of filters
32 * @param Boolean $ignoreErrors
33 * @param array $vars
34 *
35 * @throws \InvalidArgumentException If the first argument is not an URL
36 */
37 public function __construct($sourceUrl, $filters = array(), $ignoreErrors = false, array $vars = array())
38 {
39 if (0 === strpos($sourceUrl, '//')) {
40 $sourceUrl = 'http:'.$sourceUrl;
41 } elseif (false === strpos($sourceUrl, '://')) {
42 throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl));
43 }
44
45 $this->sourceUrl = $sourceUrl;
46 $this->ignoreErrors = $ignoreErrors;
47
48 list($scheme, $url) = explode('://', $sourceUrl, 2);
49 list($host, $path) = explode('/', $url, 2);
50
51 parent::__construct($filters, $scheme.'://'.$host, $path, $vars);
52 }
53
54 public function load(FilterInterface $additionalFilter = null)
55 {
56 $content = @file_get_contents(
57 VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues())
58 );
59
60 if (false === $content && !$this->ignoreErrors) {
61 throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
62 }
63
64 $this->doLoad($content, $additionalFilter);
65 }
66
67 public function getLastModified()
68 {
69 if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(array('http' => array('method' => 'HEAD'))))) {
70 foreach ($http_response_header as $header) {
71 if (0 === stripos($header, 'Last-Modified: ')) {
72 list(, $mtime) = explode(':', $header, 2);
73
74 return strtotime(trim($mtime));
75 }
76 }
77 }
78 }
79 }
80