本文整理汇总了PHP中Symfony\Component\Finder\Finder::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::count方法的具体用法?PHP Finder::count怎么用?PHP Finder::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: testGenerateTransferObjectsShouldGenerateTransferObjects
/**
* @depends testDeleteGeneratedTransferObjectsShouldDeleteAllGeneratedTransferObjects
*
* @return void
*/
public function testGenerateTransferObjectsShouldGenerateTransferObjects()
{
$this->getFacade()->generateTransferObjects($this->getMessenger());
$finder = new Finder();
$finder->in($this->getConfig()->getClassTargetDirectory())->name('*Transfer.php');
$this->assertTrue($finder->count() > 0);
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument('path');
if (!file_exists($path)) {
throw new FileNotFoundException($path);
}
/** @var EntityManager $em */
$em = $this->app['orm.em'];
// Disable SQL Logger
$em->getConnection()->getConfiguration()->setSQLLogger(null);
if (!$input->getOption('append')) {
$output->writeln('Purging database');
$em->getConnection()->executeUpdate("DELETE FROM address");
}
if (is_dir($path)) {
$finder = new Finder();
$finder->in($path)->name('/\\.csv/i');
$output->writeln('Loading CSV from ' . $path . ' (' . $finder->count() . ' files)');
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$this->loadFile($output, $file->getPathname());
}
} else {
$this->loadFile($output, $path);
}
return 0;
}
示例4: processFile
private function processFile(SplFileInfo $path)
{
$relativeDirName = dirname(str_replace($this->inPath, '', $path->getPathname()));
$filenameParts = explode('/', $relativeDirName);
$pdfDir = array_pop($filenameParts);
$restaurant = array_pop($filenameParts);
$outDir = $this->outPath . '/' . $relativeDirName;
if (!is_dir($outDir)) {
mkdir($outDir, 0777, true);
}
$outFilename = $outDir . '/' . str_replace('.pdf', '-%03d.png', $path->getFilename());
$convertCommand = "gm convert -density 300 \"{$path->getPathname()}\" -resize '1280x1280>' +profile '*' +adjoin \"{$outFilename}\"";
$this->output->writeln("Processing {$path->getPathname()}");
// convert directory
exec($convertCommand);
// create csv file
$finder = new Finder();
$finder->files()->name('*.png')->in($outDir);
/** @type SplFileInfo $file */
$index = 1;
$this->output->writeln("-- " . $finder->count() . " images");
foreach ($finder as $file) {
if (!isset($this->outCsv[$restaurant])) {
$this->outCsv[$restaurant] = [];
}
$this->outCsv[$restaurant][] = ['restaurant' => $restaurant, 'pdf' => $path->getRelativePathname(), 'page' => $index, 'image' => $relativeDirName . '/' . $file->getFilename(), 'folder' => $relativeDirName];
$index++;
}
}
示例5: load
/**
* Load a resource
*
* @param $name
* @return array
* @throws LogicException
*/
public function load($name)
{
if ($this->hasAddedPaths !== true) {
throw new LogicException('You must call one of addPath() or addPaths() methods before load().');
}
if ($cached = $this->get($name)) {
return $cached;
}
$finder = new Finder();
$name = $this->ensureDefaultFormat($name);
$finder->files()->in($this->paths)->name($name);
if (!$finder->count()) {
return false;
}
$paths = [];
foreach ($finder as $file) {
$paths[] = $file->getRealpath();
}
$path = end($paths);
$extension = pathinfo($path, PATHINFO_EXTENSION);
$handler = $this->getHandler($extension);
$resource = $handler->load($path);
$this->data[$name] = $resource;
return $resource;
}
示例6: compile
public function compile($path)
{
$this->output->write('Searching for files...');
$finder = new Finder();
$finder->files()->name('*.php')->in($path);
$count = $finder->count();
$this->output->writeln(sprintf('%u file(s) found', $count));
$index = 0;
$mappings = array();
foreach ($finder as $file) {
$index++;
$this->output->writeln(sprintf('Parsing file [%u/%u]: %s', $index, $count, $file));
$fileContent = file_get_contents($file);
$tokenParser = new TokenParser($fileContent);
$tokenParser->parse($fileContent);
if (!$tokenParser->hasClass()) {
$this->output->writeln('skipped!');
continue;
}
if (!class_exists($tokenParser->getFullClassName(), false)) {
include $file;
}
$mappings = array_merge($mappings, $this->processClass($tokenParser->getFullClassName(), $path));
}
return $mappings;
}
示例7: indexAction
public function indexAction(Request $request)
{
$form = $request->request->all();
$no_js = $request->query->get('no-js') || 0;
$script = $no_js == 1 ? 0 : 1;
$db_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/databases";
try {
$this->datasources = new \SimpleXMLElement($db_dir . "/DataSources.xml", LIBXML_NOWARNING, true);
$datasourcesCount = $this->datasources->DataSource->count();
} catch (\Exception $e) {
$datasourcesCount = 0;
}
$userManager = $this->get('fos_user.user_manager');
$users = $userManager->findUsers();
$finder = new Finder();
$simu_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/simulators";
$finder->depth('== 0')->files()->name('*.xml')->in($simu_dir);
$simulatorsCount = $finder->count();
$finder = new Finder();
$views_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/views";
$finder->depth('== 0')->ignoreVCS(true)->exclude(array('admin', 'base', 'Theme'))->directories()->in($views_dir);
$viewsCount = $finder->count();
$hiddens = array();
$hiddens['script'] = $script;
$silex = new Application();
$silex->register(new MobileDetectServiceProvider());
try {
return $this->render('EUREKAG6KBundle:admin/pages:index.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'home', 'datasourcesCount' => $datasourcesCount, 'usersCount' => count($users), 'simulatorsCount' => $simulatorsCount, 'viewsCount' => $viewsCount, 'hiddens' => $hiddens));
} catch (\Exception $e) {
echo $e->getMessage();
throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
}
}
示例8: patchFileExists
public function patchFileExists($patchFileName, Finder $finder = null)
{
if (is_null($finder)) {
$finder = $finder = new Finder();
}
$finder->files()->in($this->patchDir)->name($patchFileName);
return $finder->count() > 0;
}
示例9: 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);
}
示例10: execute
/**
* @return void
*/
public function execute()
{
if (is_dir(getcwd() . '/vendor')) {
$finder = new Finder();
$finder->files()->depth(3)->in(getcwd() . '/vendor');
if ($finder->count() == 0) {
$filesystem = new Filesystem();
$filesystem->recursiveRemoveDirectory(getcwd() . '/vendor');
}
}
}
示例11: getMessages
/**
* @param string $directory
*
* @return \Swift_Message[]
*/
private function getMessages($directory)
{
$finder = new Finder();
$finder->files()->name('*.message')->in($directory);
Assert::notEq($finder->count(), 0, sprintf('No message files found in %s.', $directory));
$messages = [];
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$messages[] = unserialize($file->getContents());
}
return $messages;
}
示例12: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelperSet()->get('formatter');
$path = $input->getArgument('path') ?: '';
$filesystem = new Filesystem();
if (!$filesystem->isAbsolutePath($path)) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
$path = rtrim(realpath($path), DIRECTORY_SEPARATOR);
if (is_file($path)) {
$files = new \ArrayIterator(array(new \SplFileInfo($path)));
} else {
$path .= DIRECTORY_SEPARATOR;
$files = new Finder();
$files->files()->name('*.php')->ignoreDotFiles(true)->ignoreVCS(true)->exclude('vendor')->in($path);
}
$output->writeln(sprintf("\rChecking %s", $path));
$total = $files->count();
$parser = Factory::createParser();
$index = 1;
/** @var \SplFileInfo $file */
foreach ($files as $file) {
$output->write(sprintf("\rParsing file %s/%s", $index, $total));
$parser->parse($file);
++$index;
}
$output->writeln(PHP_EOL);
$errorCollection = $parser->getErrorCollection();
$errorCount = count($errorCollection);
if ($errorCount > 0) {
$message = $formatter->formatBlock(sprintf('%s %s found on your code.', $errorCount, $errorCount > 1 ? 'errors were' : 'error was'), 'error', true);
$output->writeln($message);
$output->writeln('');
/** @var Error $error */
foreach ($errorCollection as $error) {
$output->writeln(sprintf(' %s', $error->getMessage()));
if ($error->getHelp()) {
$output->writeln(sprintf(' > %s', $error->getHelp()));
}
$output->writeln(sprintf(' <fg=cyan>%s</fg=cyan> on line <fg=cyan>%s</fg=cyan>', str_replace($path, '', $error->getFilename()), $error->getLine()));
$output->writeln('');
}
return 1;
}
$message = $formatter->formatBlock('No error was found when checking your code.', 'info', false);
$output->writeln($message);
$output->writeln('');
$message = $formatter->formatBlock(array('Note:', '> As this tool only do a static analyze of your code, you cannot blindly rely on it.', '> The best way to ensure that your code can run on PHP 7 is still to run a complete test suite on the targeted version of PHP.'), 'comment', false);
$output->writeln($message);
$output->writeln(PHP_EOL);
return 0;
}
示例13: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest() && $this->isCacheExpired()) {
$lastUpdateTime = $this->storage->getLatestUpdatedAt();
if ($lastUpdateTime instanceof \DateTime) {
$finder = new Finder();
$finder->files()->in($this->cacheDirectory . '/translations')->date('< ' . $lastUpdateTime->format('Y-m-d H:i:s'));
if ($finder->count() > 0) {
$this->translator->removeLocalesCacheFiles($this->managedLocales);
}
}
}
}
示例14: agenteAtivo
public function agenteAtivo($em)
{
$logger = $this->get('logger');
// Encontra agentes ativos
$rootDir = $this->container->get('kernel')->getRootDir();
$webDir = $rootDir . "/../web/";
$downloadsDir = $webDir . "downloads/";
if (!is_dir($downloadsDir)) {
mkdir($downloadsDir);
}
$cacicDir = $downloadsDir . "cacic/";
if (!is_dir($cacicDir)) {
mkdir($cacicDir);
}
// Varre diretório do Cacic
$finder = new Finder();
$finder->depth('== 0');
$finder->directories()->in($cacicDir);
$tipo_so = $em->getRepository('CacicCommonBundle:TipoSo')->findAll();
$found = false;
$platforms = 0;
foreach ($finder as $version) {
//$logger->debug("1111111111111111111111111111111 ".$version->getFileName());
if ($version->getFileName() == 'current') {
$found = true;
foreach ($tipo_so as $so) {
$agentes_path = $version->getRealPath() . "/" . $so->getTipo();
$agentes = new Finder();
try {
$agentes->files()->in($agentes_path);
} catch (\InvalidArgumentException $e) {
$logger->error($e->getMessage());
$platforms += 1;
$this->get('session')->getFlashBag()->add('notice', '<p>Não foram encontrados agentes para a plataforma ' . $so->getTipo() . '. Por favor, faça upload dos agentes na interface.</p>');
continue;
}
if ($agentes->count() == 0) {
$platforms += 1;
$this->get('session')->getFlashBag()->add('notice', '<p>Não foram encontrados agentes para a plataforma ' . $so->getTipo() . '. Por favor, faça upload dos agentes na interface.</p>');
}
}
}
}
if (!$found) {
$this->get('session')->getFlashBag()->add('notice', 'Não existe nenhum agente ativo. Por favor, faça upload dos agentes na interface.');
return sizeof($tipo_so);
} else {
return $platforms;
}
}
示例15: 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]);
}