4
* This file is part of the Assetic package, an OpenSky project.
6
* (c) 2010-2013 OpenSky Project Inc
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
12
namespace Assetic\Asset\Iterator;
15
* Asset collection filter iterator.
17
* The filter iterator is responsible for de-duplication of leaf assets based
18
* on both strict equality and source URL.
20
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
22
class AssetCollectionFilterIterator extends \RecursiveFilterIterator
30
* @param AssetCollectionIterator $iterator The inner iterator
31
* @param array $visited An array of visited asset objects
32
* @param array $sources An array of visited source strings
34
public function __construct(AssetCollectionIterator $iterator, array $visited = array(), array $sources = array())
36
parent::__construct($iterator);
38
$this->visited = $visited;
39
$this->sources = $sources;
43
* Determines whether the current asset is a duplicate.
45
* De-duplication is performed based on either strict equality or by
48
* @return Boolean Returns true if we have not seen this asset yet
50
public function accept()
52
$asset = $this->getInnerIterator()->current(true);
55
// check strict equality
56
if (in_array($asset, $this->visited, true)) {
59
$this->visited[] = $asset;
63
$sourceRoot = $asset->getSourceRoot();
64
$sourcePath = $asset->getSourcePath();
65
if ($sourceRoot && $sourcePath) {
66
$source = $sourceRoot.'/'.$sourcePath;
67
if (in_array($source, $this->sources)) {
70
$this->sources[] = $source;
78
* Passes visited objects and source URLs to the child iterator.
80
public function getChildren()
82
return new self($this->getInnerIterator()->getChildren(), $this->visited, $this->sources);