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:
14: /**
15: * Interface for finder engine implementations.
16: *
17: * @author Jean-François Simon <contact@jfsimon.fr>
18: */
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:
37: private static $areSupported = array();
38:
39: /**
40: * {@inheritDoc}
41: */
42: public function isSupported()
43: {
44: $name = $this->getName();
45:
46: if (!array_key_exists($name, self::$areSupported)) {
47: self::$areSupported[$name] = $this->canBeUsed();
48: }
49:
50: return self::$areSupported[$name];
51: }
52:
53: /**
54: * {@inheritdoc}
55: */
56: public function setFollowLinks($followLinks)
57: {
58: $this->followLinks = $followLinks;
59:
60: return $this;
61: }
62:
63: /**
64: * {@inheritdoc}
65: */
66: public function setMode($mode)
67: {
68: $this->mode = $mode;
69:
70: return $this;
71: }
72:
73: /**
74: * {@inheritdoc}
75: */
76: public function setDepths(array $depths)
77: {
78: $this->minDepth = 0;
79: $this->maxDepth = PHP_INT_MAX;
80:
81: foreach ($depths as $comparator) {
82: switch ($comparator->getOperator()) {
83: case '>':
84: $this->minDepth = $comparator->getTarget() + 1;
85: break;
86: case '>=':
87: $this->minDepth = $comparator->getTarget();
88: break;
89: case '<':
90: $this->maxDepth = $comparator->getTarget() - 1;
91: break;
92: case '<=':
93: $this->maxDepth = $comparator->getTarget();
94: break;
95: default:
96: $this->minDepth = $this->maxDepth = $comparator->getTarget();
97: }
98: }
99:
100: return $this;
101: }
102:
103: /**
104: * {@inheritdoc}
105: */
106: public function setExclude(array $exclude)
107: {
108: $this->exclude = $exclude;
109:
110: return $this;
111: }
112:
113: /**
114: * {@inheritdoc}
115: */
116: public function setNames(array $names)
117: {
118: $this->names = $names;
119:
120: return $this;
121: }
122:
123: /**
124: * {@inheritdoc}
125: */
126: public function setNotNames(array $notNames)
127: {
128: $this->notNames = $notNames;
129:
130: return $this;
131: }
132:
133: /**
134: * {@inheritdoc}
135: */
136: public function setContains(array $contains)
137: {
138: $this->contains = $contains;
139:
140: return $this;
141: }
142:
143: /**
144: * {@inheritdoc}
145: */
146: public function setNotContains(array $notContains)
147: {
148: $this->notContains = $notContains;
149:
150: return $this;
151: }
152:
153: /**
154: * {@inheritdoc}
155: */
156: public function setSizes(array $sizes)
157: {
158: $this->sizes = $sizes;
159:
160: return $this;
161: }
162:
163: /**
164: * {@inheritdoc}
165: */
166: public function setDates(array $dates)
167: {
168: $this->dates = $dates;
169:
170: return $this;
171: }
172:
173: /**
174: * {@inheritdoc}
175: */
176: public function setFilters(array $filters)
177: {
178: $this->filters = $filters;
179:
180: return $this;
181: }
182:
183: /**
184: * {@inheritdoc}
185: */
186: public function setSort($sort)
187: {
188: $this->sort = $sort;
189:
190: return $this;
191: }
192:
193: /**
194: * {@inheritdoc}
195: */
196: public function setPath(array $paths)
197: {
198: $this->paths = $paths;
199:
200: return $this;
201: }
202:
203: /**
204: * {@inheritdoc}
205: */
206: public function setNotPath(array $notPaths)
207: {
208: $this->notPaths = $notPaths;
209:
210: return $this;
211: }
212:
213: /**
214: * Returns whether the adapter is supported in the current environment.
215: *
216: * This method should be implemented in all adapters. Do not implement
217: * isSupported in the adapters as the generic implementation provides a cache
218: * layer.
219: *
220: * @see isSupported
221: *
222: * @return Boolean Whether the adapter is supported
223: */
224: abstract protected function canBeUsed();
225: }
226: