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
;
15 * PathFilterIterator filters files by path patterns (e.g. some/special/dir).
17 * @author Fabien Potencier <fabien@symfony.com>
18 * @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
20 class PathFilterIterator
extends MultiplePcreFilterIterator
23 * Filters the iterator values.
25 * @return bool true if the value should be kept, false otherwise
27 public function accept()
29 $filename = $this->current()->getRelativePathname();
31 if ('\\' === DIRECTORY_SEPARATOR
) {
32 $filename = str_replace('\\', '/', $filename);
35 // should at least not match one rule to exclude
36 foreach ($this->noMatchRegexps
as $regex) {
37 if (preg_match($regex, $filename)) {
42 // should at least match one rule
44 if ($this->matchRegexps
) {
46 foreach ($this->matchRegexps
as $regex) {
47 if (preg_match($regex, $filename)) {
57 * Converts strings to regexp.
59 * PCRE patterns are left unchanged.
62 * 'lorem/ipsum/dolor' ==> 'lorem\/ipsum\/dolor/'
64 * Use only / as directory separator (on Windows also).
66 * @param string $str Pattern: regexp or dirname.
68 * @return string regexp corresponding to a given string or regexp
70 protected function toRegex($str)
72 return $this->isRegex($str) ?
$str : '/'.preg_quote($str, '/').'/';