ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Asset\HttpAsset Class Reference

Represents an asset loaded via an HTTP request. More...

+ Inheritance diagram for Assetic\Asset\HttpAsset:
+ Collaboration diagram for Assetic\Asset\HttpAsset:

Public Member Functions

 __construct ($sourceUrl, $filters=array(), $ignoreErrors=false, array $vars=array())
 Constructor. More...
 
 load (FilterInterface $additionalFilter=null)
 Loads the asset into memory and applies load filters. More...
 
 getLastModified ()
 Returns the time the current asset was last modified. More...
 
- Public Member Functions inherited from Assetic\Asset\BaseAsset
 __construct ($filters=array(), $sourceRoot=null, $sourcePath=null, array $vars=array())
 Constructor. More...
 
 __clone ()
 
 ensureFilter (FilterInterface $filter)
 Ensures the current asset includes the supplied filter. More...
 
 getFilters ()
 Returns an array of filters currently applied. More...
 
 clearFilters ()
 Clears all filters from the current asset. More...
 
 dump (FilterInterface $additionalFilter=null)
 Applies dump filters and returns the asset as a string. More...
 
 getContent ()
 Returns the loaded content of the current asset. More...
 
 setContent ($content)
 Sets the content of the current asset. More...
 
 getSourceRoot ()
 Returns an absolute path or URL to the source asset's root directory. More...
 
 getSourcePath ()
 Returns the relative path for the source asset. More...
 
 getSourceDirectory ()
 Returns the asset's source directory. More...
 
 getTargetPath ()
 Returns the URL for the current asset. More...
 
 setTargetPath ($targetPath)
 Sets the URL for the current asset. More...
 
 getVars ()
 Returns an array of variable names for this asset. More...
 
 setValues (array $values)
 Sets the values for the asset's variables. More...
 
 getValues ()
 Returns the current values for this asset. More...
 

Private Attributes

 $sourceUrl
 
 $ignoreErrors
 

Additional Inherited Members

- Protected Member Functions inherited from Assetic\Asset\BaseAsset
 doLoad ($content, FilterInterface $additionalFilter=null)
 Encapsulates asset loading logic. More...
 

Detailed Description

Represents an asset loaded via an HTTP request.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 22 of file HttpAsset.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Asset\HttpAsset::__construct (   $sourceUrl,
  $filters = array(),
  $ignoreErrors = false,
array  $vars = array() 
)

Constructor.

Parameters
string$sourceUrlThe source URL
array$filtersAn array of filters
Boolean$ignoreErrors
array$vars
Exceptions

Definition at line 37 of file HttpAsset.php.

References Assetic\Asset\BaseAsset\$filters, Assetic\Asset\HttpAsset\$ignoreErrors, $path, Assetic\Asset\HttpAsset\$sourceUrl, $url, and Assetic\Asset\BaseAsset\$vars.

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  }
$path
Definition: aliased.php:25
$url
Definition: shib_logout.php:72

Member Function Documentation

◆ getLastModified()

Assetic\Asset\HttpAsset::getLastModified ( )

Returns the time the current asset was last modified.

Returns
integer|null A UNIX timestamp

Implements Assetic\Asset\AssetInterface.

Definition at line 67 of file HttpAsset.php.

References $header, and array.

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  }
$header
Create styles array
The data for the language used.

◆ load()

Assetic\Asset\HttpAsset::load ( FilterInterface  $additionalFilter = null)

Loads the asset into memory and applies load filters.

You may provide an additional filter to apply during load.

Parameters
FilterInterface$additionalFilterAn additional filter

Implements Assetic\Asset\AssetInterface.

Definition at line 54 of file HttpAsset.php.

References Assetic\Asset\BaseAsset\$content, Assetic\Asset\BaseAsset\doLoad(), Assetic\Asset\BaseAsset\getValues(), Assetic\Asset\BaseAsset\getVars(), and Assetic\Util\VarUtils\resolve().

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  }
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
doLoad($content, FilterInterface $additionalFilter=null)
Encapsulates asset loading logic.
Definition: BaseAsset.php:84
getVars()
Returns an array of variable names for this asset.
Definition: BaseAsset.php:160
getValues()
Returns the current values for this asset.
Definition: BaseAsset.php:177
+ Here is the call graph for this function:

Field Documentation

◆ $ignoreErrors

Assetic\Asset\HttpAsset::$ignoreErrors
private

Definition at line 25 of file HttpAsset.php.

Referenced by Assetic\Asset\HttpAsset\__construct().

◆ $sourceUrl

Assetic\Asset\HttpAsset::$sourceUrl
private

Definition at line 24 of file HttpAsset.php.

Referenced by Assetic\Asset\HttpAsset\__construct().


The documentation for this class was generated from the following file: