Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Component][Finder] ->path(), ->notPath() methods (with basic tests)
- Loading branch information
Showing
15 changed files
with
459 additions
and
105 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
75 changes: 75 additions & 0 deletions
75
src/Symfony/Component/Finder/Iterator/PathFilterIterator.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,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Finder\Iterator; | ||
|
||
/** | ||
* PathFilterIterator filters files by path patterns (e.g. some/special/dir). | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl> | ||
*/ | ||
class PathFilterIterator extends MultiplePcreFilterIterator | ||
{ | ||
|
||
/** | ||
* Filters the iterator values. | ||
* | ||
* @return Boolean true if the value should be kept, false otherwise | ||
*/ | ||
public function accept() | ||
{ | ||
$filename = $this->current()->getRelativePathname(); | ||
|
||
if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | ||
$filename = strtr($filename, '\\', '/'); | ||
} | ||
|
||
// should at least not match one rule to exclude | ||
foreach ($this->noMatchRegexps as $regex) { | ||
if (preg_match($regex, $filename)) { | ||
return false; | ||
} | ||
} | ||
|
||
// should at least match one rule | ||
$match = true; | ||
if ($this->matchRegexps) { | ||
$match = false; | ||
foreach ($this->matchRegexps as $regex) { | ||
if (preg_match($regex, $filename)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return $match; | ||
} | ||
|
||
/** | ||
* Converts strings to regexp. | ||
* | ||
* PCRE patterns are left unchanged. | ||
* | ||
* Default conversion: | ||
* 'lorem/ipsum/dolor' ==> 'lorem\/ipsum\/dolor/' | ||
* | ||
* Use only / as directory separator (on Windows also). | ||
* | ||
* @param string $str Pattern: regexp or dirname. | ||
* | ||
* @return string regexp corresponding to a given string or regexp | ||
*/ | ||
protected function toRegex($str) | ||
{ | ||
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/'; | ||
} | ||
} |
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
21 changes: 21 additions & 0 deletions
21
src/Symfony/Component/Finder/Tests/Iterator/MockFileListIterator.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,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Finder\Tests\Iterator; | ||
|
||
class MockFileListIterator extends \ArrayIterator | ||
{ | ||
public function __construct(array $filesArray = array()) | ||
{ | ||
$files = array_map(function($file){ return new MockSplFileInfo($file); }, $filesArray); | ||
parent::__construct($files); | ||
} | ||
} |
Oops, something went wrong.