TYPO3  7.6
FilecontentFilterIterator.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Iterator;
13 
21 {
27  public function accept()
28  {
29  if (!$this->matchRegexps && !$this->noMatchRegexps) {
30  return true;
31  }
32 
33  $fileinfo = $this->current();
34 
35  if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
36  return false;
37  }
38 
39  $content = $fileinfo->getContents();
40  if (!$content) {
41  return false;
42  }
43 
44  // should at least not match one rule to exclude
45  foreach ($this->noMatchRegexps as $regex) {
46  if (preg_match($regex, $content)) {
47  return false;
48  }
49  }
50 
51  // should at least match one rule
52  $match = true;
53  if ($this->matchRegexps) {
54  $match = false;
55  foreach ($this->matchRegexps as $regex) {
56  if (preg_match($regex, $content)) {
57  return true;
58  }
59  }
60  }
61 
62  return $match;
63  }
64 
72  protected function toRegex($str)
73  {
74  return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
75  }
76 }