本文整理汇总了PHP中Symfony\Component\Finder\Finder::depth方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::depth方法的具体用法?PHP Finder::depth怎么用?PHP Finder::depth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::depth方法的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: isRecursive
/**
* @param bool $isRecursive
* @return $this
*/
public function isRecursive($isRecursive = true)
{
if ($isRecursive === false) {
$this->finder->depth(0);
} else {
$this->finder->depth('>= 0');
}
return $this;
}
示例3: getReleases
/**
* @return array
*/
public function getReleases()
{
$releases = [];
$this->finder->depth('== 2')->name('*.zip');
/** @var SplFileInfo $file */
foreach ($this->finder as $file) {
$releases[] = new Release($file);
}
return $releases;
}
示例4: 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"));
}
}
示例5: fix
public function fix()
{
// Clear the cache beforehand, ar this will make sure we have a lot less files to deal with.
$result = $this->app['cache']->clearCache();
$files = '';
$finder = new Finder();
$finder->depth('<4');
foreach ($this->locations as $loc) {
$finder->in($loc);
}
foreach ($finder as $file) {
$perms = substr(sprintf('%o', $file->getPerms()), -3);
if ($file->isDir() && $perms != '777') {
@chmod($file, 0777);
if (!$file->isWritable()) {
$res = $this->getPrintInfoFile($file);
$files .= $res;
}
} else {
if (!$file->isDir() && !$this->checkFilePerms($perms)) {
// echo "joe! " . $this->checkFilePerms($perms);
@chmod($file, 0666);
$res = $this->getPrintInfoFile($file);
$files .= $res;
}
}
}
$msg = "Below you'll see the output of the changes. If there are lines\n left with a red '<i class='fa fa-close red'></i>', then these files /\n folders could not be modified by Bolt or the Chmodinator. You should use\n the command-line or your (S)FTP client to make sure these files are set\n correctly.";
$data = array('files' => $files, 'msg' => $msg);
return $this->render('index.twig', $data);
}
示例6: ensureProjectRoot
protected function ensureProjectRoot()
{
if (!($this->rootDir = $this->input->getOption('project-root'))) {
$this->rootDir = getcwd();
}
$this->rootDir = realpath($this->rootDir);
$this->fs->mkdir($this->rootDir);
$finder = new Finder();
$finder->in($this->rootDir);
$finder->depth(0);
$finder->ignoreVCS(false);
$rootFiles = [];
/** @var SplFileInfo $splInfo */
foreach ($finder as $splInfo) {
$rootFiles[] = $splInfo->getFilename();
}
$requiredFiles = ['composer.json', 'composer.lock'];
$requiredDirs = ['vendor'];
foreach (array_merge($requiredFiles, $requiredDirs) as $file) {
if (!in_array($file, $rootFiles)) {
// possibly not root
$this->output->writeln("<error>You should either run this script under your project root directory, or provide the '--project-root' option.</error>");
$this->output->writeln("The project root directory should contain at least the following files and directories:");
foreach ($requiredFiles as $requiredFile) {
$this->output->writeln("\t- <comment>{$requiredFile}</comment>");
}
foreach ($requiredDirs as $requiredDir) {
$this->output->writeln("\t- <comment>{$requiredDir}/</comment>");
}
exit(1);
}
}
}
示例7: getFiles
/**
* Finds all the files for the given config
*
* @param array $source
*
* @return SplFileInfo[]
*
* @throws \Exception
*/
protected function getFiles(array $source)
{
$fileSet = [];
foreach ($source as $set) {
if (!array_key_exists('files', $set)) {
throw new \Exception("`src` must have a `files` option");
}
if (!array_key_exists('path', $set)) {
$set['path'] = getcwd();
}
if (!array_key_exists('recursive', $set)) {
$set['recursive'] = false;
}
$paths = is_array($set['path']) ? $set['path'] : [$set['path']];
$files = is_array($set['files']) ? $set['files'] : [$set['files']];
foreach ($paths as $path) {
foreach ($files as $file) {
$finder = new Finder();
$finder->files()->in($path)->name($file);
if (!$set['recursive']) {
$finder->depth('== 0');
}
$fileSet = $this->appendFileSet($finder, $fileSet);
}
}
}
return $fileSet;
}
示例8: checkDirAction
public function checkDirAction()
{
$paths = array('/' => array('depth' => '<1', 'dir' => true), 'app' => array('depth' => '<1', 'dir' => true), 'src' => array(), 'plugins' => array(), 'api' => array(), 'vendor' => array('depth' => '<1', 'dir' => true), 'vendor2' => array('depth' => '<1', 'dir' => true), 'vendor_user' => array('depth' => '<1', 'dir' => true), 'web' => array('depth' => '<1', 'dir' => true));
$errorPaths = array();
if (PHP_OS !== 'WINNT') {
foreach ($paths as $folder => $opts) {
$finder = new Finder();
if (!empty($opts['depth'])) {
$finder->depth($opts['depth']);
}
if (!empty($opts['dir'])) {
$finder->directories();
}
try {
$finder->in($this->container->getParameter('kernel.root_dir') . '/../' . $folder);
foreach ($finder as $fileInfo) {
$relaPath = $fileInfo->getRealPath();
if (!(is_writable($relaPath) && is_readable($relaPath))) {
$errorPaths[] = $relaPath;
}
}
} catch (\Exception $e) {
}
}
}
return $this->render('TopxiaAdminBundle:System:Report/dir-permission.html.twig', array('errorPaths' => $errorPaths));
}
示例9: getServerFiles
private function getServerFiles($config, $destination)
{
$path = Path::assemble(BASE_PATH, $destination);
$finder = new Finder();
// Set folder location
$finder->in($path);
// Limit by depth
$finder->depth('<' . array_get($config, 'depth', '1'));
// Limit by file extension
foreach (array_get($config, array('allowed', 'types'), array()) as $ext) {
$finder->name("/\.{$ext}/i");
}
// Fetch matches
$matches = $finder->files()->followLinks();
// Build array
$files = array();
foreach ($matches as $file) {
$filename = Path::trimSubdirectory(Path::toAsset($file->getPathname(), false));
$display_name = ltrim(str_replace($path, '', $file->getPathname()), '/');
$value = (Config::get('prepend_site_root_to_uploads', false))
? '{{ _site_root }}' . ltrim($filename, '/')
: $filename;
$files[] = compact('value', 'display_name');
}
return $files;
}
示例10: execute
/**
* execute this command
*
* @param InputInterface $input CLI input data
* @param OutputInterface $output CLI output data
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$startTime = microtime(true);
// Create a new Finder instance
$finder = new Finder();
// Search for files in the directory specified in the CLI argument
$finder->files();
// Get paths to scan in; Either from file or from the CLI arguments
if ($input->getOption('readfromfile')) {
$paths = $input->getArgument('paths');
$pathFile = reset($paths);
$paths = $this->readPathsFromFile($pathFile);
} else {
$paths = $input->getArgument('paths');
}
foreach ($paths as $path) {
$finder->in($path);
}
// Limit search to recursion level
if ($input->getOption('depth')) {
$finder->depth("<= " . $input->getOption('depth'));
}
// Append system specific search criteria
foreach ($this->adapters as $adapterName => $adapter) {
$finder = $adapter->appendDetectionCriteria($finder);
}
$results = array();
// Iterate through results
foreach ($finder as $file) {
// Iterate through system adapters
foreach ($this->adapters as $adapterName => $adapter) {
// Pass the search result to the system adapter to verify the result
if (!($system = $adapter->detectSystem($file))) {
// search result doesn't match with system
continue;
}
// If enabled, try to determine the used CMS version
if ($input->getOption('versions')) {
$system->version = $adapter->detectVersion($system->getPath());
}
// Append successful result to array
$results[] = $system;
}
}
// Generate stats array
$stats = $this->generateStats($results, $input->getOption('versions'));
// Write output to command line
$output->writeln('<info>Successfully finished scan!</info>');
$output->writeln(sprintf('CMSScanner found %d CMS installations!', count($results)));
// Write stats to command line
$this->outputStats($stats, $input->getOption('versions'), $output);
// Write report file
if ($input->getOption('report')) {
$this->writeReport($results, $input->getOption('report'));
$output->writeln(sprintf("Report was written to %s", $input->getOption('report')));
}
$this->outputProfile($startTime, $output);
}
示例11: getSchemas
/**
* Find every schema files.
*
* @param string|array $directory Path to the input directory
* @param bool $recursive Search for file inside the input directory and all subdirectories
*
* @return array List of schema files
*/
protected function getSchemas($directory, $recursive = false)
{
$finder = new Finder();
$finder->name('*schema.xml')->sortByName()->in($directory);
if (!$recursive) {
$finder->depth(0);
}
return iterator_to_array($finder->files());
}
示例12: compile
public function compile(ImportEvent $importEvent)
{
$results = ['constants' => [], 'handlers' => []];
$wildcards = [];
foreach (['constants', 'handlers'] as $type) {
$e = $type === 'constants';
foreach (['App', 'Minute'] as $dir) {
$prefix = $e ? "{$dir}\\Event\\" : "{$dir}\\EventHandler\\";
$dirs = $this->resolver->find($prefix);
if (!empty($dirs)) {
$finder = new Finder();
$fix = function ($path, $replacement) use($prefix) {
return preg_replace('/\\.php$/', '', preg_replace(sprintf('/^.*%s/i', preg_quote($prefix)), $replacement, $path));
};
$files = $finder->depth('< 3')->files()->in($dirs)->name('*.php')->contains($e ? 'const ' : 'function ');
foreach ($files as $file) {
$classPath = $this->utils->dosPath((string) $file);
$classPath = $fix($classPath, $prefix);
$basename = $fix($classPath, '');
if ($reflector = new ReflectionClass($classPath)) {
if ($e) {
foreach ($reflector->getConstants() as $value => $constant) {
$parts = explode('.', $constant);
for ($i = 0, $j = count($parts) - 1; $i < $j; $i++) {
$wildcard = join('.', array_slice($parts, 0, $i + 1)) . '.*';
$wildcards[$wildcard] = ['name' => sprintf('%s', strtr($wildcard, '.', '_')), 'value' => $wildcard, 'group' => 'Wildcard events'];
}
$results['constants'][] = ['name' => sprintf('%s in %s', $this->utils->filename($value), $basename), 'value' => $constant, 'group' => $parts[0]];
}
} else {
foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (!preg_match('/^\\_/', $method->name)) {
$value = sprintf("%s@%s", $method->class, $method->name);
$parts = explode('\\', $classPath);
$results['handlers'][] = ['name' => sprintf('%s@%s', $basename, $method->name), 'value' => $value, 'group' => $parts[2] ?? 'App'];
}
}
}
}
}
}
}
usort($results[$type], function ($a, $b) {
return $a['group'] === $b['group'] ? $a['value'] <=> $b['value'] : $a['group'] <=> $b['group'];
});
}
usort($wildcards, function ($a, $b) {
return $a['value'] <=> $b['value'];
});
foreach ($wildcards as $wildcard => $event) {
$results['constants'][] = $event;
}
$importEvent->addContent($results);
}
示例13: schemaProvider
public function schemaProvider()
{
$finder = new Finder();
$finder->directories()->in(__DIR__ . '/fixtures');
$finder->depth('< 1');
$data = array();
foreach ($finder as $directory) {
$data[] = [$directory];
}
return $data;
}
示例14: resourceProvider
public function resourceProvider()
{
$finder = new Finder();
$finder->directories()->in(__DIR__ . '/fixtures');
$finder->depth('< 1');
$data = array();
foreach ($finder as $directory) {
$data[] = [file_get_contents($directory->getRealPath() . '/Resource/TestResource.php'), $directory->getRealPath() . '/swagger.json', $directory->getFilename()];
}
return $data;
}
示例15: findManifest
protected function findManifest()
{
$finder = new Finder();
$finder->depth('==0')->name('*.xml')->files();
foreach ($finder->in($this->path) as $file) {
/* @var $file \SplFileObject */
$this->manifest = new \SimpleXMLElement($file->getContents());
$this->installFile = $file->getBasename();
return true;
}
return false;
}