当前位置: 首页>>代码示例>>PHP>>正文


PHP Finder::getIterator方法代码示例

本文整理汇总了PHP中Symfony\Component\Finder\Finder::getIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::getIterator方法的具体用法?PHP Finder::getIterator怎么用?PHP Finder::getIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Finder\Finder的用法示例。


在下文中一共展示了Finder::getIterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 /**
  * import
  *
  * @param string                $sourceDir
  * @param DocumentNodeInterface $targetNode
  * @param array                 $excludes
  */
 public function import($sourceDir, DocumentNodeInterface $targetNode, array $excludes = array())
 {
     if (!is_dir($sourceDir)) {
         throw new \InvalidArgumentException(sprintf('The directory %s does not exist', $sourceDir));
     }
     $this->emn->persist($targetNode);
     $currentNode = array(0 => $targetNode);
     $finder = new Finder();
     $finder->in($sourceDir);
     $files = $finder->getIterator();
     foreach ($files as $file) {
         foreach ($excludes as $exclude) {
             if (strpos($file->getRelativePathname(), $exclude) !== false) {
                 continue 2;
             }
         }
         $depth = $files->getDepth();
         if ($file->isDir()) {
             $currentNode[$depth + 1] = $this->importDir($currentNode, $depth, $file, $targetNode);
         } elseif ($file->isFile()) {
             $this->importFile($currentNode, $depth, $file);
         }
     }
     $this->emn->flush();
 }
开发者ID:DavidG04,项目名称:ErichardDmsBundle,代码行数:32,代码来源:FilesystemImporter.php

示例2: execute

 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $paths = $input->getArgument('paths');
     $finder = new Finder();
     $finder->files();
     $finder->name('*.php');
     foreach ($paths as $path) {
         $finder->in($path);
     }
     try {
         $files = $finder->getIterator();
     } catch (\Exception $ex) {
         return 1;
     }
     if (empty($files)) {
         $output->writeln('No files to analyze');
         return 1;
     }
     $analyzer = new Analyzer();
     $result = $analyzer->run($files);
     $output->writeln('<html><body><pre>');
     $output->writeln(print_r($result, true));
     $output->writeln('</pre></body></html>');
     return 0;
 }
开发者ID:hacfi,项目名称:php-file-analyzer,代码行数:33,代码来源:Command.php

示例3: locate

 /**
  * {@inheritdoc}
  */
 public function locate($name, $currentPath = null, $first = true)
 {
     if (empty($name)) {
         throw new \InvalidArgumentException('An empty file name is not valid to be located.');
     }
     if ($this->isAbsolutePath($name)) {
         if (!file_exists($name)) {
             throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
         }
         return $name;
     }
     $directories = $this->paths;
     if (null !== $currentPath) {
         $directories[] = $currentPath;
         $directories = array_values(array_unique($directories));
     }
     $filepaths = [];
     $finder = new Finder();
     $finder->files()->name($name)->ignoreUnreadableDirs()->in($directories);
     /** @var SplFileInfo $file */
     if ($first && null !== ($file = $finder->getIterator()->current())) {
         return $file->getPathname();
     }
     foreach ($finder as $file) {
         $filepaths[] = $file->getPathname();
     }
     if (!$filepaths) {
         throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $directories)));
     }
     return array_values(array_unique($filepaths));
 }
开发者ID:liverbool,项目名称:dos-theme-bundle,代码行数:34,代码来源:RecursiveFileLocator.php

示例4: isEmpty

 /**
  * Test is files or directories passed as arguments are empty.
  * Only valid for regular files and directories.
  *
  * @param mixed $files String or array of strings of path to files and directories.
  *
  * @return boolean True if all arguments are empty. (Size 0 for files and no children for directories).
  */
 public function isEmpty($files)
 {
     if (!$files instanceof \Traversable) {
         $files = new \ArrayObject(is_array($files) ? $files : array($files));
     }
     foreach ($files as $file) {
         if (!$this->exists($file)) {
             throw new FileNotFoundException(null, 0, null, $file);
         }
         if (is_file($file)) {
             $file_info = new \SplFileInfo($file);
             if ($file_info->getSize() !== 0) {
                 return false;
             }
         } elseif (is_dir($file)) {
             $finder = new Finder();
             $finder->in($file);
             $it = $finder->getIterator();
             $it->rewind();
             if ($it->valid()) {
                 return false;
             }
         } else {
             throw new IOException(sprintf('File "%s" is not a directory or a regular file.', $file), 0, null, $file);
         }
     }
     return true;
 }
开发者ID:inetprocess,项目名称:libsugarcrm,代码行数:36,代码来源:Filesystem.php

示例5: fetchFromCache

 protected function fetchFromCache($dimensions)
 {
     $fs = new Filesystem();
     $cacheDir = $_SERVER['HOME'] . '/.symfony/media';
     if (!$fs->exists($cacheDir)) {
         $fs->mkdir($cacheDir, 0777);
     } else {
         $cacheDir .= '/' . $dimensions['w'] . '-' . $dimensions['h'];
         if (!$fs->exists($cacheDir)) {
             $fs->mkdir($cacheDir, 0777);
         } else {
             $finder = new Finder();
             $files = $finder->in($cacheDir . '/')->files();
             if ($files->count() === 3) {
                 $iterator = $finder->getIterator();
                 $iterator->rewind();
                 for ($i = 0; $i < rand(0, 2); $i++) {
                     $iterator->next();
                 }
                 $file = new File($iterator->current());
                 $fs->copy($file->getRealPath(), sys_get_temp_dir() . '/' . $file->getFilename());
                 return new File(sys_get_temp_dir() . '/' . $file->getFilename());
             }
         }
     }
 }
开发者ID:alpixel,项目名称:AlpixelMediaBundle,代码行数:26,代码来源:MediaProvider.php

示例6: availableArt

 /**
  * Return available art
  * @return array
  */
 protected function availableArt()
 {
     // Find all of the art in the assets directory.
     $finder = new Finder();
     $finder->files()->in($this->config->get('assets_dir'))->depth('== 0')->name('*.txt')->sortbyname();
     return array_values(array_map(function ($file) {
         return $file->getBasename('.txt');
     }, (array) $finder->getIterator()));
 }
开发者ID:pantheon-systems,项目名称:terminus,代码行数:13,代码来源:ArtCommand.php

示例7: availableReflections

 /**
  * Available file reflections. Generator.
  *
  *
  * @generate ReflectionFile[]
  */
 protected function availableReflections()
 {
     /**
      * @var SplFileInfo $file
      */
     foreach ($this->finder->getIterator() as $file) {
         $reflection = $this->tokenizer->fileReflection((string) $file);
         //We are not analyzing files which has includes, it's not safe to require such reflections
         if ($reflection->hasIncludes()) {
             $this->logger()->warning("File '{filename}' has includes and will be excluded from analysis.", ['filename' => (string) $file]);
             continue;
         }
         /**
          * @var ReflectionFile $reflection
          */
         (yield $reflection);
     }
 }
开发者ID:tuneyourserver,项目名称:components,代码行数:24,代码来源:AbstractLocator.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln($this->getDescription() . PHP_EOL);
     $target = $input->getArgument('target');
     $sources = $this->createArrayBy($input->getOption('source'));
     $excludes = $this->createArrayBy($input->getOption('exclude'));
     $noComments = (bool) $input->getOption('nocomments');
     $this->writer->setTarget($target);
     $this->finder->in($sources)->exclude($excludes);
     if ($notName = $input->getOption('notname')) {
         $this->finder->notName($notName);
     }
     $output->writeln(sprintf(Message::PROGRESS_FILTER, $this->finder->count()));
     $classMap = $this->filter->extractClassMapFrom($this->finder->getIterator());
     $output->writeln(sprintf(Message::PROGRESS_WRITE, $target));
     $this->writer->minify($classMap, $noComments);
     $output->writeln(PHP_EOL . Message::PROGRESS_DONE . PHP_EOL);
 }
开发者ID:mamuz,项目名称:squeezer,代码行数:18,代码来源:Command.php

示例9: isEmptyDir

 private function isEmptyDir($path)
 {
     if ($this->fs->exists($path) === true) {
         $finder = new Finder();
         $finder->in($path);
         $iterator = $finder->getIterator();
         $iterator->next();
         return iterator_count($iterator) === 0;
     }
     return true;
 }
开发者ID:jjk-jacky,项目名称:Spress,代码行数:11,代码来源:NewSite.php

示例10: getRepositoryFiles

 public function getRepositoryFiles()
 {
     try {
         $f = new Finder();
         $f->name('*Repository.php');
         $f->in($this->getDocumentDirectory());
         return $f->getIterator();
     } catch (\Exception $e) {
         return array();
     }
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:11,代码来源:OdmMetadata.php

示例11: matches

 /**
  * {@inheritDoc}
  */
 public function matches(Repo $repo)
 {
     $directory = $repo->getGitRepo()->getDir();
     $finder = new Finder();
     $finder->files()->name('*Kernel.php')->in($directory)->depth('< 3');
     $candidates = $finder->getIterator();
     foreach ($candidates as $candidate) {
         if (preg_match('/public function registerBundles/s', file_get_contents($candidate))) {
             return true;
         }
     }
     return false;
 }
开发者ID:ruian,项目名称:KnpBundles,代码行数:16,代码来源:SymfonyKernel.php

示例12: __construct

 /**
  * Initializes the internal Symfony Finder with appropriate filters
  *
  * @param string $sources  Path to source files to be archived
  * @param array  $excludes Composer's own exclude rules from composer.json
  */
 public function __construct($sources, array $excludes)
 {
     $fs = new Filesystem();
     $sources = $fs->normalizePath($sources);
     $filters = array(new HgExcludeFilter($sources), new GitExcludeFilter($sources), new ComposerExcludeFilter($sources, $excludes));
     $this->finder = new Finder();
     $filter = function (\SplFileInfo $file) use($sources, $filters, $fs) {
         if ($file->isLink() && strpos($file->getLinkTarget(), $sources) !== 0) {
             return false;
         }
         $relativePath = preg_replace('#^' . preg_quote($sources, '#') . '#', '', $fs->normalizePath($file->getRealPath()));
         $exclude = false;
         foreach ($filters as $filter) {
             $exclude = $filter->filter($relativePath, $exclude);
         }
         return !$exclude;
     };
     if (method_exists($filter, 'bindTo')) {
         $filter = $filter->bindTo(null);
     }
     $this->finder->in($sources)->filter($filter)->ignoreVCS(true)->ignoreDotFiles(false);
     parent::__construct($this->finder->getIterator());
 }
开发者ID:alancleaver,项目名称:composer,代码行数:29,代码来源:ArchivableFilesFinder.php

示例13: calculateDirVersion

 private function calculateDirVersion(Resource $resource)
 {
     // Adjust finder
     $dir = $resource->getMetadata('dir');
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException(sprintf('Directory "%s" not found.', $dir));
     }
     $this->finder->files()->in($dir);
     if ($resource->hasMetadata('filter')) {
         $this->finder->name($resource->getMetadata('filter'));
     }
     if ($resource->hasMetadata('depth')) {
         $this->finder->depth($resource->getMetadata('depth'));
     } else {
         $this->finder->depth('>= 0');
     }
     $version = array();
     /** @var \SplFileInfo $file */
     foreach ($this->finder->getIterator() as $file) {
         $version[md5($file->getRealPath())] = filemtime($file);
     }
     return $version;
 }
开发者ID:yosmanyga,项目名称:resource,代码行数:23,代码来源:DirectoryVersionChecker.php

示例14: indexAction

 /**
  * @Route("s/", name="admin_file_home", defaults={"page" = 1})
  * @Route("s/page-{page}", name="admin_file_home_page", requirements={"page" : "\d+"})
  */
 public function indexAction($page)
 {
     $page = $page < 1 ? 1 : $page;
     $itemsPerPage = 10;
     $finder = new Finder();
     $finder->files()->in($this->getParameter('uploads_directory'));
     $iterator = iterator_to_array($finder->getIterator());
     $total = $finder->count();
     $totalPages = ceil($total / $itemsPerPage);
     if ($totalPages != 0 && $page > $totalPages) {
         throw new NotFoundHttpException('There are only ' . $totalPages . ' pages to show');
     }
     $start = ($page - 1) * $itemsPerPage;
     return $this->render('/admin/file/admin_file_index.html.twig', ['files' => array_slice($iterator, $start, $itemsPerPage), 'total' => $total, 'totalPages' => $totalPages, 'page' => $page]);
 }
开发者ID:JuanLuisGarciaBorrego,项目名称:jedy,代码行数:19,代码来源:FileController.php

示例15: testSomeEdge

 public function testSomeEdge()
 {
     $nsVertex = 'Trismegiste\\Mondrian\\Transform\\Vertex\\';
     $scan = new Finder();
     $scan->files()->in(__DIR__ . '/../Fixtures/Project/');
     $this->compiler->run($scan->getIterator());
     $result = $this->graph;
     $classVertex = $this->findVertex($result, $nsVertex . 'ClassVertex', 'Project\\Concrete');
     $this->assertNotNull($classVertex);
     $signature = $this->findVertex($result, $nsVertex . 'MethodVertex', 'Project\\Concrete::simple');
     $this->assertNotNull($signature);
     $this->assertNotNull($result->searchEdge($classVertex, $signature));
     $impl = $this->findVertex($result, $nsVertex . 'ImplVertex', 'Project\\Concrete::simple');
     $this->assertNotNull($impl);
     $this->assertNotNull($result->searchEdge($signature, $impl));
 }
开发者ID:trismegiste,项目名称:mondrian,代码行数:16,代码来源:FullGraphTest.php


注:本文中的Symfony\Component\Finder\Finder::getIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。