PhpAdapter.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\Adapter;
  11. use Symfony\Component\Finder\Iterator;
  12. /**
  13. * PHP finder engine implementation.
  14. *
  15. * @author Jean-François Simon <contact@jfsimon.fr>
  16. */
  17. class PhpAdapter extends AbstractAdapter
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function searchInDirectory($dir)
  23. {
  24. $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
  25. if ($this->followLinks) {
  26. $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
  27. }
  28. $iterator = new \RecursiveIteratorIterator(
  29. new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
  30. \RecursiveIteratorIterator::SELF_FIRST
  31. );
  32. if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
  33. $iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
  34. }
  35. if ($this->mode) {
  36. $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
  37. }
  38. if ($this->exclude) {
  39. $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
  40. }
  41. if ($this->names || $this->notNames) {
  42. $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
  43. }
  44. if ($this->contains || $this->notContains) {
  45. $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
  46. }
  47. if ($this->sizes) {
  48. $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
  49. }
  50. if ($this->dates) {
  51. $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
  52. }
  53. if ($this->filters) {
  54. $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
  55. }
  56. if ($this->sort) {
  57. $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
  58. $iterator = $iteratorAggregate->getIterator();
  59. }
  60. if ($this->paths || $this->notPaths) {
  61. $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
  62. }
  63. return $iterator;
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function getName()
  69. {
  70. return 'php';
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. protected function canBeUsed()
  76. {
  77. return true;
  78. }
  79. }