本文整理汇总了PHP中Symfony\Component\Finder\Finder::sortByName方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::sortByName方法的具体用法?PHP Finder::sortByName怎么用?PHP Finder::sortByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::sortByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: dirAction
/**
* @Route("/inbox", defaults={"_format"="json"})
*/
public function dirAction(Request $request)
{
$dir = $request->query->get("dir", "");
$type = $request->query->get("type", "file");
$baseDir = realpath($this->container->getParameter('pumukit2.inbox'));
/*
if(0 !== strpos($dir, $baseDir)) {
throw $this->createAccessDeniedException();
}
*/
$finder = new Finder();
$res = array();
if ("file" == $type) {
$finder->depth('< 1')->followLinks()->in($dir);
$finder->sortByName();
foreach ($finder as $f) {
$res[] = array('path' => $f->getRealpath(), 'relativepath' => $f->getRelativePathname(), 'is_file' => $f->isFile(), 'hash' => hash('md5', $f->getRealpath()), 'content' => false);
}
} else {
$finder->depth('< 1')->directories()->followLinks()->in($dir);
$finder->sortByName();
foreach ($finder as $f) {
if (0 !== count(glob("{$f}/*"))) {
$contentFinder = new Finder();
$contentFinder->files()->in($f->getRealpath());
$res[] = array('path' => $f->getRealpath(), 'relativepath' => $f->getRelativePathname(), 'is_file' => $f->isFile(), 'hash' => hash('md5', $f->getRealpath()), 'content' => $contentFinder->count());
}
}
}
return new JsonResponse($res);
}
示例3: gather
/**
* Gather data from annotations.js and *.md files found in source/_annotations
*
* @return {Array} populates Annotations::$store
*/
public static function gather()
{
// set-up default var
$annotationsDir = Config::getOption("annotationsDir");
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// dispatch that the data gather has started
$dispatcherInstance->dispatch("annotations.gatherStart");
// set-up the comments store
self::$store["comments"] = array();
// create the annotations dir if it doesn't exist
if (!is_dir($annotationsDir)) {
mkdir($annotationsDir);
}
// find the markdown-based annotations
$finder = new Finder();
$finder->files()->name("*.md")->in($annotationsDir);
$finder->sortByName();
foreach ($finder as $name => $file) {
$data = array();
$data[0] = array();
$text = file_get_contents($file->getPathname());
$matches = strpos($text, PHP_EOL . "~*~" . PHP_EOL) !== false ? explode(PHP_EOL . "~*~" . PHP_EOL, $text) : array($text);
foreach ($matches as $match) {
list($yaml, $markdown) = Documentation::parse($match);
if (isset($yaml["el"]) || isset($yaml["selector"])) {
$data[0]["el"] = isset($yaml["el"]) ? $yaml["el"] : $yaml["selector"];
} else {
$data[0]["el"] = "#someimpossibleselector";
}
$data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : "";
$data[0]["comment"] = $markdown;
self::$store["comments"] = array_merge(self::$store["comments"], $data);
}
}
// read in the old style annotations.js, modify the data and generate JSON array to merge
$data = array();
$oldStyleAnnotationsPath = $annotationsDir . DIRECTORY_SEPARATOR . "annotations.js";
if (file_exists($oldStyleAnnotationsPath)) {
$text = trim(file_get_contents($oldStyleAnnotationsPath));
$text = str_replace("var comments = ", "", $text);
if ($text[strlen($text) - 1] == ";") {
$text = rtrim($text, ";");
}
$data = json_decode($text, true);
if ($jsonErrorMessage = JSON::hasError()) {
JSON::lastErrorMsg(Console::getHumanReadablePath($oldStyleAnnotationsPath), $jsonErrorMessage, $data);
}
}
// merge in any data from the old file if the json decode was successful
if (is_array($data) && isset($data["comments"])) {
self::$store["comments"] = array_merge(self::$store["comments"], $data["comments"]);
}
$dispatcherInstance->dispatch("annotations.gatherEnd");
}
示例4: createFromFiles
/**
* Create ProcessSet from given files, optionally filtering by given $groups and $excludeGroups
*
* @param Finder $files
* @param array $groups Groups to be run
* @param array $excludeGroups Groups to be excluded
* @param string $filter filter test cases by name
* @return ProcessSet
*/
public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null, $filter = null)
{
$files->sortByName();
$processSet = $this->getProcessSet();
if ($groups || $excludeGroups || $filter) {
$this->output->writeln('Filtering testcases:');
}
if ($groups) {
$this->output->writeln(sprintf(' - by group(s): %s', implode(', ', $groups)));
}
if ($excludeGroups) {
$this->output->writeln(sprintf(' - excluding group(s): %s', implode(', ', $excludeGroups)));
}
if ($filter) {
$this->output->writeln(sprintf(' - by testcase/test name: %s', $filter));
}
$testCasesNum = 0;
foreach ($files as $file) {
$fileName = $file->getRealpath();
// Parse classes from the testcase file
$classes = AnnotationsParser::parsePhp(\file_get_contents($fileName));
// Get annotations for the first class in testcase (one file = one class)
$annotations = AnnotationsParser::getAll(new \ReflectionClass(key($classes)));
// Filter out test-cases having any of excluded groups
if ($excludeGroups && array_key_exists('group', $annotations) && count($excludingGroups = array_intersect($excludeGroups, $annotations['group']))) {
if ($this->output->isDebug()) {
$this->output->writeln(sprintf('Excluding testcase file %s with group %s', $fileName, implode(', ', $excludingGroups)));
}
continue;
}
// Filter out test-cases without any matching group
if ($groups) {
if (!array_key_exists('group', $annotations) || !count($matchingGroups = array_intersect($groups, $annotations['group']))) {
continue;
}
if ($this->output->isDebug()) {
$this->output->writeln(sprintf('Found testcase file #%d in group %s: %s', ++$testCasesNum, implode(', ', $matchingGroups), $fileName));
}
} else {
if ($this->output->isDebug()) {
$this->output->writeln(sprintf('Found testcase file #%d: %s', ++$testCasesNum, $fileName));
}
}
$phpunitArgs = ['--log-junit=logs/' . Strings::webalize(key($classes), null, $lower = false) . '.xml', '--configuration=' . realpath(__DIR__ . '/../phpunit.xml')];
if ($filter) {
$phpunitArgs[] = '--filter=' . $filter;
}
// If ANSI output is enabled, turn on colors in PHPUnit
if ($this->output->isDecorated()) {
$phpunitArgs[] = '--colors=always';
}
$processSet->add($this->buildProcess($fileName, $phpunitArgs), key($classes), $delayAfter = !empty($annotations['delayAfter']) ? current($annotations['delayAfter']) : '', $delayMinutes = !empty($annotations['delayMinutes']) ? current($annotations['delayMinutes']) : null);
}
return $processSet;
}
示例5: getListaIframes
protected function getListaIframes()
{
$iframeDir = $this->container->getParameter('iframe_dir');
$finder = new Finder();
$finder->files()->in($iframeDir);
$finder->sortByName();
$iframes = array();
foreach ($finder as $file) {
$iframes[] = $file->getRelativePathname();
}
return $iframes;
}
示例6: gather
/**
* Gather data from annotations.js and *.md files found in source/_annotations
*
* @return {Array} populates Annotations::$store
*/
public static function gather()
{
// set-up default var
$sourceDir = Config::getOption("sourceDir");
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// dispatch that the data gather has started
$dispatcherInstance->dispatch("annotations.gatherStart");
// set-up the comments store
self::$store["comments"] = array();
// iterate over all of the files in the annotations dir
if (!is_dir($sourceDir . "/_annotations")) {
Console::writeWarning("<path>_annotations/</path><warning> doesn't exist so you won't have annotations...");
mkdir($sourceDir . "/_annotations");
}
// find the markdown-based annotations
$finder = new Finder();
$finder->files()->name("*.md")->in($sourceDir . "/_annotations");
$finder->sortByName();
foreach ($finder as $name => $file) {
$data = array();
$data[0] = array();
$text = file_get_contents($file->getPathname());
$matches = strpos($text, PHP_EOL . "~*~" . PHP_EOL) !== false ? explode(PHP_EOL . "~*~" . PHP_EOL, $text) : array($text);
foreach ($matches as $match) {
list($yaml, $markdown) = Documentation::parse($match);
if (isset($yaml["el"]) || isset($yaml["selector"])) {
$data[0]["el"] = isset($yaml["el"]) ? $yaml["el"] : $yaml["selector"];
} else {
$data[0]["el"] = "#someimpossibleselector";
}
$data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : "";
$data[0]["comment"] = $markdown;
self::$store["comments"] = array_merge(self::$store["comments"], $data);
}
}
// read in the old style annotations.js, modify the data and generate JSON array to merge
if (file_exists($sourceDir . "/_annotations/annotations.js")) {
$text = file_get_contents($sourceDir . "/_annotations/annotations.js");
$text = str_replace("var comments = ", "", $text);
$text = rtrim($text, ";");
$data = json_decode($text, true);
if ($jsonErrorMessage = JSON::hasError()) {
JSON::lastErrorMsg("_annotations/annotations.js", $jsonErrorMessage, $data);
}
}
// merge in any data from the old file
self::$store["comments"] = array_merge(self::$store["comments"], $data["comments"]);
$dispatcherInstance->dispatch("annotations.gatherEnd");
}
示例7: categoryAction
/**
* @Route("/catalog/{slug}/{tag}/", name="spb_shop_catalog_category")
*/
public function categoryAction($slug)
{
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('SpbShopBundle:Category');
$entity = $repo->findOneBySlug($slug);
$parents = $repo->getPath($entity);
if ($repo->childCount($entity) > 0) {
$children = $repo->children($entity, true);
return $this->render('SpbShopBundle:Catalog:category.html.twig', array('entity' => $entity, 'parents' => $parents, 'items' => $children));
} else {
$finder = new Finder();
$finder->files()->in($this->container->getParameter('catalog_img') . $entity->getTag());
$finder->sortByName();
return $this->render('SpbShopBundle:Catalog:product.html.twig', array('entity' => $entity, 'parents' => $parents, 'finder' => $finder));
}
}
示例8: findPatchsFiles
/**
* Find patch files in good order
*
* @param string $dir
* @return array
*/
protected function findPatchsFiles($dir)
{
if (is_dir($dir) === false) {
return array();
}
$finderFiles = new Finder();
$finderFiles->files();
$finderFiles->in($dir);
$finderFiles->name('Patch*.php');
$finderFiles->sortByName();
// we want first patch in first, but sortByName sort first patch in last
$return = array();
foreach ($finderFiles as $file) {
$return = array_merge($return, array($file));
}
return $return;
}
示例9: listAllDumps
/**
* @return void
*/
protected function listAllDumps()
{
$finder = new Finder();
$finder->files()->in($this->getDumpsPath());
if ($finder->count() === 0) {
return $this->line($this->colors->getColoredString("\n" . 'You haven\'t saved any dumps.' . "\n", 'brown'));
}
$finder->sortByName();
$count = count($finder);
$i = 0;
foreach ($finder as $dump) {
$i++;
$fileName = $dump->getFilename();
if ($i === $count - 1) {
$fileName .= "\n";
}
$this->line($this->colors->getColoredString($fileName, 'brown'));
}
}
示例10: finder
/**
* Build a Symfony Finder object that scans the given $directory.
*
* @param string|array|Finder $directory The directory(s) or filename(s)
* @param null|string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths)
* @throws InvalidArgumentException
*/
public static function finder($directory, $exclude = null)
{
if ($directory instanceof Finder) {
return $directory;
} else {
$finder = new Finder();
$finder->sortByName();
}
$finder->files();
if (is_string($directory)) {
if (is_file($directory)) {
// Scan a single file?
$finder->append([$directory]);
} else {
// Scan a directory
$finder->in($directory);
}
} elseif (is_array($directory)) {
foreach ($directory as $path) {
if (is_file($path)) {
// Scan a file?
$finder->append([$path]);
} else {
$finder->in($path);
}
}
} else {
throw new InvalidArgumentException('Unexpected $directory value:' . gettype($directory));
}
if ($exclude !== null) {
if (is_string($exclude)) {
$finder->notPath(Util::getRelativePath($exclude, $directory));
} elseif (is_array($exclude)) {
foreach ($exclude as $path) {
$finder->notPath(Util::getRelativePath($path, $directory));
}
} else {
throw new InvalidArgumentException('Unexpected $exclude value:' . gettype($exclude));
}
}
return $finder;
}
示例11: listAllDumps
protected function listAllDumps()
{
$finder = new Finder();
$finder->files()->in($this->getDumpsPath());
if ($finder->count() > 0) {
$this->line($this->colors->getColoredString("\n" . 'Please select one of the following dumps:' . "\n", 'white'));
$finder->sortByName();
$count = count($finder);
$i = 0;
foreach ($finder as $dump) {
$i++;
if ($i != $count) {
$this->line($this->colors->getColoredString($dump->getFilename(), 'brown'));
} else {
$this->line($this->colors->getColoredString($dump->getFilename() . "\n", 'brown'));
}
}
} else {
$this->line($this->colors->getColoredString("\n" . 'You haven\'t saved any dumps.' . "\n", 'brown'));
}
}
示例12: getLastSchemaDefinition
/**
* Get the most recent schema
*
* @param type $configuration
*/
protected function getLastSchemaDefinition($configuration)
{
$migrationDirectoryHelper = new \Doctrine\DBAL\Migrations\Tools\Console\Helper\MigrationDirectoryHelper($configuration);
$dir = $migrationDirectoryHelper->getMigrationDirectory() . '/SchemaVersion';
//create the directory if required
$fs = new Filesystem();
$fs->mkdir($dir);
//get the files containing the schema
$finder = new Finder();
$finder->in($dir);
$finder->sortByName();
$filesIterator = $finder->getIterator();
$filesArray = iterator_to_array($filesIterator);
if (count($filesArray) === 0) {
$lastSchema = new \Doctrine\DBAL\Schema\Schema();
} else {
//get last entry
$lastSchemaFile = end($filesArray);
$content = $lastSchemaFile->getContents();
$lastSchema = unserialize($content);
}
return $lastSchema;
}
示例13: loadTests
/**
* Load functions for the Twig PatternEngine
* @param {Instance} an instance of the twig engine
*
* @return {Instance} an instance of the twig engine
*/
public static function loadTests($instance)
{
// load defaults
$testDir = Config::getOption("sourceDir") . DIRECTORY_SEPARATOR . "_twig-components/tests";
$testExt = Config::getOption("twigTestExt");
$testExt = $testExt ? $testExt : "test.php";
if (is_dir($testDir)) {
// loop through the test dir...
$finder = new Finder();
$finder->files()->name("*\\." . $testExt)->in($testDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include $file->getPathname();
// $test should be defined in the included file
if (isset($test)) {
$instance->addTest($test);
unset($test);
}
}
}
}
return $instance;
}
示例14: findFiles
/**
* Find all files to merge.
*
* @param string $directory
* @param array $names
* @param array $ignoreNames
*
* @return Finder
*/
private function findFiles($directory, array $names, array $ignoreNames)
{
$finder = new Finder();
$finder->files()->in($directory);
foreach ($names as $name) {
$finder->name($name);
}
foreach ($ignoreNames as $name) {
$finder->notName($name);
}
$finder->sortByName();
return $finder;
}
示例15: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return bool|int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
if ($input->isInteractive()) {
$this->writeCommandHeader($output, 'Looking for videos...');
$confPath = $this->getConfigurationHelper()->getConfigurationFilePath();
$sysPath = $this->getConfigurationHelper()->getSysPathFromConfigurationFile($confPath);
$dir = $input->getArgument('source');
//1 if the option was set
if (substr($dir, 0, 1) != '/') {
$dir = $sysPath . $dir;
}
if (!is_dir($dir)) {
$output->writeln($dir . ' was not confirmed as a directory (if not starting with /, it is considered as relative to Chamilo\'s root folder)');
return;
}
$this->ext = $input->getOption('ext');
if (empty($this->ext)) {
$this->ext = 'webm';
}
$this->origExt = $input->getOption('orig-ext');
if (empty($this->origExt)) {
$this->origExt = 'orig';
}
$fps = $input->getOption('fps');
if (empty($fps)) {
$fps = '24';
}
$bitRate = $input->getOption('bitrate');
if (empty($bitRate)) {
$bitRate = '512';
}
$vcodec = 'copy';
if ($this->ext == 'webm') {
$vcodec = 'libvpx';
}
// Find the files we want to treat, using Finder selectors
$finder = new Finder();
$filter = function (\SplFileInfo $file, $ext, $orig) {
$combinedExt = '.' . $orig . '.' . $ext;
$combinedExtLength = strlen($combinedExt);
$extLength = strlen('.' . $ext);
if (substr($file->getRealPath(), -$combinedExtLength) == $combinedExt) {
return false;
}
if (is_file(substr($file->getRealPath(), 0, -$extLength) . $combinedExt)) {
$this->excluded[] = $file;
return false;
}
};
$finder->sortByName()->files()->in($dir)->name('*.' . $this->ext)->filter($filter, $this->ext, $this->origExt);
// Print the list of matching files we found
if (count($finder) > 0) {
$output->writeln('Videos found for conversion: ');
foreach ($finder as $file) {
$output->writeln($file->getRealpath());
}
} else {
if (count($this->excluded) > 0) {
$output->writeln('The system has detected several videos already converted: ');
foreach ($this->excluded as $file) {
$output->writeln('- ' . $file->getRealPath());
}
}
$output->writeln('No video left to convert');
return;
}
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>All listed videos will be altered and a copy of the original will be taken with a .orig.webm extension. Are you sure you want to proceed? (y/N)</question>', false)) {
return;
}
$fs = new Filesystem();
$time = time();
$counter = 0;
$sizeNew = $sizeOrig = 0;
foreach ($finder as $file) {
$sizeOrig += $file->getSize();
$origName = $file->getRealPath();
$newName = substr($file->getRealPath(), 0, -4) . 'orig.webm';
$fs->rename($origName, $newName);
$out = array();
$newNameCommand = preg_replace('/\\s/', '\\ ', $newName);
$newNameCommand = preg_replace('/\\(/', '\\(', $newNameCommand);
$newNameCommand = preg_replace('/\\)/', '\\)', $newNameCommand);
$origNameCommand = preg_replace('/\\s/', '\\ ', $origName);
$origNameCommand = preg_replace('/\\(/', '\\(', $origNameCommand);
$origNameCommand = preg_replace('/\\)/', '\\)', $origNameCommand);
$output->writeln('ffmpeg -i ' . $newNameCommand . ' -b ' . $bitRate . 'k -f ' . $this->ext . ' -vcodec ' . $vcodec . ' -acodec copy -r ' . $fps . ' ' . $origNameCommand);
$exec = @system('ffmpeg -i ' . $newNameCommand . ' -b ' . $bitRate . 'k -f ' . $this->ext . ' -vcodec ' . $vcodec . ' -acodec copy -r ' . $fps . ' ' . $origNameCommand, $out);
$sizeNew += filesize($origName);
$counter++;
}
}
$output->writeln('');
$output->writeln('Done converting all videos from ' . $dir);
//.........这里部分代码省略.........