ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
HttpAsset.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 HttpAsset extends BaseAsset
23{
24 private $sourceUrl;
26
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}
sprintf('%.4f', $callTime)
$path
Definition: aliased.php:25
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 via an HTTP request.
Definition: HttpAsset.php:23
__construct($sourceUrl, $filters=array(), $ignoreErrors=false, array $vars=array())
Constructor.
Definition: HttpAsset.php:37
getLastModified()
Returns the time the current asset was last modified.
Definition: HttpAsset.php:67
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
Definition: HttpAsset.php:54
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.
$header
A filter manipulates an asset at load and dump.
$url
Definition: shib_logout.php:72