45 $this->assets = array();
52 $this->clones = new \SplObjectStorage();
54 $this->values = array();
60 $this->clones = new \SplObjectStorage();
70 $this->assets[] = $asset;
75 foreach ($this->assets as $i => $asset) {
76 $clone = isset($this->clones[$asset]) ? $this->clones[$asset] :
null;
77 if (in_array($needle, array($asset, $clone),
true)) {
78 unset($this->clones[$asset], $this->assets[$i]);
92 throw new \InvalidArgumentException(
'Leaf not found.');
97 foreach ($this->assets as $i => $asset) {
98 $clone = isset($this->clones[$asset]) ? $this->clones[$asset] :
null;
99 if (in_array($needle, array($asset, $clone),
true)) {
100 unset($this->clones[$asset]);
101 $this->assets[$i] = $replacement;
115 throw new \InvalidArgumentException(
'Leaf not found.');
120 $this->filters->ensure($filter);
125 return $this->filters->all();
130 $this->filters->clear();
131 $this->clones = new \SplObjectStorage();
138 foreach ($this as $asset) {
139 $asset->load($additionalFilter);
140 $parts[] = $asset->getContent();
143 $this->content = implode(
"\n", $parts);
150 foreach ($this as $asset) {
151 $parts[] = $asset->dump($additionalFilter);
154 return implode(
"\n", $parts);
197 if (!count($this->assets)) {
202 foreach ($this as $asset) {
203 $assetMtime = $asset->getLastModified();
204 if ($assetMtime > $mtime) {
205 $mtime = $assetMtime;
229 foreach ($this as $asset) {
230 $asset->setValues(array_intersect_key(
$values, array_flip($asset->getVars())));
ensureFilter(FilterInterface $filter)
Ensures the current asset includes the supplied filter.
getVars()
Returns an array of variable names for this asset.
getFilters()
Returns an array of filters currently applied.
replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful=false)
Replaces an existing leaf with a new one.
dump(FilterInterface $additionalFilter=null)
Applies dump filters and returns the asset as a string.
__construct($assets=array(), $filters=array(), $sourceRoot=null, array $vars=array())
Constructor.
getContent()
Returns the loaded content of the current asset.
all()
Returns all child assets.
getSourcePath()
Returns the relative path for the source asset.
getTargetPath()
Returns the URL for the current asset.
getSourceDirectory()
Returns the asset's source directory.
getLastModified()
Returns the highest last-modified value of all assets in the current collection.
setTargetPath($targetPath)
Sets the URL for the current asset.
clearFilters()
Clears all filters from the current asset.
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
getIterator()
Returns an iterator for looping recursively over unique leaves.
setContent($content)
Sets the content of the current asset.
add(AssetInterface $asset)
Adds an asset to the current collection.
getValues()
Returns the current values for this asset.
setValues(array $values)
Sets the values for the asset's variables.
removeLeaf(AssetInterface $needle, $graceful=false)
Removes a leaf.
getSourceRoot()
Returns an absolute path or URL to the source asset's root directory.
Asset collection filter iterator.
Iterates over an asset collection.
An exception for terminatinating execution or to throw for unit testing.
replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful=false)
Replaces an existing leaf with a new one.
removeLeaf(AssetInterface $leaf, $graceful=false)
Removes a leaf.
An asset has a mutable URL and content and can be loaded and dumped.
A filter manipulates an asset at load and dump.