[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/finder/ -> Finder.php (source)

   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;
  13  
  14  use Symfony\Component\Finder\Adapter\AdapterInterface;
  15  use Symfony\Component\Finder\Adapter\BsdFindAdapter;
  16  use Symfony\Component\Finder\Adapter\GnuFindAdapter;
  17  use Symfony\Component\Finder\Adapter\PhpAdapter;
  18  use Symfony\Component\Finder\Comparator\DateComparator;
  19  use Symfony\Component\Finder\Comparator\NumberComparator;
  20  use Symfony\Component\Finder\Exception\ExceptionInterface;
  21  use Symfony\Component\Finder\Iterator\CustomFilterIterator;
  22  use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
  23  use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
  24  use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
  25  use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
  26  use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
  27  use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
  28  use Symfony\Component\Finder\Iterator\SortableIterator;
  29  
  30  /**
  31   * Finder allows to build rules to find files and directories.
  32   *
  33   * It is a thin wrapper around several specialized iterator classes.
  34   *
  35   * All rules may be invoked several times.
  36   *
  37   * All methods return the current Finder object to allow easy chaining:
  38   *
  39   *     $finder = Finder::create()->files()->name('*.php')->in(__DIR__);
  40   *
  41   * @author Fabien Potencier <fabien@symfony.com>
  42   */
  43  class Finder implements \IteratorAggregate, \Countable
  44  {
  45      const IGNORE_VCS_FILES = 1;
  46      const IGNORE_DOT_FILES = 2;
  47  
  48      private $mode = 0;
  49      private $names = array();
  50      private $notNames = array();
  51      private $exclude = array();
  52      private $filters = array();
  53      private $depths = array();
  54      private $sizes = array();
  55      private $followLinks = false;
  56      private $sort = false;
  57      private $ignore = 0;
  58      private $dirs = array();
  59      private $dates = array();
  60      private $iterators = array();
  61      private $contains = array();
  62      private $notContains = array();
  63      private $adapters = null;
  64      private $paths = array();
  65      private $notPaths = array();
  66      private $ignoreUnreadableDirs = false;
  67  
  68      private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
  69  
  70      public function __construct()
  71      {
  72          $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
  73      }
  74  
  75      /**
  76       * Creates a new Finder.
  77       *
  78       * @return static
  79       */
  80      public static function create()
  81      {
  82          return new static();
  83      }
  84  
  85      /**
  86       * Registers a finder engine implementation.
  87       *
  88       * @param AdapterInterface $adapter  An adapter instance
  89       * @param int              $priority Highest is selected first
  90       *
  91       * @return $this
  92       *
  93       * @deprecated since 2.8, to be removed in 3.0.
  94       */
  95      public function addAdapter(AdapterInterface $adapter, $priority = 0)
  96      {
  97          @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  98  
  99          $this->initDefaultAdapters();
 100  
 101          $this->adapters[$adapter->getName()] = array(
 102              'adapter' => $adapter,
 103              'priority' => $priority,
 104              'selected' => false,
 105          );
 106  
 107          return $this->sortAdapters();
 108      }
 109  
 110      /**
 111       * Sets the selected adapter to the best one according to the current platform the code is run on.
 112       *
 113       * @return $this
 114       *
 115       * @deprecated since 2.8, to be removed in 3.0.
 116       */
 117      public function useBestAdapter()
 118      {
 119          @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
 120  
 121          $this->initDefaultAdapters();
 122  
 123          $this->resetAdapterSelection();
 124  
 125          return $this->sortAdapters();
 126      }
 127  
 128      /**
 129       * Selects the adapter to use.
 130       *
 131       * @param string $name
 132       *
 133       * @return $this
 134       *
 135       * @throws \InvalidArgumentException
 136       *
 137       * @deprecated since 2.8, to be removed in 3.0.
 138       */
 139      public function setAdapter($name)
 140      {
 141          @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
 142  
 143          $this->initDefaultAdapters();
 144  
 145          if (!isset($this->adapters[$name])) {
 146              throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name));
 147          }
 148  
 149          $this->resetAdapterSelection();
 150          $this->adapters[$name]['selected'] = true;
 151  
 152          return $this->sortAdapters();
 153      }
 154  
 155      /**
 156       * Removes all adapters registered in the finder.
 157       *
 158       * @return $this
 159       *
 160       * @deprecated since 2.8, to be removed in 3.0.
 161       */
 162      public function removeAdapters()
 163      {
 164          @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
 165  
 166          $this->adapters = array();
 167  
 168          return $this;
 169      }
 170  
 171      /**
 172       * Returns registered adapters ordered by priority without extra information.
 173       *
 174       * @return AdapterInterface[]
 175       *
 176       * @deprecated since 2.8, to be removed in 3.0.
 177       */
 178      public function getAdapters()
 179      {
 180          @trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
 181  
 182          $this->initDefaultAdapters();
 183  
 184          return array_values(array_map(function (array $adapter) {
 185              return $adapter['adapter'];
 186          }, $this->adapters));
 187      }
 188  
 189      /**
 190       * Restricts the matching to directories only.
 191       *
 192       * @return $this
 193       */
 194      public function directories()
 195      {
 196          $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
 197  
 198          return $this;
 199      }
 200  
 201      /**
 202       * Restricts the matching to files only.
 203       *
 204       * @return $this
 205       */
 206      public function files()
 207      {
 208          $this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
 209  
 210          return $this;
 211      }
 212  
 213      /**
 214       * Adds tests for the directory depth.
 215       *
 216       * Usage:
 217       *
 218       *     $finder->depth('> 1') // the Finder will start matching at level 1.
 219       *     $finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
 220       *
 221       * @param string|int $level The depth level expression
 222       *
 223       * @return $this
 224       *
 225       * @see DepthRangeFilterIterator
 226       * @see NumberComparator
 227       */
 228      public function depth($level)
 229      {
 230          $this->depths[] = new Comparator\NumberComparator($level);
 231  
 232          return $this;
 233      }
 234  
 235      /**
 236       * Adds tests for file dates (last modified).
 237       *
 238       * The date must be something that strtotime() is able to parse:
 239       *
 240       *     $finder->date('since yesterday');
 241       *     $finder->date('until 2 days ago');
 242       *     $finder->date('> now - 2 hours');
 243       *     $finder->date('>= 2005-10-15');
 244       *
 245       * @param string $date A date range string
 246       *
 247       * @return $this
 248       *
 249       * @see strtotime
 250       * @see DateRangeFilterIterator
 251       * @see DateComparator
 252       */
 253      public function date($date)
 254      {
 255          $this->dates[] = new Comparator\DateComparator($date);
 256  
 257          return $this;
 258      }
 259  
 260      /**
 261       * Adds rules that files must match.
 262       *
 263       * You can use patterns (delimited with / sign), globs or simple strings.
 264       *
 265       *     $finder->name('*.php')
 266       *     $finder->name('/\.php$/') // same as above
 267       *     $finder->name('test.php')
 268       *
 269       * @param string $pattern A pattern (a regexp, a glob, or a string)
 270       *
 271       * @return $this
 272       *
 273       * @see FilenameFilterIterator
 274       */
 275      public function name($pattern)
 276      {
 277          $this->names[] = $pattern;
 278  
 279          return $this;
 280      }
 281  
 282      /**
 283       * Adds rules that files must not match.
 284       *
 285       * @param string $pattern A pattern (a regexp, a glob, or a string)
 286       *
 287       * @return $this
 288       *
 289       * @see FilenameFilterIterator
 290       */
 291      public function notName($pattern)
 292      {
 293          $this->notNames[] = $pattern;
 294  
 295          return $this;
 296      }
 297  
 298      /**
 299       * Adds tests that file contents must match.
 300       *
 301       * Strings or PCRE patterns can be used:
 302       *
 303       *     $finder->contains('Lorem ipsum')
 304       *     $finder->contains('/Lorem ipsum/i')
 305       *
 306       * @param string $pattern A pattern (string or regexp)
 307       *
 308       * @return $this
 309       *
 310       * @see FilecontentFilterIterator
 311       */
 312      public function contains($pattern)
 313      {
 314          $this->contains[] = $pattern;
 315  
 316          return $this;
 317      }
 318  
 319      /**
 320       * Adds tests that file contents must not match.
 321       *
 322       * Strings or PCRE patterns can be used:
 323       *
 324       *     $finder->notContains('Lorem ipsum')
 325       *     $finder->notContains('/Lorem ipsum/i')
 326       *
 327       * @param string $pattern A pattern (string or regexp)
 328       *
 329       * @return $this
 330       *
 331       * @see FilecontentFilterIterator
 332       */
 333      public function notContains($pattern)
 334      {
 335          $this->notContains[] = $pattern;
 336  
 337          return $this;
 338      }
 339  
 340      /**
 341       * Adds rules that filenames must match.
 342       *
 343       * You can use patterns (delimited with / sign) or simple strings.
 344       *
 345       *     $finder->path('some/special/dir')
 346       *     $finder->path('/some\/special\/dir/') // same as above
 347       *
 348       * Use only / as dirname separator.
 349       *
 350       * @param string $pattern A pattern (a regexp or a string)
 351       *
 352       * @return $this
 353       *
 354       * @see FilenameFilterIterator
 355       */
 356      public function path($pattern)
 357      {
 358          $this->paths[] = $pattern;
 359  
 360          return $this;
 361      }
 362  
 363      /**
 364       * Adds rules that filenames must not match.
 365       *
 366       * You can use patterns (delimited with / sign) or simple strings.
 367       *
 368       *     $finder->notPath('some/special/dir')
 369       *     $finder->notPath('/some\/special\/dir/') // same as above
 370       *
 371       * Use only / as dirname separator.
 372       *
 373       * @param string $pattern A pattern (a regexp or a string)
 374       *
 375       * @return $this
 376       *
 377       * @see FilenameFilterIterator
 378       */
 379      public function notPath($pattern)
 380      {
 381          $this->notPaths[] = $pattern;
 382  
 383          return $this;
 384      }
 385  
 386      /**
 387       * Adds tests for file sizes.
 388       *
 389       *     $finder->size('> 10K');
 390       *     $finder->size('<= 1Ki');
 391       *     $finder->size(4);
 392       *
 393       * @param string|int $size A size range string or an integer
 394       *
 395       * @return $this
 396       *
 397       * @see SizeRangeFilterIterator
 398       * @see NumberComparator
 399       */
 400      public function size($size)
 401      {
 402          $this->sizes[] = new Comparator\NumberComparator($size);
 403  
 404          return $this;
 405      }
 406  
 407      /**
 408       * Excludes directories.
 409       *
 410       * Directories passed as argument must be relative to the ones defined with the `in()` method. For example:
 411       *
 412       *     $finder->in(__DIR__)->exclude('ruby');
 413       *
 414       * @param string|array $dirs A directory path or an array of directories
 415       *
 416       * @return $this
 417       *
 418       * @see ExcludeDirectoryFilterIterator
 419       */
 420      public function exclude($dirs)
 421      {
 422          $this->exclude = array_merge($this->exclude, (array) $dirs);
 423  
 424          return $this;
 425      }
 426  
 427      /**
 428       * Excludes "hidden" directories and files (starting with a dot).
 429       *
 430       * This option is enabled by default.
 431       *
 432       * @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
 433       *
 434       * @return $this
 435       *
 436       * @see ExcludeDirectoryFilterIterator
 437       */
 438      public function ignoreDotFiles($ignoreDotFiles)
 439      {
 440          if ($ignoreDotFiles) {
 441              $this->ignore |= static::IGNORE_DOT_FILES;
 442          } else {
 443              $this->ignore &= ~static::IGNORE_DOT_FILES;
 444          }
 445  
 446          return $this;
 447      }
 448  
 449      /**
 450       * Forces the finder to ignore version control directories.
 451       *
 452       * This option is enabled by default.
 453       *
 454       * @param bool $ignoreVCS Whether to exclude VCS files or not
 455       *
 456       * @return $this
 457       *
 458       * @see ExcludeDirectoryFilterIterator
 459       */
 460      public function ignoreVCS($ignoreVCS)
 461      {
 462          if ($ignoreVCS) {
 463              $this->ignore |= static::IGNORE_VCS_FILES;
 464          } else {
 465              $this->ignore &= ~static::IGNORE_VCS_FILES;
 466          }
 467  
 468          return $this;
 469      }
 470  
 471      /**
 472       * Adds VCS patterns.
 473       *
 474       * @see ignoreVCS()
 475       *
 476       * @param string|string[] $pattern VCS patterns to ignore
 477       */
 478      public static function addVCSPattern($pattern)
 479      {
 480          foreach ((array) $pattern as $p) {
 481              self::$vcsPatterns[] = $p;
 482          }
 483  
 484          self::$vcsPatterns = array_unique(self::$vcsPatterns);
 485      }
 486  
 487      /**
 488       * Sorts files and directories by an anonymous function.
 489       *
 490       * The anonymous function receives two \SplFileInfo instances to compare.
 491       *
 492       * This can be slow as all the matching files and directories must be retrieved for comparison.
 493       *
 494       * @return $this
 495       *
 496       * @see SortableIterator
 497       */
 498      public function sort(\Closure $closure)
 499      {
 500          $this->sort = $closure;
 501  
 502          return $this;
 503      }
 504  
 505      /**
 506       * Sorts files and directories by name.
 507       *
 508       * This can be slow as all the matching files and directories must be retrieved for comparison.
 509       *
 510       * @return $this
 511       *
 512       * @see SortableIterator
 513       */
 514      public function sortByName()
 515      {
 516          $this->sort = Iterator\SortableIterator::SORT_BY_NAME;
 517  
 518          return $this;
 519      }
 520  
 521      /**
 522       * Sorts files and directories by type (directories before files), then by name.
 523       *
 524       * This can be slow as all the matching files and directories must be retrieved for comparison.
 525       *
 526       * @return $this
 527       *
 528       * @see SortableIterator
 529       */
 530      public function sortByType()
 531      {
 532          $this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
 533  
 534          return $this;
 535      }
 536  
 537      /**
 538       * Sorts files and directories by the last accessed time.
 539       *
 540       * This is the time that the file was last accessed, read or written to.
 541       *
 542       * This can be slow as all the matching files and directories must be retrieved for comparison.
 543       *
 544       * @return $this
 545       *
 546       * @see SortableIterator
 547       */
 548      public function sortByAccessedTime()
 549      {
 550          $this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
 551  
 552          return $this;
 553      }
 554  
 555      /**
 556       * Sorts files and directories by the last inode changed time.
 557       *
 558       * This is the time that the inode information was last modified (permissions, owner, group or other metadata).
 559       *
 560       * On Windows, since inode is not available, changed time is actually the file creation time.
 561       *
 562       * This can be slow as all the matching files and directories must be retrieved for comparison.
 563       *
 564       * @return $this
 565       *
 566       * @see SortableIterator
 567       */
 568      public function sortByChangedTime()
 569      {
 570          $this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
 571  
 572          return $this;
 573      }
 574  
 575      /**
 576       * Sorts files and directories by the last modified time.
 577       *
 578       * This is the last time the actual contents of the file were last modified.
 579       *
 580       * This can be slow as all the matching files and directories must be retrieved for comparison.
 581       *
 582       * @return $this
 583       *
 584       * @see SortableIterator
 585       */
 586      public function sortByModifiedTime()
 587      {
 588          $this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
 589  
 590          return $this;
 591      }
 592  
 593      /**
 594       * Filters the iterator with an anonymous function.
 595       *
 596       * The anonymous function receives a \SplFileInfo and must return false
 597       * to remove files.
 598       *
 599       * @return $this
 600       *
 601       * @see CustomFilterIterator
 602       */
 603      public function filter(\Closure $closure)
 604      {
 605          $this->filters[] = $closure;
 606  
 607          return $this;
 608      }
 609  
 610      /**
 611       * Forces the following of symlinks.
 612       *
 613       * @return $this
 614       */
 615      public function followLinks()
 616      {
 617          $this->followLinks = true;
 618  
 619          return $this;
 620      }
 621  
 622      /**
 623       * Tells finder to ignore unreadable directories.
 624       *
 625       * By default, scanning unreadable directories content throws an AccessDeniedException.
 626       *
 627       * @param bool $ignore
 628       *
 629       * @return $this
 630       */
 631      public function ignoreUnreadableDirs($ignore = true)
 632      {
 633          $this->ignoreUnreadableDirs = (bool) $ignore;
 634  
 635          return $this;
 636      }
 637  
 638      /**
 639       * Searches files and directories which match defined rules.
 640       *
 641       * @param string|array $dirs A directory path or an array of directories
 642       *
 643       * @return $this
 644       *
 645       * @throws \InvalidArgumentException if one of the directories does not exist
 646       */
 647      public function in($dirs)
 648      {
 649          $resolvedDirs = array();
 650  
 651          foreach ((array) $dirs as $dir) {
 652              if (is_dir($dir)) {
 653                  $resolvedDirs[] = $this->normalizeDir($dir);
 654              } elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
 655                  $resolvedDirs = array_merge($resolvedDirs, array_map(array($this, 'normalizeDir'), $glob));
 656              } else {
 657                  throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
 658              }
 659          }
 660  
 661          $this->dirs = array_merge($this->dirs, $resolvedDirs);
 662  
 663          return $this;
 664      }
 665  
 666      /**
 667       * Returns an Iterator for the current Finder configuration.
 668       *
 669       * This method implements the IteratorAggregate interface.
 670       *
 671       * @return \Iterator|SplFileInfo[] An iterator
 672       *
 673       * @throws \LogicException if the in() method has not been called
 674       */
 675      public function getIterator()
 676      {
 677          if (0 === \count($this->dirs) && 0 === \count($this->iterators)) {
 678              throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
 679          }
 680  
 681          if (1 === \count($this->dirs) && 0 === \count($this->iterators)) {
 682              return $this->searchInDirectory($this->dirs[0]);
 683          }
 684  
 685          $iterator = new \AppendIterator();
 686          foreach ($this->dirs as $dir) {
 687              $iterator->append($this->searchInDirectory($dir));
 688          }
 689  
 690          foreach ($this->iterators as $it) {
 691              $iterator->append($it);
 692          }
 693  
 694          return $iterator;
 695      }
 696  
 697      /**
 698       * Appends an existing set of files/directories to the finder.
 699       *
 700       * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
 701       *
 702       * @param iterable $iterator
 703       *
 704       * @return $this
 705       *
 706       * @throws \InvalidArgumentException when the given argument is not iterable
 707       */
 708      public function append($iterator)
 709      {
 710          if ($iterator instanceof \IteratorAggregate) {
 711              $this->iterators[] = $iterator->getIterator();
 712          } elseif ($iterator instanceof \Iterator) {
 713              $this->iterators[] = $iterator;
 714          } elseif ($iterator instanceof \Traversable || \is_array($iterator)) {
 715              $it = new \ArrayIterator();
 716              foreach ($iterator as $file) {
 717                  $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
 718              }
 719              $this->iterators[] = $it;
 720          } else {
 721              throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
 722          }
 723  
 724          return $this;
 725      }
 726  
 727      /**
 728       * Counts all the results collected by the iterators.
 729       *
 730       * @return int
 731       */
 732      public function count()
 733      {
 734          return iterator_count($this->getIterator());
 735      }
 736  
 737      /**
 738       * @return $this
 739       */
 740      private function sortAdapters()
 741      {
 742          uasort($this->adapters, function (array $a, array $b) {
 743              if ($a['selected'] || $b['selected']) {
 744                  return $a['selected'] ? -1 : 1;
 745              }
 746  
 747              return $a['priority'] > $b['priority'] ? -1 : 1;
 748          });
 749  
 750          return $this;
 751      }
 752  
 753      /**
 754       * @param string $dir
 755       *
 756       * @return \Iterator
 757       */
 758      private function searchInDirectory($dir)
 759      {
 760          if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
 761              $this->exclude = array_merge($this->exclude, self::$vcsPatterns);
 762          }
 763  
 764          if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
 765              $this->notPaths[] = '#(^|/)\..+(/|$)#';
 766          }
 767  
 768          if ($this->adapters) {
 769              foreach ($this->adapters as $adapter) {
 770                  if ($adapter['adapter']->isSupported()) {
 771                      try {
 772                          return $this
 773                              ->buildAdapter($adapter['adapter'])
 774                              ->searchInDirectory($dir);
 775                      } catch (ExceptionInterface $e) {
 776                      }
 777                  }
 778              }
 779          }
 780  
 781          $minDepth = 0;
 782          $maxDepth = PHP_INT_MAX;
 783  
 784          foreach ($this->depths as $comparator) {
 785              switch ($comparator->getOperator()) {
 786                  case '>':
 787                      $minDepth = $comparator->getTarget() + 1;
 788                      break;
 789                  case '>=':
 790                      $minDepth = $comparator->getTarget();
 791                      break;
 792                  case '<':
 793                      $maxDepth = $comparator->getTarget() - 1;
 794                      break;
 795                  case '<=':
 796                      $maxDepth = $comparator->getTarget();
 797                      break;
 798                  default:
 799                      $minDepth = $maxDepth = $comparator->getTarget();
 800              }
 801          }
 802  
 803          $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
 804  
 805          if ($this->followLinks) {
 806              $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
 807          }
 808  
 809          $iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
 810  
 811          if ($this->exclude) {
 812              $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
 813          }
 814  
 815          $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
 816  
 817          if ($minDepth > 0 || $maxDepth < PHP_INT_MAX) {
 818              $iterator = new Iterator\DepthRangeFilterIterator($iterator, $minDepth, $maxDepth);
 819          }
 820  
 821          if ($this->mode) {
 822              $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
 823          }
 824  
 825          if ($this->names || $this->notNames) {
 826              $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
 827          }
 828  
 829          if ($this->contains || $this->notContains) {
 830              $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
 831          }
 832  
 833          if ($this->sizes) {
 834              $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
 835          }
 836  
 837          if ($this->dates) {
 838              $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
 839          }
 840  
 841          if ($this->filters) {
 842              $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
 843          }
 844  
 845          if ($this->paths || $this->notPaths) {
 846              $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
 847          }
 848  
 849          if ($this->sort) {
 850              $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
 851              $iterator = $iteratorAggregate->getIterator();
 852          }
 853  
 854          return $iterator;
 855      }
 856  
 857      /**
 858       * @return AdapterInterface
 859       */
 860      private function buildAdapter(AdapterInterface $adapter)
 861      {
 862          return $adapter
 863              ->setFollowLinks($this->followLinks)
 864              ->setDepths($this->depths)
 865              ->setMode($this->mode)
 866              ->setExclude($this->exclude)
 867              ->setNames($this->names)
 868              ->setNotNames($this->notNames)
 869              ->setContains($this->contains)
 870              ->setNotContains($this->notContains)
 871              ->setSizes($this->sizes)
 872              ->setDates($this->dates)
 873              ->setFilters($this->filters)
 874              ->setSort($this->sort)
 875              ->setPath($this->paths)
 876              ->setNotPath($this->notPaths)
 877              ->ignoreUnreadableDirs($this->ignoreUnreadableDirs);
 878      }
 879  
 880      /**
 881       * Unselects all adapters.
 882       */
 883      private function resetAdapterSelection()
 884      {
 885          $this->adapters = array_map(function (array $properties) {
 886              $properties['selected'] = false;
 887  
 888              return $properties;
 889          }, $this->adapters);
 890      }
 891  
 892      private function initDefaultAdapters()
 893      {
 894          if (null === $this->adapters) {
 895              $this->adapters = array();
 896              $this
 897                  ->addAdapter(new GnuFindAdapter())
 898                  ->addAdapter(new BsdFindAdapter())
 899                  ->addAdapter(new PhpAdapter(), -50)
 900                  ->setAdapter('php')
 901              ;
 902          }
 903      }
 904  
 905      /**
 906       * Normalizes given directory names by removing trailing slashes.
 907       *
 908       * @param string $dir
 909       *
 910       * @return string
 911       */
 912      private function normalizeDir($dir)
 913      {
 914          return rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
 915      }
 916  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1