class FileAsset

Represents an asset loaded from a file.

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

Hierarchy

Expanded class hierarchy of FileAsset

23 files declare their use of FileAsset
AssetCollectionTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Asset/AssetCollectionTest.php
AssetFactory.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/AssetFactory.php
AssetWriterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/AssetWriterTest.php
CompassFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/CompassFilterTest.php
CssEmbedFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/CssEmbedFilterTest.php

... See full list

File

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

Namespace

Assetic\Asset
View source
class FileAsset extends BaseAsset {
  private $source;

  /**
   * Constructor.
   *
   * @param string $source     An absolute path
   * @param array  $filters    An array of filters
   * @param string $sourceRoot The source asset root directory
   * @param string $sourcePath The source asset path
   *
   * @throws \InvalidArgumentException If the supplied root doesn't match the source when guessing the path
   */
  public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array()) {
    if (null === $sourceRoot) {
      $sourceRoot = dirname($source);
      if (null === $sourcePath) {
        $sourcePath = basename($source);
      }
    }
    elseif (null === $sourcePath) {
      if (0 !== strpos($source, $sourceRoot)) {
        throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot));
      }
      $sourcePath = substr($source, strlen($sourceRoot) + 1);
    }
    $this->source = $source;
    parent::__construct($filters, $sourceRoot, $sourcePath, $vars);
  }
  public function load(FilterInterface $additionalFilter = null) {
    $source = PathUtils::resolvePath($this->source, $this
      ->getVars(), $this
      ->getValues());
    if (!is_file($source)) {
      throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
    }
    $this
      ->doLoad(file_get_contents($source), $additionalFilter);
  }
  public function getLastModified() {
    $source = PathUtils::resolvePath($this->source, $this
      ->getVars(), $this
      ->getValues());
    if (!is_file($source)) {
      throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
    }
    return filemtime($source);
  }

}

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
FileAsset::$source private property
FileAsset::getLastModified public function Returns the time the current asset was last modified. Overrides AssetInterface::getLastModified
FileAsset::load public function Loads the asset into memory and applies load filters. Overrides AssetInterface::load
FileAsset::__construct public function Constructor. Overrides BaseAsset::__construct