TYPO3  7.6
AbstractAdapter.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\Adapter;
13 
19 abstract class AbstractAdapter implements AdapterInterface
20 {
21  protected $followLinks = false;
22  protected $mode = 0;
23  protected $minDepth = 0;
24  protected $maxDepth = PHP_INT_MAX;
25  protected $exclude = array();
26  protected $names = array();
27  protected $notNames = array();
28  protected $contains = array();
29  protected $notContains = array();
30  protected $sizes = array();
31  protected $dates = array();
32  protected $filters = array();
33  protected $sort = false;
34  protected $paths = array();
35  protected $notPaths = array();
36  protected $ignoreUnreadableDirs = false;
37 
38  private static $areSupported = array();
39 
43  public function isSupported()
44  {
45  $name = $this->getName();
46 
47  if (!array_key_exists($name, self::$areSupported)) {
48  self::$areSupported[$name] = $this->canBeUsed();
49  }
50 
51  return self::$areSupported[$name];
52  }
53 
57  public function setFollowLinks($followLinks)
58  {
59  $this->followLinks = $followLinks;
60 
61  return $this;
62  }
63 
67  public function setMode($mode)
68  {
69  $this->mode = $mode;
70 
71  return $this;
72  }
73 
77  public function setDepths(array $depths)
78  {
79  $this->minDepth = 0;
80  $this->maxDepth = PHP_INT_MAX;
81 
82  foreach ($depths as $comparator) {
83  switch ($comparator->getOperator()) {
84  case '>':
85  $this->minDepth = $comparator->getTarget() + 1;
86  break;
87  case '>=':
88  $this->minDepth = $comparator->getTarget();
89  break;
90  case '<':
91  $this->maxDepth = $comparator->getTarget() - 1;
92  break;
93  case '<=':
94  $this->maxDepth = $comparator->getTarget();
95  break;
96  default:
97  $this->minDepth = $this->maxDepth = $comparator->getTarget();
98  }
99  }
100 
101  return $this;
102  }
103 
107  public function setExclude(array $exclude)
108  {
109  $this->exclude = $exclude;
110 
111  return $this;
112  }
113 
117  public function setNames(array $names)
118  {
119  $this->names = $names;
120 
121  return $this;
122  }
123 
127  public function setNotNames(array $notNames)
128  {
129  $this->notNames = $notNames;
130 
131  return $this;
132  }
133 
137  public function setContains(array $contains)
138  {
139  $this->contains = $contains;
140 
141  return $this;
142  }
143 
147  public function setNotContains(array $notContains)
148  {
149  $this->notContains = $notContains;
150 
151  return $this;
152  }
153 
157  public function setSizes(array $sizes)
158  {
159  $this->sizes = $sizes;
160 
161  return $this;
162  }
163 
167  public function setDates(array $dates)
168  {
169  $this->dates = $dates;
170 
171  return $this;
172  }
173 
177  public function setFilters(array $filters)
178  {
179  $this->filters = $filters;
180 
181  return $this;
182  }
183 
187  public function setSort($sort)
188  {
189  $this->sort = $sort;
190 
191  return $this;
192  }
193 
197  public function setPath(array $paths)
198  {
199  $this->paths = $paths;
200 
201  return $this;
202  }
203 
207  public function setNotPath(array $notPaths)
208  {
209  $this->notPaths = $notPaths;
210 
211  return $this;
212  }
213 
217  public function ignoreUnreadableDirs($ignore = true)
218  {
219  $this->ignoreUnreadableDirs = (bool) $ignore;
220 
221  return $this;
222  }
223 
235  abstract protected function canBeUsed();
236 }