You can use patterns (delimited with / sign) or simple strings.
$finder->notPath('some/special/dir')
$finder->notPath('/some\/special\/dir/') // same as above
Use only / as dirname separator.
/** * 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; }
public static function followLinks(array $paths, $excludePatterns) { $finder = new Finder(); $finder->directories(); foreach ($excludePatterns as $excludePattern) { if (substr($excludePattern, 0, 1) == '/') { $excludePattern = substr($excludePattern, 1); } $excludePattern = '/' . preg_quote($excludePattern, '/') . '/'; $excludePattern = str_replace(preg_quote('*', '/'), '.*', $excludePattern); $finder->notPath($excludePattern); } foreach ($paths as $p) { $finder->in($p); } foreach ($finder as $i) { if ($i->isLink()) { $realPath = $i->getRealPath(); foreach ($paths as $k => $p2) { if (substr($realPath, 0, strlen($p2) + 1) == $p2 . '/') { continue 2; } } $paths[] = $realPath; } } return $paths; }
/** * @return array */ public function findFiles() { $files = array(); $finder = new Finder(); $iterate = false; $finder->ignoreUnreadableDirs(); foreach ($this->items as $item) { if (!is_file($item)) { $finder->in($item); $iterate = true; } else { $files[] = realpath($item); } } foreach ($this->excludes as $exclude) { $finder->exclude($exclude); } foreach ($this->names as $name) { $finder->name($name); } foreach ($this->notNames as $notName) { $finder->notName($notName); } foreach ($this->regularExpressionsExcludes as $regularExpressionExclude) { $finder->notPath($regularExpressionExclude); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; }
/** * TYPO3 has a file called LocalConfiguration.php or localconf.php that can be used to search for working installations * * @param Finder $finder finder instance to append the criteria * * @return Finder */ public function appendDetectionCriteria(Finder $finder) { $finder->name('LocalConfiguration.php'); $finder->name('localconf.php'); // always skip typo3temp as it may contain leftovers from functional tests $finder->notPath('typo3temp'); return $finder; }
/** * Action for Add an ignore pattern. * * @param string $pattern The pattern */ public function doAddPattern($pattern) { if (0 === strpos($pattern, '!')) { $this->finder->notPath(Glob::toRegex(substr($pattern, 1), true, false)); } else { $this->finder->path(Glob::toRegex($pattern, true, false)); } }
/** * Step2: Converter pattern to glob. * * @param string $prefix The prefix * @param string $searchPattern The search pattern * @param string $pattern The pattern */ protected function convertPatternStep2($prefix, $searchPattern, $pattern) { if ('.*' === $searchPattern) { $this->doAddPattern($prefix . '**/.*'); } elseif ('**' === $searchPattern) { $this->finder->path('/.*/'); $this->finder->notPath('/^\\..*(?!\\/)/'); } elseif (preg_match('/\\/\\*$|\\/\\*\\*$/', $pattern, $matches)) { $this->doAddPattern(substr($pattern, 0, strlen($pattern) - strlen($matches[0]))); } }
public function getFiles() { $files = new Finder(); $files->files()->in(realpath($this->path)); foreach ($this->excludes as $exclude) { $files->notPath($exclude); } foreach ($this->extensions as $extension) { $files->name('*.' . $extension); } return iterator_to_array($files); }
public function getItems(array $include, array $exclude) { $finder = new Finder(); $finder->in($this->getRootPath()); foreach ($include as $path) { $finder->path($this->normalizePath($path)); } foreach ($exclude as $path) { $finder->notPath($this->normalizePath($path)); } $items = []; foreach ($finder as $resource) { $items[] = $this->loadItem($resource); } return $items; }
/** * Returns a Finder instance for the files that will be included in the * backup. * * By default we ignore unreadable files and directories as well as, common * version control folders / files, "Dot" files and anything matching the * exclude rules. * * @uses Finder * @return Finder The Finder iterator of all files to be included */ public function get_files() { $finder = new Finder(); $finder->followLinks(true); $finder->ignoreDotFiles(false); $finder->ignoreVCS(true); $finder->ignoreUnreadableDirs(true); // Skip unreadable files too $finder->filter(function (\SplFileInfo $file) { if (!$file->isReadable()) { return false; } }); // Finder expects exclude rules to be in a regex format $exclude_rules = $this->excludes->get_excludes_for_regex(); // Skips folders/files that match default exclude patterns foreach ($exclude_rules as $exclude) { $finder->notPath($exclude); } return $finder->in(Path::get_root()); }
/** * @param InputInterface $input * @return Finder */ public function createFinder(InputInterface $input) { $finder = new Finder(); $finder->files(); foreach ($input->getArgument('directory') as $dir) { $finder->in($dir); } foreach ($input->getOption('not-dir') as $ignoreDir) { $finder->exclude($ignoreDir); } foreach ($input->getOption('file-name') as $pattern) { $finder->name($pattern); } foreach ($input->getOption('not-file-name') as $pattern) { $finder->notName($pattern); } foreach ($input->getOption('contains') as $pattern) { $finder->contains($pattern); } foreach ($input->getOption('not-contains') as $pattern) { $finder->notContains($pattern); } foreach ($input->getOption('path') as $pattern) { $finder->path($pattern); } foreach ($input->getOption('not-path') as $pattern) { $finder->notPath($pattern); } if ($size = $input->getOption('size')) { $finder->size($size); } if ($modified = $input->getOption('modified')) { $finder->date($modified); } if ($depth = $input->getOption('depth')) { $finder->depth($depth); } return $finder; }
/** * @param string $root * @param string $virtualHost * @param array $settings * @param string|null $repository * @return Finder */ protected function getRepositoryFinder($root, $virtualHost, array $settings, $repository = null) { $root = rtrim($root, '/\\'); $virtualHost = trim($virtualHost, '/\\'); $absolutePath = $root . DIRECTORY_SEPARATOR . $virtualHost; if (!@is_dir($absolutePath)) { throw new \InvalidArgumentException('Wrong path provided', 1456264866695); } if (!isset($settings['default']['show']['depth'])) { throw new \InvalidArgumentException('Missing default repository configuration', 1456425560002); } $depth = $settings['default']['show']['depth']; if (isset($settings[$virtualHost]['show']['depth'])) { $depth = $settings[$virtualHost]['show']['depth']; } $finder = new Finder(); $finder->directories()->ignoreUnreadableDirs(true)->ignoreDotFiles(false)->ignoreVCS(false)->followLinks()->name('.git')->depth($depth)->sort(function (SplFileInfo $a, SplFileInfo $b) { return strcmp($a->getRelativePathname(), $b->getRelativePathname()); })->in($absolutePath); $excludeDirs = null; if (isset($settings['default']['show']['exclude'])) { $excludeDirs = $settings['default']['show']['exclude']; } if (isset($settings[$virtualHost]['show']['exclude'])) { $excludeDirs = $settings[$virtualHost]['show']['exclude']; } if (!empty($excludeDirs) && is_array($excludeDirs)) { foreach ($excludeDirs as $dir) { $finder->notPath(strtr($dir, '\\', '/')); } } if ($repository) { $repository = trim($repository, '/\\'); $absolutePath .= DIRECTORY_SEPARATOR . $repository; if (!@is_dir($absolutePath)) { throw new \InvalidArgumentException('Wrong repository path provided', 1456433944431); } $finder->depth(0)->in($absolutePath); if (count($finder) !== 1) { throw new \RuntimeException('Unexpected repository count found', 1456433999553); } } return $finder; }
/** * Build a Symfony Finder object that scans the given $directory. * * @param string|array|Finder $directory The directory(s) or filename(s) * @param null|string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths) * @throws InvalidArgumentException */ public static function finder($directory, $exclude = null) { if ($directory instanceof Finder) { return $directory; } else { $finder = new Finder(); $finder->sortByName(); } $finder->files(); if (is_string($directory)) { if (is_file($directory)) { // Scan a single file? $finder->append([$directory]); } else { // Scan a directory $finder->in($directory); } } elseif (is_array($directory)) { foreach ($directory as $path) { if (is_file($path)) { // Scan a file? $finder->append([$path]); } else { $finder->in($path); } } } else { throw new InvalidArgumentException('Unexpected $directory value:' . gettype($directory)); } if ($exclude !== null) { if (is_string($exclude)) { $finder->notPath(Util::getRelativePath($exclude, $directory)); } elseif (is_array($exclude)) { foreach ($exclude as $path) { $finder->notPath(Util::getRelativePath($path, $directory)); } } else { throw new InvalidArgumentException('Unexpected $exclude value:' . gettype($exclude)); } } return $finder; }
/** * @return Finder */ public function getSysFiles() { $finder = new Finder(); $sysPath = $this->getSysPath(); $finder->files()->in($sysPath); $finder->notPath('vendor'); $finder->notPath('tests'); return $finder; }
/** * Copy the rest files to destination * * @return array Filenames affected */ public function copyRestToDestination() { $fs = new Filesystem(); $result = array(); $includedFiles = array(); $dir = $this->getSourceDir(); $include = $this->configuration->getRepository()->get('include'); $exclude = $this->configuration->getRepository()->get('exclude'); $processableExt = $this->getProcessableExtention(); $finder = new Finder(); $finder->in($dir)->exclude($this->getSpecialDir()); $finder->notName($this->configuration->getConfigFilename()); $finder->notName($this->configuration->getConfigEnvironmentFilenameWildcard()); $finder->notName($this->fileExtToRegExpr($processableExt)); foreach ($include as $item) { if (is_dir($item)) { $finder->in($item); } else { if (is_file($item) && !in_array(pathinfo($item, PATHINFO_EXTENSION), $processableExt)) { $includedFiles[] = new SplFileInfo($this->resolvePath($item), "", pathinfo($item, PATHINFO_BASENAME)); } } } foreach ($exclude as $item) { $finder->notPath($item); } $finder->append($includedFiles); foreach ($finder as $file) { if ($file->isDir()) { $this->mkDirIfNotExists($this->getDestinationDir() . '/' . $file->getRelativePath()); } else { if ($file->isFile()) { $result[] = $file->getRealpath(); $fs->copy($file->getRealpath(), $this->getDestinationDir() . '/' . $file->getRelativePathname()); } } } return $result; }
/** * Get a list of plugin files. * * @param Finder $finder The finder to use, can be pre-configured * * @return array Of files */ public function getFiles(Finder $finder) { $finder->files()->in($this->directory)->ignoreUnreadableDirs(); // Ignore third party libraries. foreach ($this->getThirdPartyLibraryPaths() as $libPath) { $finder->notPath($libPath); } // Extra ignores for CI. $ignores = $this->getIgnores(); if (!empty($ignores['notPaths'])) { foreach ($ignores['notPaths'] as $notPath) { $finder->notPath($notPath); } } if (!empty($ignores['notNames'])) { foreach ($ignores['notNames'] as $notName) { $finder->notName($notName); } } $files = []; foreach ($finder as $file) { /* @var \SplFileInfo $file */ $files[] = $file->getRealpath(); } return $files; }
private function processContentFiles() { $includedFiles = []; $finder = new Finder(); $finder->in($this->composeSubPath('content'))->notName('*.meta')->files(); foreach ($this->params['include'] as $item) { if (is_dir($item)) { $finder->in($item); } elseif (is_file($item)) { $includedFiles[] = new SplFileInfo($item, '', pathinfo($item, PATHINFO_BASENAME)); } } $finder->append($includedFiles); foreach ($this->params['exclude'] as $item) { $finder->notPath($item); } $this->processItems($finder, Item::TYPE_ITEM); }
/** * Get the locale that is used in the Frontend but doesn't exists. * * @param string $language The language to check. * @return array */ public static function getNonExistingFrontendLocale($language) { $locale = array(); $frontendModuleFiles = array(); $installedModules = BackendModel::getModules(); // pickup the Frontend module files $finder = new Finder(); $finder->notPath('Cache')->name('*.php')->name('*.tpl')->name('*.js'); // collect all files foreach ($finder->files()->in(FRONTEND_PATH) as $file) { // returns false if nothing found $module = self::getInbetweenStrings('Modules/', '/', $file->getPath()); if ($module && !in_array($module, $installedModules)) { continue; } $filename = $file->getPath() . '/' . $file->getFilename(); $frontendModuleFiles['Core'][$filename] = $file; } // Find the locale in files an sort them foreach ($frontendModuleFiles as $moduleName => $module) { $locale[$moduleName] = self::findLocaleInFiles($module); } // getAllFrontendDBLocale $oldLocale = self::getSortLocaleFrom('Frontend', $language); // filter the Foundlocale $nonExisting = array(); foreach ($locale as $moduleName => &$module) { foreach ($module as $filename => &$file) { // extra filter for Core $file['locale'] = array_diff_key($file['locale'], $oldLocale['Core']); // output a converted array foreach ($file['locale'] as $localeName => $localeType) { $key = $localeName; $type = $localeType; $nonExisting['Frontend' . $key . $type . $moduleName] = array('language' => $language, 'application' => 'Frontend', 'module' => $moduleName, 'type' => $type, 'name' => $key, 'used_in' => serialize($file['file'])); } } } ksort($nonExisting); return $nonExisting; }
/** * @return array|\Iterator */ public function getConfigFiles() { try { $f = new Finder(); $f->name('*.xml.skeleton'); $f->name('*.yml.skeleton'); $f->notName('*.orm.xml.skeleton'); $f->notName('*.orm.yml.skeleton'); $f->notPath('doctrine/'); $f->notPath('serializer/'); $f->in($this->getMappingConfigDirectory()); return $f->getIterator(); } catch (\Exception $e) { return array(); } }
/** * @return Finder */ public function notPath($pattern) { return parent::notPath($pattern); }
/** * generate classes from given namespace/entity, using given srcDir (or default one) * into given destDir (or default one) * * @param string $namespace * @param string $entity * @param string $skeletonsPath * @param string $targetPath * @param array $excludedSkeletons */ public function generate($namespace, $entity, $skeletonsPath = null, $targetPath = null, array $excludedSkeletons) { $skeletonsPath = $skeletonsPath ?: $this->skeletonsPath; $targetPath = $targetPath ?: $this->targetPath; $finder = new Finder(); $inflector = new Inflector(array('MajoraEntity' => $entity, 'MajoraNamespace' => $namespace)); $modifiersStack = array(); // create file tree $finder->in($skeletonsPath); array_map(function ($excludedSkeleton) use($finder) { $finder->notPath($excludedSkeleton); }, $excludedSkeletons); foreach ($finder as $templateFile) { $generatedFile = new SplFileInfo($generatedFilePath = $this->generatePath($templateFile, realpath($skeletonsPath), realpath($targetPath), $inflector), '', ''); // directory --------------------------------------------------------- if ($templateFile->isDir()) { $this->generateDir($generatedFilePath); continue; } // file -------------------------------------------------------------- $fileContent = $inflector->translate($templateFile->getContents()); // always read template file metadata $metadata = $this->getMetadata($fileContent); $forceGeneration = !empty($metadata['force_generation']); unset($metadata['force_generation']); $modifyContent = count($metadata); $alreadyGenerated = $this->filesystem->exists($generatedFilePath); // contents needs to be updated ? if ($alreadyGenerated && $modifyContent) { $fileContent = $generatedFile->getContents(); } // stack content modifiers $modifiersStack[] = array(array($this, 'modify'), array($generatedFile, $templateFile, $metadata, $inflector)); // have to touch existing file ? if ($alreadyGenerated && !$forceGeneration) { continue; } $this->filesystem->dumpFile($generatedFilePath, $fileContent); $this->logger->info(sprintf('file %s : %s', $forceGeneration ? 'forced' : 'created', $generatedFilePath)); } // unstack all modifiers foreach ($modifiersStack as $modifierCallback) { call_user_func_array($modifierCallback[0], $modifierCallback[1]); } }
/** * Apply configuration to finder * * @param Finder $finder */ public function apply(Finder $finder) { $finder->exclude($this->excludeDirs); foreach ($this->excludePaths as $pattern) { $finder->notPath($pattern); } foreach ($this->excludeFiles as $pattern) { $finder->notName($pattern); } $finder->in($this->includeDirs); foreach ($this->includePaths as $pattern) { $finder->path($pattern); } foreach ($this->includeFiles as $pattern) { $finder->name($pattern); } }
/** * Get files from directory. * * @param string $dir * * @return array */ protected function getFilesFromDir($dir) { $finder = new Finder(); $finder->files()->ignoreUnreadableDirs()->in(realpath($dir)); foreach ($this->excludes as $exclude) { $finder->notPath($exclude); } foreach ($this->extensions as $extension) { $finder->name('*.' . $extension); } return iterator_to_array($finder); }
/** * Get the locale that is used in the frontend but doesn't exists. * * @param string $language The language to check. * @return array */ public static function getNonExistingFrontendLocale($language) { $used = array(); $finder = new Finder(); $finder->notPath('cache')->name('*.php')->name('*.tpl')->name('*.js'); // loop files foreach ($finder->files()->in(FRONTEND_PATH) as $file) { /** @var $file \SplFileInfo */ // grab content $content = $file->getContents(); // process the file based on extension switch ($file->getExtension()) { // javascript file case 'js': $matches = array(); // get matches preg_match_all('/\\{\\$(act|err|lbl|msg)(.*)(\\|.*)?\\}/iU', $content, $matches); // any matches? if (isset($matches[2])) { // loop matches foreach ($matches[2] as $key => $match) { // set type $type = $matches[1][$key]; // init if needed if (!isset($used[$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file->getRealPath(); } } } break; // PHP file // PHP file case 'php': $matches = array(); // get matches preg_match_all('/(FrontendLanguage|FL)::(get(Action|Label|Error|Message)|act|lbl|err|msg)\\(\'(.*)\'\\)/iU', $content, $matches); // any matches? if (!empty($matches[4])) { // loop matches foreach ($matches[4] as $key => $match) { $type = 'lbl'; if ($matches[3][$key] == 'Action') { $type = 'act'; } if ($matches[2][$key] == 'act') { $type = 'act'; } if ($matches[3][$key] == 'Error') { $type = 'err'; } if ($matches[2][$key] == 'err') { $type = 'err'; } if ($matches[3][$key] == 'Message') { $type = 'msg'; } if ($matches[2][$key] == 'msg') { $type = 'msg'; } // init if needed if (!isset($used[$type][$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file->getRealPath(); } } } break; // template file // template file case 'tpl': $matches = array(); // get matches preg_match_all('/\\{\\$(act|err|lbl|msg)([a-z-_]*)(\\|.*)?\\}/iU', $content, $matches); // any matches? if (isset($matches[2])) { // loop matches foreach ($matches[2] as $key => $match) { // set type $type = $matches[1][$key]; // init if needed if (!isset($used[$type][$match])) { $used[$type][$match] = array('files' => array()); } // add file if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) { $used[$type][$match]['files'][] = $file->getRealPath(); } } } break; } } // init var $nonExisting = array(); // set language FL::setLocale($language); // check if the locale is present in the current language foreach ($used as $type => $items) { // loop items foreach ($items as $key => $data) { // process based on type switch ($type) { case 'act': // if the action isn't available add it to the list if (FL::act($key, false) == '{$' . $type . $key . '}') { $nonExisting['Frontend' . $key . $type] = array('language' => $language, 'application' => 'Frontend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'err': // if the error isn't available add it to the list if (FL::err($key, false) == '{$' . $type . $key . '}') { $nonExisting['Frontend' . $key . $type] = array('language' => $language, 'application' => 'Frontend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'lbl': // if the label isn't available add it to the list if (FL::lbl($key, false) == '{$' . $type . $key . '}') { $nonExisting['Frontend' . $key . $type] = array('language' => $language, 'application' => 'Frontend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; case 'msg': // if the message isn't available add it to the list if (FL::msg($key, false) == '{$' . $type . $key . '}') { $nonExisting['Frontend' . $key . $type] = array('language' => $language, 'application' => 'Frontend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files'])); } break; } } } ksort($nonExisting); return $nonExisting; }
/** * Build a Symfony2 Finder instance that searches all included paths for files. * * The local config instance will be queried for included and excluded files and the Finder will be populated with * them. * * @return Finder */ protected function buildFinder() { $finder = new Finder(); $finder->in($this->config->getIncludedPaths())->notPath('/vendor/')->files(); foreach ($this->config->getExcludedPaths() as $excluded) { $finder->notPath($excluded); } return $finder; }
/** * Return the single depth list of files and subdirectories in $directory ordered by total filesize * * Will schedule background threads to recursively calculate the filesize of subdirectories. * The total filesize of each directory and subdirectory is cached in a transient for 1 week. * * @param string $directory The directory to scan * * @return array returns an array of files ordered by filesize */ public function list_directory_by_total_filesize($directory) { $files = $files_with_no_size = $empty_files = $files_with_size = $unreadable_files = array(); if (!is_dir($directory)) { return $files; } $found = array(); if (!empty($this->files)) { return $this->files; } $default_excludes = $this->backup->default_excludes(); $finder = new Finder(); $finder->ignoreDotFiles(false); $finder->ignoreUnreadableDirs(); $finder->followLinks(); $finder->depth('== 0'); foreach ($default_excludes as $exclude) { $finder->notPath($exclude); } foreach ($finder->in($directory) as $entry) { $files[] = $entry; // Get the total filesize for each file and directory $filesize = $this->filesize($entry); if ($filesize) { // If there is already a file with exactly the same filesize then let's keep increasing the filesize of this one until we don't have a clash while (array_key_exists($filesize, $files_with_size)) { $filesize++; } $files_with_size[$filesize] = $entry; } elseif (0 === $filesize) { $empty_files[] = $entry; } else { $files_with_no_size[] = $entry; } } // Add 0 byte files / directories to the bottom $files = $files_with_size + array_merge($empty_files, $unreadable_files); // Add directories that are still calculating to the top if ($files_with_no_size) { // We have to loop as merging or concatenating the array would re-flow the keys which we don't want because the filesize is stored in the key foreach ($files_with_no_size as $entry) { array_unshift($files, $entry); } } return $files; }
/** * Return an array of all files in the filesystem. * * @param bool $ignore_default_exclude_rules If true then will return all files under root. Otherwise returns all files except those matching default exclude rules. * * @return array */ public function get_files($ignore_default_exclude_rules = false) { $found = array(); if (!empty($this->files)) { return $this->files; } $finder = new Finder(); $finder->followLinks(); $finder->ignoreDotFiles(false); $finder->ignoreUnreadableDirs(); if (!$ignore_default_exclude_rules) { // Skips folders/files that match default exclude patterns foreach ($this->default_excludes() as $exclude) { $finder->notPath($exclude); } } foreach ($finder->in($this->get_root()) as $entry) { $this->files[] = $entry; } return $this->files; }
/** * Return an array of all files in the filesystem * * @return \RecursiveIteratorIterator */ public function get_files() { $found = array(); if (!empty($this->files)) { return $this->files; } $finder = new Finder(); $finder->followLinks(); $finder->ignoreDotFiles(false); $finder->ignoreUnreadableDirs(); foreach ($this->default_excludes() as $exclude) { $finder->notPath($exclude); } foreach ($finder->in($this->get_root()) as $entry) { $this->files[] = $entry; } return $this->files; }
$directoryIterator = $directoryFinder->in($path->path); $directoryArray = array(); foreach ($directoryIterator as $directory) { $directoryArray[] = array("path" => $directory->getRelativePathname(), "name" => $directory->getBasename()); } $fileFinder = new Finder(); $fileFinder->files()->ignoreUnreadableDirs()->depth(0); $allowedImageTypes = loadPicFile("helpers/imagetypes.php"); foreach ($allowedImageTypes as $imageType) { $fileFinder->name("*.{$imageType}"); } foreach (array_map("strtoupper", $allowedImageTypes) as $imageType) { $fileFinder->name("*.{$imageType}"); } $fileFinder->sortByName(); if ($path->hasPermission("symlinks")) { $fileFinder->followLinks(); } if (!empty($relpath)) { $fileFinder->path($relpath)->depth(substr_count($relpath, "/") + 1); } if ($path->hasPermission("nsfw") === false) { $fileFinder->notPath("/.*\\/NSFW\\/.*/")->notPath("/NSFW\\/.*/")->notPath("/.*\\/NSFW/"); } $fileIterator = $fileFinder->in($path->path); $fileArray = array(); foreach ($fileIterator as $file) { $fileArray[] = array("filename" => $file->getBasename(), "relpath" => $file->getRelativePathname(), "size" => humanFilesize($file->getSize()), "mtime" => date("Y-m-d H:i:s", $file->getMTime())); } header("Content-type: application/json"); echo json_encode(array("directories" => $directoryArray, "files" => $fileArray));