1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
-
- /*
- * This file is part of the Assetic package, an OpenSky project.
- *
- * (c) 2010-2012 OpenSky Project Inc
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
- namespace Assetic\Filter;
-
- use Assetic\Asset\AssetInterface;
-
- /**
- * A collection of filters.
- *
- * @author Kris Wallsmith <kris.wallsmith@gmail.com>
- */
- class FilterCollection implements FilterInterface, \IteratorAggregate, \Countable
- {
- private $filters = array();
-
- public function __construct($filters = array())
- {
- foreach ($filters as $filter) {
- $this->ensure($filter);
- }
- }
-
- /**
- * Checks that the current collection contains the supplied filter.
- *
- * If the supplied filter is another filter collection, each of its
- * filters will be checked.
- */
- public function ensure(FilterInterface $filter)
- {
- if ($filter instanceof \Traversable) {
- foreach ($filter as $f) {
- $this->ensure($f);
- }
- } elseif (!in_array($filter, $this->filters, true)) {
- $this->filters[] = $filter;
- }
- }
-
- public function all()
- {
- return $this->filters;
- }
-
- public function clear()
- {
- $this->filters = array();
- }
-
- public function filterLoad(AssetInterface $asset)
- {
- foreach ($this->filters as $filter) {
- $filter->filterLoad($asset);
- }
- }
-
- public function filterDump(AssetInterface $asset)
- {
- foreach ($this->filters as $filter) {
- $filter->filterDump($asset);
- }
- }
-
- public function getIterator()
- {
- return new \ArrayIterator($this->filters);
- }
-
- public function count()
- {
- return count($this->filters);
- }
- }
|