X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Ffinder%2FFinder.php;fp=vendor%2Fsymfony%2Ffinder%2FFinder.php;h=278b9841f619e2393668fe1b4ea89864e709b045;hp=4d9b470fe1fdc37ae048ebbc2ef8cc1a833b27ec;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/finder/Finder.php b/vendor/symfony/finder/Finder.php index 4d9b470fe..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,7 +55,6 @@ 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; @@ -82,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 Symfony 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 Symfony 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 Symfony 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 Symfony 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 Symfony 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. * @@ -407,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 @@ -646,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)); } @@ -721,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()); } /** @@ -761,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; @@ -851,50 +730,14 @@ class Finder implements \IteratorAggregate, \Countable } /** - * @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. + * Normalizes given directory names by removing trailing slashes. + * + * @param string $dir + * + * @return string */ - private function resetAdapterSelection() + private function normalizeDir($dir) { - $this->adapters = array_map(function (array $properties) { - $properties['selected'] = false; - - return $properties; - }, $this->adapters); - } - - private function initDefaultAdapters() - { - 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); } }