Source of file AssetCollectionIterator.php
Size: 2,737 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Asset/Iterator/AssetCollectionIterator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 OpenSky Project Inc * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Assetic\Asset\Iterator; use Assetic\Asset\AssetCollectionInterface; /** * Iterates over an asset collection. * * The iterator is responsible for cascading filters and target URL patterns * from parent to child assets. * * @author Kris Wallsmith <kris.wallsmith@gmail.com> */ class AssetCollectionIterator implements \RecursiveIterator { private $assets; private $filters; private $output; private $clones; public function __construct(AssetCollectionInterface $coll, \SplObjectStorage $clones) { $this->assets = $coll->all(); $this->filters = $coll->getFilters(); $this->output = $coll->getTargetPath(); $this->clones = $clones; if (false === $pos = strrpos($this->output, '.')) { $this->output .= '_*'; } else { $this->output = substr($this->output, 0, $pos).'_*'.substr($this->output, $pos); } } /** * Returns a copy of the current asset with filters and a target URL applied. * * @param Boolean $raw Returns the unmodified asset if true * @return \Assetic\Asset\AssetInterface */ public function current($raw = false) { $asset = current($this->assets); if ($raw) { return $asset; } // clone once if (!isset($this->clones[$asset])) { $clone = $this->clones[$asset] = clone $asset; // generate a target path based on asset name $name = sprintf('%s_%d', pathinfo($asset->getSourcePath(), PATHINFO_FILENAME) ?: 'part', $this->key() + 1); $clone->setTargetPath(str_replace('*', $name, $this->output)); } else { $clone = $this->clones[$asset]; } // cascade filters foreach ($this->filters as $filter) { $clone->ensureFilter($filter); } return $clone; } public function key() { return key($this->assets); } public function next() { return next($this->assets); } public function rewind() { return reset($this->assets); } public function valid() { return false !== current($this->assets); } public function hasChildren() { return current($this->assets) instanceof AssetCollectionInterface; } /** * @uses current() */ public function getChildren() { return new self($this->current(), $this->clones); } } |