Represents an asset loaded via an HTTP request.
@author Kris Wallsmith <kris.wallsmith@gmail.com>
Expanded class hierarchy of HttpAsset
class HttpAsset extends BaseAsset {
private $sourceUrl;
private $ignoreErrors;
/**
* Constructor.
*
* @param string $sourceUrl The source URL
* @param array $filters An array of filters
* @param Boolean $ignoreErrors
* @param array $vars
*
* @throws \InvalidArgumentException If the first argument is not an URL
*/
public function __construct($sourceUrl, $filters = array(), $ignoreErrors = false, array $vars = array()) {
if (0 === strpos($sourceUrl, '//')) {
$sourceUrl = 'http:' . $sourceUrl;
}
elseif (false === strpos($sourceUrl, '://')) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl));
}
$this->sourceUrl = $sourceUrl;
$this->ignoreErrors = $ignoreErrors;
list($scheme, $url) = explode('://', $sourceUrl, 2);
list($host, $path) = explode('/', $url, 2);
parent::__construct($filters, $scheme . '://' . $host, $path, $vars);
}
public function load(FilterInterface $additionalFilter = null) {
$content = @file_get_contents(VarUtils::resolve($this->sourceUrl, $this
->getVars(), $this
->getValues()));
if (false === $content && !$this->ignoreErrors) {
throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
}
$this
->doLoad($content, $additionalFilter);
}
public function getLastModified() {
if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(array(
'http' => array(
'method' => 'HEAD',
),
)))) {
foreach ($http_response_header as $header) {
if (0 === stripos($header, 'Last-Modified: ')) {
list(, $mtime) = explode(':', $header, 2);
return strtotime(trim($mtime));
}
}
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseAsset:: |
private | property | 1 | |
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
private | property | ||
BaseAsset:: |
public | function |
Clears all filters from the current asset. Overrides AssetInterface:: |
|
BaseAsset:: |
protected | function | Encapsulates asset loading logic. | |
BaseAsset:: |
public | function |
Applies dump filters and returns the asset as a string. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Ensures the current asset includes the supplied filter. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns the loaded content of the current asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns an array of filters currently applied. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns the relative path for the source asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns an absolute path or URL to the source asset's root directory. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns the URL for the current asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns the current values for this asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Returns an array of variable names for this asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Sets the content of the current asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Sets the URL for the current asset. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function |
Sets the values for the asset's variables. Overrides AssetInterface:: |
|
BaseAsset:: |
public | function | ||
HttpAsset:: |
private | property | ||
HttpAsset:: |
private | property | ||
HttpAsset:: |
public | function |
Returns the time the current asset was last modified. Overrides AssetInterface:: |
|
HttpAsset:: |
public | function |
Loads the asset into memory and applies load filters. Overrides AssetInterface:: |
|
HttpAsset:: |
public | function |
Constructor. Overrides BaseAsset:: |