sort() публичный Метод

The anonymous function receives two \SplFileInfo instances to compare. This can be slow as all the matching files and directories must be retrieved for comparison.
См. также: SortableIterator
public sort ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$closure Closure An anonymous function
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance
Пример #1
2
 /**
  * @param string|callable $by
  * @return $this
  */
 public function sortBy($by = self::SORT_BY_NAME)
 {
     if (is_callable($by)) {
         $this->finder->sort($by);
         return $this;
     }
     switch (strtolower($by)) {
         case self::SORT_BY_NAME:
         case 'name':
             $this->finder->sortByName();
             break;
         case self::SORT_BY_CHANGED_TIME:
         case 'ctime':
             $this->finder->sortByChangedTime();
             break;
         case self::SORT_BY_ACCESSED_TIME:
         case 'atime':
             $this->finder->sortByAccessedTime();
             break;
         case self::SORT_BY_TYPE:
         case 'type':
             $this->finder->sortByType();
             break;
         case self::SORT_BY_MODIFIED_TIME:
         case 'mtime':
             $this->finder->sortByModifiedTime();
             break;
         default:
             throw new \InvalidArgumentException($by . ' is not a supported argument for sorting.');
     }
     return $this;
 }
Пример #2
2
 /**
  * Finds directory assets
  *
  * @param string $dir
  * @param string $ext
  * @param string $env
  * @param array  $assets
  *
  * @return array
  */
 protected function findAssets($dir, $ext, $env, &$assets)
 {
     $rootPath = str_replace('\\', '/', $this->factory->getSystemPath('assets_root') . '/');
     $directories = new Finder();
     $directories->directories()->exclude('*less')->depth('0')->ignoreDotFiles(true)->in($dir);
     $modifiedLast = array();
     if (count($directories)) {
         foreach ($directories as $directory) {
             $group = $directory->getBasename();
             // Only auto load directories app or libraries
             if (!in_array($group, array('app', 'libraries'))) {
                 continue;
             }
             $files = new Finder();
             $thisDirectory = str_replace('\\', '/', $directory->getRealPath());
             $files->files()->depth('0')->name('*.' . $ext)->in($thisDirectory);
             $sort = function (\SplFileInfo $a, \SplFileInfo $b) {
                 return strnatcmp($a->getRealpath(), $b->getRealpath());
             };
             $files->sort($sort);
             foreach ($files as $file) {
                 $fullPath = $file->getPathname();
                 $relPath = str_replace($rootPath, '', $file->getPathname());
                 if (strpos($relPath, '/') === 0) {
                     $relPath = substr($relPath, 1);
                 }
                 $details = array('fullPath' => $fullPath, 'relPath' => $relPath);
                 if ($env == 'prod') {
                     $lastModified = filemtime($fullPath);
                     if (!isset($modifiedLast[$group]) || $lastModified > $modifiedLast[$group]) {
                         $modifiedLast[$group] = $lastModified;
                     }
                     $assets[$ext][$group][$relPath] = $details;
                 } else {
                     $assets[$ext][$relPath] = $details;
                 }
             }
             unset($files);
         }
     }
     unset($directories);
     $files = new Finder();
     $files->files()->depth('0')->ignoreDotFiles(true)->name('*.' . $ext)->in($dir);
     $sort = function (\SplFileInfo $a, \SplFileInfo $b) {
         return strnatcmp($a->getRealpath(), $b->getRealpath());
     };
     $files->sort($sort);
     foreach ($files as $file) {
         $fullPath = str_replace('\\', '/', $file->getPathname());
         $relPath = str_replace($rootPath, '', $fullPath);
         $details = array('fullPath' => $fullPath, 'relPath' => $relPath);
         if ($env == 'prod') {
             $lastModified = filemtime($fullPath);
             if (!isset($modifiedLast['app']) || $lastModified > $modifiedLast['app']) {
                 $modifiedLast['app'] = $lastModified;
             }
             $assets[$ext]['app'][$relPath] = $details;
         } else {
             $assets[$ext][$relPath] = $details;
         }
     }
     unset($files);
     return $modifiedLast;
 }
Пример #3
-1
 /**
  * Returns the fixtures files to load.
  *
  * @param string $type The extension of the files.
  * @param string $in   The directory in which we search the files. If null,
  *                     we'll use the absoluteFixturesPath property.
  *
  * @return \Iterator An iterator through the files.
  */
 protected function getFixtureFiles($type = 'sql', $in = null)
 {
     $finder = new Finder();
     $finder->sort(function ($a, $b) {
         return strcmp($a->getPathname(), $b->getPathname());
     })->name('*.' . $type);
     $files = $finder->in(null !== $in ? $in : $this->absoluteFixturesPath);
     if (null === $this->bundle) {
         return $files;
     }
     $finalFixtureFiles = array();
     foreach ($files as $file) {
         $fixtureFilePath = str_replace($this->getFixturesPath($this->bundle) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
         $logicalName = sprintf('@%s/Resources/fixtures/%s', $this->bundle->getName(), $fixtureFilePath);
         $finalFixtureFiles[] = new \SplFileInfo($this->getFileLocator()->locate($logicalName));
     }
     return new \ArrayIterator($finalFixtureFiles);
 }
Пример #4
-2
 /**
  * @return Finder
  */
 public function sort(Closure $closure)
 {
     return parent::sort($closure);
 }