本文整理汇总了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();
}
示例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;
}
示例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));
}
示例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;
}
示例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());
}
}
}
}
示例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()));
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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());
}
示例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;
}
示例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]);
}
示例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));
}