Drupal investigation

AbstractAdapter.php 4.9KB

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