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 
12 namespace Assetic\Asset;
13 
16 
22 class HttpAsset extends BaseAsset
23 {
24  private $sourceUrl;
25  private $ignoreErrors;
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 }
$path
Definition: aliased.php:25
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
Definition: HttpAsset.php:54
A base abstract asset.
Definition: BaseAsset.php:25
__construct($sourceUrl, $filters=array(), $ignoreErrors=false, array $vars=array())
Constructor.
Definition: HttpAsset.php:37
$url
Definition: shib_logout.php:72
doLoad($content, FilterInterface $additionalFilter=null)
Encapsulates asset loading logic.
Definition: BaseAsset.php:84
Represents an asset loaded via an HTTP request.
Definition: HttpAsset.php:22
A filter manipulates an asset at load and dump.
$header
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
getLastModified()
Returns the time the current asset was last modified.
Definition: HttpAsset.php:67
Create styles array
The data for the language used.
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177