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