4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Iterator
;
14 use Symfony\Component\Finder\Expression\Expression
;
17 * FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
19 * @author Fabien Potencier <fabien@symfony.com>
21 class FilenameFilterIterator
extends MultiplePcreFilterIterator
24 * Filters the iterator values.
26 * @return bool true if the value should be kept, false otherwise
28 public function accept()
30 $filename = $this->current()->getFilename();
32 // should at least not match one rule to exclude
33 foreach ($this->noMatchRegexps
as $regex) {
34 if (preg_match($regex, $filename)) {
39 // should at least match one rule
41 if ($this->matchRegexps
) {
43 foreach ($this->matchRegexps
as $regex) {
44 if (preg_match($regex, $filename)) {
54 * Converts glob to regexp.
56 * PCRE patterns are left unchanged.
57 * Glob strings are transformed with Glob::toRegex().
59 * @param string $str Pattern: glob or regexp
61 * @return string regexp corresponding to a given glob or regexp
63 protected function toRegex($str)
65 return Expression
::create($str)->getRegex()->render();