本文整理匯總了PHP中Symfony\Component\Finder\Finder::sort方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::sort方法的具體用法?PHP Finder::sort怎麽用?PHP Finder::sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::sort方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sortBy
/**
* @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: findAssets
/**
* 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: getFixtureFiles
/**
* 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: sort
/**
* @return Finder
*/
public function sort(Closure $closure)
{
return parent::sort($closure);
}