Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
6 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
66 changes: 66 additions & 0 deletions
66
src/Symfony/Components/Finder/Iterator/DateRangeFilterIterator.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,66 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* DateRangeFilterIterator filters out files that are not in the given date range (last modified dates). | ||
* | ||
* @package Symfony | ||
* @subpackage Components_Finder | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
*/ | ||
class DateRangeFilterIterator extends \FilterIterator | ||
{ | ||
protected $minDate = false; | ||
protected $maxDate = false; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Iterator $iterator The Iterator to filter | ||
* @param integer $minDate The minimum date | ||
* @param integer $maxDate The maximum date | ||
*/ | ||
public function __construct(\Iterator $iterator, $minDate = false, $maxDate = false) | ||
{ | ||
$this->minDate = $minDate; | ||
$this->maxDate = $maxDate; | ||
|
||
parent::__construct($iterator); | ||
} | ||
|
||
/** | ||
* Filters the iterator values. | ||
* | ||
* @return Boolean true if the value should be kept, false otherwise | ||
*/ | ||
public function accept() | ||
{ | ||
$fileinfo = $this->getInnerIterator()->current(); | ||
|
||
if (!$fileinfo->isFile()) { | ||
return true; | ||
} | ||
|
||
$filedate = $fileinfo->getMTime(); | ||
|
||
if ( | ||
(false !== $this->minDate && $filedate < $this->minDate) | ||
|| | ||
(false !== $this->maxDate && $filedate > $this->maxDate) | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |