X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Ffinder%2FFinder.php;h=278b9841f619e2393668fe1b4ea89864e709b045;hb=9e65bae52407293a5182f19dc57b5628b09e92f4;hp=e6a5442f1fff7fe861e17e282c2762f4f60af6dd;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/finder/Finder.php b/vendor/symfony/finder/Finder.php index e6a5442f1..278b9841f 100644 --- a/vendor/symfony/finder/Finder.php +++ b/vendor/symfony/finder/Finder.php @@ -11,13 +11,8 @@ namespace Symfony\Component\Finder; -use Symfony\Component\Finder\Adapter\AdapterInterface; -use Symfony\Component\Finder\Adapter\GnuFindAdapter; -use Symfony\Component\Finder\Adapter\BsdFindAdapter; -use Symfony\Component\Finder\Adapter\PhpAdapter; use Symfony\Component\Finder\Comparator\DateComparator; use Symfony\Component\Finder\Comparator\NumberComparator; -use Symfony\Component\Finder\Exception\ExceptionInterface; use Symfony\Component\Finder\Iterator\CustomFilterIterator; use Symfony\Component\Finder\Iterator\DateRangeFilterIterator; use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator; @@ -60,16 +55,12 @@ class Finder implements \IteratorAggregate, \Countable private $iterators = array(); private $contains = array(); private $notContains = array(); - private $adapters = null; private $paths = array(); private $notPaths = array(); private $ignoreUnreadableDirs = false; private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg'); - /** - * Constructor. - */ public function __construct() { $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES; @@ -85,110 +76,6 @@ class Finder implements \IteratorAggregate, \Countable return new static(); } - /** - * Registers a finder engine implementation. - * - * @param AdapterInterface $adapter An adapter instance - * @param int $priority Highest is selected first - * - * @return $this - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function addAdapter(AdapterInterface $adapter, $priority = 0) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - $this->initDefaultAdapters(); - - $this->adapters[$adapter->getName()] = array( - 'adapter' => $adapter, - 'priority' => $priority, - 'selected' => false, - ); - - return $this->sortAdapters(); - } - - /** - * Sets the selected adapter to the best one according to the current platform the code is run on. - * - * @return $this - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function useBestAdapter() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - $this->initDefaultAdapters(); - - $this->resetAdapterSelection(); - - return $this->sortAdapters(); - } - - /** - * Selects the adapter to use. - * - * @param string $name - * - * @return $this - * - * @throws \InvalidArgumentException - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function setAdapter($name) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - $this->initDefaultAdapters(); - - if (!isset($this->adapters[$name])) { - throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name)); - } - - $this->resetAdapterSelection(); - $this->adapters[$name]['selected'] = true; - - return $this->sortAdapters(); - } - - /** - * Removes all adapters registered in the finder. - * - * @return $this - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function removeAdapters() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - $this->adapters = array(); - - return $this; - } - - /** - * Returns registered adapters ordered by priority without extra information. - * - * @return AdapterInterface[] - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function getAdapters() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - $this->initDefaultAdapters(); - - return array_values(array_map(function (array $adapter) { - return $adapter['adapter']; - }, $this->adapters)); - } - /** * Restricts the matching to directories only. * @@ -410,6 +297,10 @@ class Finder implements \IteratorAggregate, \Countable /** * Excludes directories. * + * Directories passed as argument must be relative to the ones defined with the `in()` method. For example: + * + * $finder->in(__DIR__)->exclude('ruby'); + * * @param string|array $dirs A directory path or an array of directories * * @return $this @@ -426,6 +317,8 @@ class Finder implements \IteratorAggregate, \Countable /** * Excludes "hidden" directories and files (starting with a dot). * + * This option is enabled by default. + * * @param bool $ignoreDotFiles Whether to exclude "hidden" files or not * * @return $this @@ -446,6 +339,8 @@ class Finder implements \IteratorAggregate, \Countable /** * Forces the finder to ignore version control directories. * + * This option is enabled by default. + * * @param bool $ignoreVCS Whether to exclude VCS files or not * * @return $this @@ -486,8 +381,6 @@ class Finder implements \IteratorAggregate, \Countable * * This can be slow as all the matching files and directories must be retrieved for comparison. * - * @param \Closure $closure An anonymous function - * * @return $this * * @see SortableIterator @@ -593,8 +486,6 @@ class Finder implements \IteratorAggregate, \Countable * The anonymous function receives a \SplFileInfo and must return false * to remove files. * - * @param \Closure $closure An anonymous function - * * @return $this * * @see CustomFilterIterator @@ -649,9 +540,9 @@ class Finder implements \IteratorAggregate, \Countable foreach ((array) $dirs as $dir) { if (is_dir($dir)) { - $resolvedDirs[] = $dir; + $resolvedDirs[] = $this->normalizeDir($dir); } elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) { - $resolvedDirs = array_merge($resolvedDirs, $glob); + $resolvedDirs = array_merge($resolvedDirs, array_map(array($this, 'normalizeDir'), $glob)); } else { throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir)); } @@ -702,7 +593,7 @@ class Finder implements \IteratorAggregate, \Countable * * @return $this * - * @throws \InvalidArgumentException When the given argument is not iterable. + * @throws \InvalidArgumentException when the given argument is not iterable */ public function append($iterator) { @@ -724,29 +615,27 @@ class Finder implements \IteratorAggregate, \Countable } /** - * Counts all the results collected by the iterators. + * Check if the any results were found. * - * @return int + * @return bool */ - public function count() + public function hasResults() { - return iterator_count($this->getIterator()); + foreach ($this->getIterator() as $_) { + return true; + } + + return false; } /** - * @return $this + * Counts all the results collected by the iterators. + * + * @return int */ - private function sortAdapters() + public function count() { - uasort($this->adapters, function (array $a, array $b) { - if ($a['selected'] || $b['selected']) { - return $a['selected'] ? -1 : 1; - } - - return $a['priority'] > $b['priority'] ? -1 : 1; - }); - - return $this; + return iterator_count($this->getIterator()); } /** @@ -764,19 +653,6 @@ class Finder implements \IteratorAggregate, \Countable $this->notPaths[] = '#(^|/)\..+(/|$)#'; } - if ($this->adapters) { - foreach ($this->adapters as $adapter) { - if ($adapter['adapter']->isSupported()) { - try { - return $this - ->buildAdapter($adapter['adapter']) - ->searchInDirectory($dir); - } catch (ExceptionInterface $e) { - } - } - } - } - $minDepth = 0; $maxDepth = PHP_INT_MAX; @@ -854,52 +730,14 @@ class Finder implements \IteratorAggregate, \Countable } /** - * @param AdapterInterface $adapter + * Normalizes given directory names by removing trailing slashes. * - * @return AdapterInterface - */ - private function buildAdapter(AdapterInterface $adapter) - { - return $adapter - ->setFollowLinks($this->followLinks) - ->setDepths($this->depths) - ->setMode($this->mode) - ->setExclude($this->exclude) - ->setNames($this->names) - ->setNotNames($this->notNames) - ->setContains($this->contains) - ->setNotContains($this->notContains) - ->setSizes($this->sizes) - ->setDates($this->dates) - ->setFilters($this->filters) - ->setSort($this->sort) - ->setPath($this->paths) - ->setNotPath($this->notPaths) - ->ignoreUnreadableDirs($this->ignoreUnreadableDirs); - } - - /** - * Unselects all adapters. + * @param string $dir + * + * @return string */ - private function resetAdapterSelection() - { - $this->adapters = array_map(function (array $properties) { - $properties['selected'] = false; - - return $properties; - }, $this->adapters); - } - - private function initDefaultAdapters() + private function normalizeDir($dir) { - if (null === $this->adapters) { - $this->adapters = array(); - $this - ->addAdapter(new GnuFindAdapter()) - ->addAdapter(new BsdFindAdapter()) - ->addAdapter(new PhpAdapter(), -50) - ->setAdapter('php') - ; - } + return rtrim($dir, '/'.\DIRECTORY_SEPARATOR); } }