Represents an asset loaded from a file.
@author Kris Wallsmith <kris.wallsmith@gmail.com>
Expanded class hierarchy of FileAsset
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);
}
}
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 | ||
FileAsset:: |
private | property | ||
FileAsset:: |
public | function |
Returns the time the current asset was last modified. Overrides AssetInterface:: |
|
FileAsset:: |
public | function |
Loads the asset into memory and applies load filters. Overrides AssetInterface:: |
|
FileAsset:: |
public | function |
Constructor. Overrides BaseAsset:: |