PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/finder/Symfony/Component/Finder/Iterator/FilenameFilterIterator.php

https://bitbucket.org/hermescarretero/simon-iniesta
PHP | 68 lines | 29 code | 9 blank | 30 comment | 3 complexity | 1352a170440d178a5461a004d89bb3de MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Finder\Iterator;
  11. use Symfony\Component\Finder\Glob;
  12. /**
  13. * FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class FilenameFilterIterator extends MultiplePcreFilterIterator
  18. {
  19. /**
  20. * Filters the iterator values.
  21. *
  22. * @return Boolean true if the value should be kept, false otherwise
  23. */
  24. public function accept()
  25. {
  26. $filename = $this->current()->getFilename();
  27. // should at least not match one rule to exclude
  28. foreach ($this->noMatchRegexps as $regex) {
  29. if (preg_match($regex, $filename)) {
  30. return false;
  31. }
  32. }
  33. // should at least match one rule
  34. $match = true;
  35. if ($this->matchRegexps) {
  36. $match = false;
  37. foreach ($this->matchRegexps as $regex) {
  38. if (preg_match($regex, $filename)) {
  39. return true;
  40. }
  41. }
  42. }
  43. return $match;
  44. }
  45. /**
  46. * Converts glob to regexp.
  47. *
  48. * PCRE patterns are left unchanged.
  49. * Glob strings are transformed with Glob::toRegex().
  50. *
  51. * @param string $str Pattern: glob or regexp
  52. *
  53. * @return string regexp corresponding to a given glob or regexp
  54. */
  55. protected function toRegex($str)
  56. {
  57. return $this->isRegex($str) ? $str : Glob::toRegex($str);
  58. }
  59. }