Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Finder] refactored directory depth management
- Loading branch information
Showing
10 changed files
with
194 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Symfony/Components/Finder/Iterator/DepthRangeFilterIterator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* DepthRangeFilterIterator limits the directory depth. | ||
* | ||
* @package Symfony | ||
* @subpackage Components_Finder | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
*/ | ||
class DepthRangeFilterIterator extends \FilterIterator | ||
{ | ||
protected $minDepth = 0; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Iterator $iterator The Iterator to filter | ||
* @param array $comparators An array of \NumberComparator instances | ||
*/ | ||
public function __construct(\RecursiveIteratorIterator $iterator, array $comparators) | ||
{ | ||
$minDepth = 0; | ||
$maxDepth = INF; | ||
foreach ($comparators as $comparator) { | ||
switch ($comparator->getOperator()) { | ||
case '>': | ||
$minDepth = $comparator->getTarget() + 1; | ||
break; | ||
case '>=': | ||
$minDepth = $comparator->getTarget(); | ||
break; | ||
case '<': | ||
$maxDepth = $comparator->getTarget() - 1; | ||
break; | ||
case '<=': | ||
$maxDepth = $comparator->getTarget(); | ||
break; | ||
default: | ||
$minDepth = $maxDepth = $comparator->getTarget(); | ||
} | ||
} | ||
|
||
$this->minDepth = $minDepth; | ||
$iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth); | ||
|
||
parent::__construct($iterator); | ||
} | ||
|
||
/** | ||
* Filters the iterator values. | ||
* | ||
* @return Boolean true if the value should be kept, false otherwise | ||
*/ | ||
public function accept() | ||
{ | ||
return $this->getInnerIterator()->getDepth() >= $this->minDepth; | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
src/Symfony/Components/Finder/Iterator/LimitDepthFilterIterator.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.