class HttpAsset

Represents an asset loaded via an HTTP request.

@author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of HttpAsset

2 files declare their use of HttpAsset
AssetFactory.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/AssetFactory.php
CssImportFilter.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/CssImportFilter.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/HttpAsset.php, line 22

Namespace

Assetic\Asset
View source
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));
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseAsset::$content private property 1
BaseAsset::$filters private property
BaseAsset::$loaded private property
BaseAsset::$sourcePath private property
BaseAsset::$sourceRoot private property
BaseAsset::$targetPath private property
BaseAsset::$values private property
BaseAsset::$vars private property
BaseAsset::clearFilters public function Clears all filters from the current asset. Overrides AssetInterface::clearFilters
BaseAsset::doLoad protected function Encapsulates asset loading logic.
BaseAsset::dump public function Applies dump filters and returns the asset as a string. Overrides AssetInterface::dump
BaseAsset::ensureFilter public function Ensures the current asset includes the supplied filter. Overrides AssetInterface::ensureFilter
BaseAsset::getContent public function Returns the loaded content of the current asset. Overrides AssetInterface::getContent
BaseAsset::getFilters public function Returns an array of filters currently applied. Overrides AssetInterface::getFilters
BaseAsset::getSourcePath public function Returns the relative path for the source asset. Overrides AssetInterface::getSourcePath
BaseAsset::getSourceRoot public function Returns an absolute path or URL to the source asset's root directory. Overrides AssetInterface::getSourceRoot
BaseAsset::getTargetPath public function Returns the URL for the current asset. Overrides AssetInterface::getTargetPath
BaseAsset::getValues public function Returns the current values for this asset. Overrides AssetInterface::getValues
BaseAsset::getVars public function Returns an array of variable names for this asset. Overrides AssetInterface::getVars
BaseAsset::setContent public function Sets the content of the current asset. Overrides AssetInterface::setContent
BaseAsset::setTargetPath public function Sets the URL for the current asset. Overrides AssetInterface::setTargetPath
BaseAsset::setValues public function Sets the values for the asset's variables. Overrides AssetInterface::setValues
BaseAsset::__clone public function
HttpAsset::$ignoreErrors private property
HttpAsset::$sourceUrl private property
HttpAsset::getLastModified public function Returns the time the current asset was last modified. Overrides AssetInterface::getLastModified
HttpAsset::load public function Loads the asset into memory and applies load filters. Overrides AssetInterface::load
HttpAsset::__construct public function Constructor. Overrides BaseAsset::__construct