123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\Finder\Adapter;
- /**
- * Interface for finder engine implementations.
- *
- * @author Jean-François Simon <contact@jfsimon.fr>
- */
- abstract class AbstractAdapter implements AdapterInterface
- {
- protected $followLinks = false;
- protected $mode = 0;
- protected $minDepth = 0;
- protected $maxDepth = PHP_INT_MAX;
- protected $exclude = array();
- protected $names = array();
- protected $notNames = array();
- protected $contains = array();
- protected $notContains = array();
- protected $sizes = array();
- protected $dates = array();
- protected $filters = array();
- protected $sort = false;
- protected $paths = array();
- protected $notPaths = array();
- protected $ignoreUnreadableDirs = false;
- private static $areSupported = array();
- /**
- * {@inheritDoc}
- */
- public function isSupported()
- {
- $name = $this->getName();
- if (!array_key_exists($name, self::$areSupported)) {
- self::$areSupported[$name] = $this->canBeUsed();
- }
- return self::$areSupported[$name];
- }
- /**
- * {@inheritdoc}
- */
- public function setFollowLinks($followLinks)
- {
- $this->followLinks = $followLinks;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setMode($mode)
- {
- $this->mode = $mode;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setDepths(array $depths)
- {
- $this->minDepth = 0;
- $this->maxDepth = PHP_INT_MAX;
- foreach ($depths as $comparator) {
- switch ($comparator->getOperator()) {
- case '>':
- $this->minDepth = $comparator->getTarget() + 1;
- break;
- case '>=':
- $this->minDepth = $comparator->getTarget();
- break;
- case '<':
- $this->maxDepth = $comparator->getTarget() - 1;
- break;
- case '<=':
- $this->maxDepth = $comparator->getTarget();
- break;
- default:
- $this->minDepth = $this->maxDepth = $comparator->getTarget();
- }
- }
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setExclude(array $exclude)
- {
- $this->exclude = $exclude;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setNames(array $names)
- {
- $this->names = $names;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setNotNames(array $notNames)
- {
- $this->notNames = $notNames;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setContains(array $contains)
- {
- $this->contains = $contains;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setNotContains(array $notContains)
- {
- $this->notContains = $notContains;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setSizes(array $sizes)
- {
- $this->sizes = $sizes;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setDates(array $dates)
- {
- $this->dates = $dates;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setFilters(array $filters)
- {
- $this->filters = $filters;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setSort($sort)
- {
- $this->sort = $sort;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setPath(array $paths)
- {
- $this->paths = $paths;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setNotPath(array $notPaths)
- {
- $this->notPaths = $notPaths;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function ignoreUnreadableDirs($ignore = true)
- {
- $this->ignoreUnreadableDirs = (Boolean) $ignore;
- return $this;
- }
- /**
- * Returns whether the adapter is supported in the current environment.
- *
- * This method should be implemented in all adapters. Do not implement
- * isSupported in the adapters as the generic implementation provides a cache
- * layer.
- *
- * @see isSupported
- *
- * @return Boolean Whether the adapter is supported
- */
- abstract protected function canBeUsed();
- }
|