本文整理汇总了PHP中Symfony\Component\Finder\Finder::files方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::files方法的具体用法?PHP Finder::files怎么用?PHP Finder::files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::files方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
// Delete local files
$finder = new Finder();
$fs = new Filesystem();
$fs->remove($finder->files()->in($this->tmpDir . "/download"));
$fs->remove($finder->files()->in($this->tmpDir));
$fs->remove($this->tmpDir . "/download");
$fs->remove($this->tmpDir);
// Delete file uploads
$options = new ListFilesOptions();
$options->setTags(["docker-bundle-test"]);
$files = $this->client->listFiles($options);
foreach ($files as $file) {
$this->client->deleteFile($file["id"]);
}
if ($this->client->bucketExists("in.c-docker-test")) {
// Delete tables
foreach ($this->client->listTables("in.c-docker-test") as $table) {
$this->client->dropTable($table["id"]);
}
// Delete bucket
$this->client->dropBucket("in.c-docker-test");
}
if ($this->client->bucketExists("in.c-docker-test-redshift")) {
// Delete tables
foreach ($this->client->listTables("in.c-docker-test-redshift") as $table) {
$this->client->dropTable($table["id"]);
}
// Delete bucket
$this->client->dropBucket("in.c-docker-test-redshift");
}
}
示例2: process
/**
* Process a build set
* @param object $set The build configuration set
* @return array Returns the complete process set
* @since 1.1.0
*/
public function process()
{
$result = array();
if (property_exists($this->set, 'processor')) {
$this->processor += $this->pushProcessor($this->set->processor);
$result[] = new Stack($this->processor);
}
foreach ($this->set->build as $entry) {
if (is_object($entry)) {
$subManager = new BuildManager($entry, $this->processor);
$result = array_merge($result, $subManager->process());
$result[] = new Stack($this->processor);
} else {
$find = new Finder();
if (is_dir($entry)) {
$find->files()->in($entry);
} elseif (is_file($entry)) {
$find->files()->depth('== 0')->name(basename($entry))->in(dirname($entry));
} else {
$find = array();
}
foreach ($find as $file) {
$result[] = $file;
}
}
}
return $result;
}
示例3: searchAction
/**
* @Route("/search")
*/
public function searchAction(Request $request)
{
$search = new FileSearch();
$dirList = $this->generateDirList();
$form = $this->createForm(SearchType::class, $search, array('dir_list' => $dirList));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchFor = $form->get('searchFor')->getData();
$fileType = $form->get('fileType')->getData();
$searchDir = $form->get('searchDir')->getData();
$finder = new Finder();
if (isset($fileType)) {
$finder->files()->name("*.{$fileType}");
}
if (isset($searchDir)) {
$finder->files()->in($searchDir);
} else {
$finder->files()->in(__DIR__);
}
if (isset($searchFor)) {
$finder->contains($searchFor);
}
if (isset($finder) && count($finder) > 0) {
echo "<h3>Found results in {$searchDir}: </h3><br/>";
foreach ($finder as $key => $value) {
echo "<h4> {$value} contains '{$searchFor}' </h4>";
}
} else {
echo "No content '{$searchFor}' in '{$searchDir}'";
}
}
return $this->render('MihailSearchBundle:randomsearch:search_form.html.twig', array('form' => $form->createView()));
}
示例4: warmup
protected function warmup($warmupDir)
{
$this->getContainer()->get('filesystem')->remove($warmupDir);
$parent = $this->getContainer()->get('kernel');
$class = get_class($parent);
$namespace = '';
if (false !== ($pos = strrpos($class, '\\'))) {
$namespace = substr($class, 0, $pos);
$class = substr($class, $pos + 1);
}
$kernel = $this->getTempKernel($parent, $namespace, $class, $warmupDir);
$kernel->boot();
$warmer = $kernel->getContainer()->get('cache_warmer');
$warmer->enableOptionalWarmers();
$warmer->warmUp($warmupDir);
// fix container files and classes
$regex = '/' . preg_quote($this->getTempKernelSuffix(), '/') . '/';
$finder = new Finder();
foreach ($finder->files()->name(get_class($kernel->getContainer()) . '*')->in($warmupDir) as $file) {
$content = file_get_contents($file);
$content = preg_replace($regex, '', $content);
file_put_contents(preg_replace($regex, '', $file), $content);
unlink($file);
}
// fix meta references to the Kernel
foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) {
$content = preg_replace('/C\\:\\d+\\:"' . preg_quote($class . $this->getTempKernelSuffix(), '"/') . '"/', sprintf('C:%s:"%s"', strlen($class), $class), file_get_contents($file));
file_put_contents($file, $content);
}
}
示例5: loadResource
public function loadResource($language, $directoryRoot)
{
$this->language = $language;
$this->translator = new Translator($this->language);
$this->addLoader(new ArrayLoader(), 'array');
$this->addLoader(new YamlFileLoader(), 'yaml');
$finder = new Finder();
// Fetch all language files for translation
try {
$finder->files()->name('*.yml')->in($directoryRoot . 'config/translations/' . $language);
} catch (Exception $e) {
if ($language != 'en') {
$finder->files()->name('*.yml')->in($directoryRoot . 'config/translations/en');
}
}
foreach ($finder as $file) {
$resource = $file->getRealpath();
$filename = $file->getBasename('.yml');
// Handle application file different than commands
if ($filename == 'application') {
$this->writeTranslationByFile($resource, 'application');
} else {
$key = 'commands.' . $filename;
$this->writeTranslationByFile($resource, $key);
}
}
}
示例6: __construct
/**
* @param string $repository
* @param PriorityHandlerInterface $priorityHandler
* @param Filesystem $fs
* @param Finder $finder
* @param LockHandlerFactoryInterface $lockHandlerFactory
*/
public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null)
{
if (empty($repository)) {
throw new InvalidArgumentException('Argument repository empty or not defined.');
}
if (null === $fs) {
$fs = new Filesystem();
}
if (null === $finder) {
$finder = new Finder();
}
if (null === $lockHandlerFactory) {
$lockHandlerFactory = new LockHandlerFactory();
}
if (null === $priorityHandler) {
$priorityHandler = new StandardPriorityHandler();
}
$this->fs = $fs;
if (!$this->fs->exists($repository)) {
try {
$this->fs->mkdir($repository);
} catch (IOExceptionInterface $e) {
throw new InvalidArgumentException('An error occurred while creating your directory at ' . $e->getPath());
}
}
$this->priorityHandler = $priorityHandler;
$this->repository = $repository;
$this->finder = $finder;
$this->finder->files()->in($repository);
$this->lockHandlerFactory = $lockHandlerFactory;
return $this;
}
示例7: get_file_list_as_iterator
/**
* Get the file list as an iterator.
*
* @since 1.0.0
* @access public
*/
public function get_file_list_as_iterator()
{
//Get the files in the provided path
$this->finder->files()->in($this->path);
//Return the iterator
return $this->finder;
}
开发者ID:signalfire,项目名称:signalfire-cloud-backup,代码行数:13,代码来源:class-signalfire-cloud-backup-filetree.php
示例8: createMap
/**
* Create a map for a given path
*
* @param array $paths
* @return array
*/
public function createMap(...$paths)
{
$classes = [];
$this->finder->files()->ignoreUnreadableDirs()->in($paths);
foreach ($this->excludePathPatterns as $exclude) {
$this->finder->notPath($exclude);
}
foreach ($this->inPathPatterns as $inPath) {
$this->finder->path($inPath);
}
foreach ($this->names as $name) {
$this->finder->name($name);
}
/** @var SplFileInfo $file */
foreach ($this->finder as $file) {
$content = file_get_contents($file->getPathname());
preg_match('^\\s*class ([\\S]*)\\s*(extends|implements|{)^', $content, $match, PREG_OFFSET_CAPTURE);
if (isset($match[1])) {
$className = '\\' . trim($match[1][0]);
$offset = $match[1][1];
} else {
continue;
}
preg_match('|\\s*namespace\\s*([\\S]*)\\s*;|', substr($content, 0, $offset), $match);
if (isset($match[1]) && trim($match[1]) !== '') {
$className = '\\' . trim($match[1]) . $className;
}
if ($className !== '\\') {
$classes[$file->getPathname()] = $className;
}
}
return $classes;
}
示例9: load
/**
* {@inheritdoc}
*/
public function load($resource)
{
$files = $this->finder->files()->name('*.php')->ignoreDotFiles(true)->ignoreUnreadableDirs(true)->ignoreUnreadableDirs(true)->in($resource);
if (0 === $files->count()) {
throw new \InvalidArgumentException(sprintf('%s doesnt contains any php files', $resource));
}
return $this->parseFiles($files->getIterator());
}
示例10: syncTranslations
protected function syncTranslations($io, $language = null, $languages, $file, $appRoot)
{
$englishFilesFinder = new Finder();
$yaml = new Parser();
$dumper = new Dumper();
$englishDirectory = $appRoot . 'config/translations/en';
if ($file) {
$englishFiles = $englishFilesFinder->files()->name($file)->in($englishDirectory);
} else {
$englishFiles = $englishFilesFinder->files()->name('*.yml')->in($englishDirectory);
}
foreach ($englishFiles as $file) {
$resource = $englishDirectory . '/' . $file->getBasename();
$filename = $file->getBasename('.yml');
try {
$englishFile = file_get_contents($resource);
$englishFileParsed = $yaml->parse($englishFile);
} catch (ParseException $e) {
$io->error($filename . '.yml: ' . $e->getMessage());
continue;
}
foreach ($languages as $langCode => $languageName) {
$languageDir = $appRoot . 'config/translations/' . $langCode;
if (isset($language) && $langCode != $language) {
continue;
}
if (!isset($statistics[$langCode])) {
$statistics[$langCode] = ['total' => 0, 'equal' => 0, 'diff' => 0];
}
$resourceTranslated = $languageDir . '/' . $file->getBasename();
if (!file_exists($resourceTranslated)) {
file_put_contents($resourceTranslated, $englishFile);
$io->info(sprintf($this->trans('commands.translation.sync.messages.created-file'), $file->getBasename(), $languageName));
continue;
}
try {
//print $resourceTranslated . "\n";
$resourceTranslatedParsed = $yaml->parse(file_get_contents($resourceTranslated));
} catch (ParseException $e) {
$io->error($resourceTranslated . ':' . $e->getMessage());
continue;
}
$resourceTranslatedParsed = array_replace_recursive($englishFileParsed, $resourceTranslatedParsed);
try {
$resourceTranslatedParsedYaml = $dumper->dump($resourceTranslatedParsed, 10);
} catch (\Exception $e) {
$io->error(sprintf($this->trans('commands.translation.sync.messages.error-generating'), $resourceTranslated, $languageName, $e->getMessage()));
continue;
}
try {
file_put_contents($resourceTranslated, $resourceTranslatedParsedYaml);
} catch (\Exception $e) {
$io->error(sprintf('%s: %s', $this->trans('commands.translation.sync.messages.error-writing'), $resourceTranslated, $languageName, $e->getMessage()));
return 1;
}
}
}
}
示例11: collect
/**
* {@inheritDoc}
*/
public function collect() : AssetCollection
{
$files = [];
$this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.txt$/')->sortByType();
foreach ($this->finder as $file) {
$files[] = new TextFile(new File($file->getPathname()), $this->filesystem, dirname(Path::makeRelative($file->getPathname(), (string) $this->srcDir)));
}
return new AssetCollection($files);
}
示例12: load
/**
* {@inheritdoc}
*/
public function load(ClassMetadata $metadata, ParserInterface $parser)
{
$this->finder->files()->in($this->dir);
$content = array();
foreach ($this->finder as $file) {
$content[] = $parser->parse($metadata, $file->getRelativePathname(), $file->getContents());
}
return $content;
}
示例13: collect
/**
* {@inheritDoc}
*/
public function collect() : AssetCollection
{
$templates = [];
$this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.twig$/')->sortByType();
foreach ($this->finder as $template) {
$templates[] = new TwigTemplateFile(Path::makeRelative($template->getPathname(), (string) $this->srcDir), $this->twigData, $this->twig, $this->filesystem);
}
return new AssetCollection($templates);
}
示例14: getFiles
public function getFiles()
{
$files = [];
foreach ($this->finder->files()->name('*.php')->in($this->configPath) as $file) {
$nesting = $this->getConfigurationNesting($file);
$files[$nesting . basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
return $files;
}
示例15: getIterator
public function getIterator()
{
$files = array();
foreach ($this->finder->files() as $file) {
$item = new StorageSelection(new \SplFileInfo($file), $file->getFilename(), $file->getFilename());
$files[] = $item;
}
return new \ArrayIterator($files);
}