[Finder] replaced ChainIterator with PHP built-in AppendIterator
This commit is contained in:
parent
4be3a508f1
commit
376ca78346
@ -288,10 +288,10 @@ class Finder
|
|||||||
{
|
{
|
||||||
if (is_array($dir))
|
if (is_array($dir))
|
||||||
{
|
{
|
||||||
$iterator = new Iterator\ChainIterator();
|
$iterator = new \AppendIterator();
|
||||||
foreach ($dir as $d)
|
foreach ($dir as $d)
|
||||||
{
|
{
|
||||||
$iterator->attach($this->searchInDirectory($d));
|
$iterator->append($this->searchInDirectory($d));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $iterator;
|
return $iterator;
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Components\Finder\Iterator;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony framework.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ChainIterator iterates through several iterators, one at a time.
|
|
||||||
*
|
|
||||||
* @package Symfony
|
|
||||||
* @subpackage Components_Finder
|
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*/
|
|
||||||
class ChainIterator implements \Iterator
|
|
||||||
{
|
|
||||||
protected $iterators;
|
|
||||||
protected $current;
|
|
||||||
protected $cursor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param Iterator[] $iterators An array of \Iterator instances
|
|
||||||
*/
|
|
||||||
public function __construct(array $iterators = array())
|
|
||||||
{
|
|
||||||
$this->iterators = array();
|
|
||||||
foreach ($iterators as $iterator)
|
|
||||||
{
|
|
||||||
$this->attach($iterator);
|
|
||||||
}
|
|
||||||
$this->rewind();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function attach(\Iterator $iterator)
|
|
||||||
{
|
|
||||||
$this->iterators[] = $iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
$this->cursor = 0;
|
|
||||||
$this->current = 0;
|
|
||||||
foreach ($this->iterators as $iterator)
|
|
||||||
{
|
|
||||||
$iterator->rewind();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
if ($this->current > count($this->iterators) - 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// still something for the current iterator?
|
|
||||||
if ($this->iterators[$this->current]->valid())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// go to the next one
|
|
||||||
++$this->current;
|
|
||||||
|
|
||||||
return $this->valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
$this->iterators[$this->current]->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
return $this->iterators[$this->current]->current();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->cursor++;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Tests\Components\Finder\Iterator;
|
|
||||||
|
|
||||||
use Symfony\Components\Finder\Iterator\ChainIterator;
|
|
||||||
|
|
||||||
require_once __DIR__.'/IteratorTestCase.php';
|
|
||||||
|
|
||||||
class ChainIteratorTest extends IteratorTestCase
|
|
||||||
{
|
|
||||||
public function testAccept()
|
|
||||||
{
|
|
||||||
$inner1 = new Iterator(array('test.php', 'test.py'));
|
|
||||||
$inner2 = new Iterator(array());
|
|
||||||
$inner3 = new Iterator(array('foo.php'));
|
|
||||||
|
|
||||||
$iterator = new ChainIterator(array($inner1, $inner2, $inner3));
|
|
||||||
|
|
||||||
$this->assertIterator(array('test.php', 'test.py', 'foo.php'), $iterator);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user