本文整理汇总了PHP中Symfony\Component\Finder\Finder::ignoreUnreadableDirs方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::ignoreUnreadableDirs方法的具体用法?PHP Finder::ignoreUnreadableDirs怎么用?PHP Finder::ignoreUnreadableDirs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::ignoreUnreadableDirs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: searchString
/**
* @inheritdoc
*/
public function searchString($stringToSearch, $searchFolder)
{
$this->finder = $this->finderFactory->create();
$result = new FileSearchResult($searchFolder);
$this->finder->ignoreUnreadableDirs()->in($searchFolder);
foreach ($this->finder->files()->contains($stringToSearch) as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
$fileLocation = new FileLocation();
$fileLocation->setFolder($file->getPath());
$fileLocation->setName($file->getFilename());
$fileLocation->setExtension($file->getExtension());
$result->add($fileLocation);
}
return $result;
}
示例2: installAdapters
/**
* Install external adapters
* @return void
* @throws Exception
*/
private function installAdapters(AdaptersEvent $event)
{
$fs = new Filesystem();
$finder = new Finder();
try {
$pluginsDir = __DIR__ . '/../../../';
$iterator = $finder->ignoreUnreadableDirs()->files()->name('*Adapter.php')->in($pluginsDir . '*/*/Adapter/PaywallAdapters/')->in(__DIR__ . '/../Adapter/');
foreach ($iterator as $file) {
$classNamespace = str_replace(realpath($pluginsDir), '', substr($file->getRealPath(), 0, -4));
$namespace = str_replace('/', '\\', $classNamespace);
$adapterName = substr($file->getFilename(), 0, -4);
$oneAdapter = $this->em->getRepository('Newscoop\\PaywallBundle\\Entity\\Settings')->findOneBy(array('value' => $adapterName));
$event->registerAdapter($adapterName, array('class' => $namespace));
if (!$oneAdapter) {
$adapter = new Settings();
$adapter->setName(str_replace("Adapter.php", "", $file->getFilename()));
$adapter->setValue($adapterName);
if ($adapterName !== 'PaypalAdapter') {
$adapter->setIsActive(false);
}
$this->em->persist($adapter);
}
}
$this->em->flush();
} catch (\Exception $e) {
}
}
示例3: findFiles
/**
* @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;
}
示例4: generatedirList
public function generatedirList()
{
$path = $this->container->getParameter('kernel.root_dir') . "/../";
$finder = new Finder();
$iterator = $finder->ignoreUnreadableDirs()->directories()->depth('< 2')->in($path);
$dirList = array();
foreach ($iterator as $key => $value) {
$dirList["{$value}"] = "{$value}";
}
return $dirList;
}
示例5: clear
public function clear()
{
#ToDO prueba de concepto sacar a un servicio
$manager = $this->orphanManager->get('gallery');
$fs = new Filesystem();
$finder = new Finder();
if ($fs->exists($this->config['directory'] . '/' . $this->session->getId())) {
$files = $finder->ignoreUnreadableDirs()->in($this->config['directory'] . '/' . $this->session->getId());
$fs->remove($files);
}
}
示例6: generateDirsList
/**
* Function that generates the directories list
* which is used to fill the drop down options for Search Path
*
* @return array
*/
public function generateDirsList()
{
$path = $this->get('kernel')->getRootDir();
$finder = new Finder();
$iterator = $finder->ignoreUnreadableDirs()->directories()->depth('< 2')->in($path);
$dirsList = array();
foreach ($iterator as $key => $value) {
$dirsList["{$value}"] = "{$value}";
}
return $dirsList;
}
示例7: generateSecret
protected function generateSecret($password)
{
$finder = new Finder();
$root = $this->container->get('kernel')->getRootDir();
$files = $finder->ignoreUnreadableDirs()->in($root . 'key/')->files()->name('uipubkey.pem');
foreach ($files as $file) {
$private_key_text = $file->getContent();
break;
}
if (!$private_key_text) {
throw new FileNotFoundException('Encryption key not found');
}
$rsa = new RSA();
$rsa->loadKey($private_key_text);
return base64_encode($rsa->encrypt($password));
}
示例8: tearDownAfterClass
public static function tearDownAfterClass()
{
$dirs = array();
$finder = new Finder();
//許可がありませんDIR対応
$finder->ignoreUnreadableDirs(true);
$iterator = $finder->in(sys_get_temp_dir())->name('FileController*')->directories();
foreach ($iterator as $dir) {
$dirs[] = $dir->getPathName();
}
foreach ($dirs as $dir) {
// プロセスが掴んでいるためか、確実に削除できない場合がある
try {
$f = new Filesystem();
$f->remove($dir);
} catch (\Exception $e) {
// queit.
}
}
}
示例9: get_files
/**
* 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());
}
示例10: installParsers
/**
* Install external parsers
*
* @return void
*
* @throws Exception
*/
private function installParsers(IngestParsersEvent $event)
{
$fs = new Filesystem();
$finder = new Finder();
try {
$pluginsDir = __DIR__ . '/../../../';
$namespaces = array();
$iterator = $finder->ignoreUnreadableDirs()->files()->name('*Parser.php')->notName('AbstractParser.php')->in(__DIR__ . '/../Parsers/');
try {
$iterator = $iterator->in($pluginsDir . '*/*/Parsers/IngestAdapters/');
} catch (\Exception $e) {
// Catch exception if no such directory exists
}
foreach ($iterator as $file) {
$classNamespace = str_replace(realpath($pluginsDir), '', substr($file->getRealPath(), 0, -4));
$namespace = str_replace('/', '\\', $classNamespace);
$namespaces[] = (string) $namespace;
$parserName = substr($file->getFilename(), 0, -4);
$parser = $this->em->getRepository('Newscoop\\IngestPluginBundle\\Entity\\Parser')->findOneByNamespace($namespace);
$event->registerParser($parserName, array('class' => $namespace));
if (!$parser) {
$parser = new Parser();
}
$parser->setName($namespace::getParserName())->setDescription($namespace::getParserDescription())->setDomain($namespace::getParserDomain())->setRequiresUrl($namespace::getRequiresUrl())->setSectionHandling($namespace::getHandlesSection())->setNamespace($namespace);
$this->em->persist($parser);
}
// Remove parser which we didn't find anymore
$parsersToRemove = $this->em->createQuery('
DELETE FROM Newscoop\\IngestPluginBundle\\Entity\\Parser AS p
WHERE p.namespace NOT IN (:namespaces)
')->setParameter('namespaces', $namespaces)->getResult();
$this->em->flush();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
示例11: recursive_filesize_scanner
/**
* Recursively scans a directory to calculate the total filesize
*
* Locks should be set by the caller with `set_transient( 'hmbkp_directory_filesizes_running', true, HOUR_IN_SECONDS );`
*
* @return array $directory_sizes An array of directory paths => filesize sum of all files in directory
*/
public function recursive_filesize_scanner()
{
/**
* Raise the `memory_limit` and `max_execution time`
*
* Respects the WP_MAX_MEMORY_LIMIT Constant and the `admin_memory_limit`
* filter.
*/
@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
@set_time_limit(0);
// Use the cached array directory sizes if available
$directory_sizes = $this->get_cached_filesizes();
// If we do have it in cache then let's use it and also clear the lock
if (is_array($directory_sizes)) {
delete_transient('hmbkp_directory_filesizes_running');
return $directory_sizes;
}
// If we don't have it cached then we'll need to re-calculate
$finder = new Finder();
$finder->followLinks();
$finder->ignoreDotFiles(false);
$finder->ignoreUnreadableDirs(true);
$files = $finder->in(Path::get_root());
foreach ($files as $file) {
if ($file->isReadable()) {
$directory_sizes[wp_normalize_path($file->getRealpath())] = $file->getSize();
} else {
$directory_sizes[wp_normalize_path($file->getRealpath())] = 0;
}
}
file_put_contents(PATH::get_path() . '/.files', gzcompress(json_encode($directory_sizes)));
// Remove the lock
delete_transient('hmbkp_directory_filesizes_running');
return $directory_sizes;
}
示例12: list_directory_by_total_filesize
/**
* 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;
}
示例13: get_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;
}
示例14: setUmask
/**
* @param string $directoryPath
* @param array $settings
* @param string $virtualHost
*/
protected function setUmask($directoryPath, array $settings, $virtualHost)
{
$fileUmask = !empty($settings[$virtualHost]['umask']['file']) ? $settings[$virtualHost]['umask']['file'] : !empty($settings['default']['umask']['file']) ? $settings['default']['umask']['file'] : 0;
$folderUmask = !empty($settings[$virtualHost]['umask']['folder']) ? $settings[$virtualHost]['umask']['folder'] : (!empty($settings['default']['umask']['folder']) ? $settings['default']['umask']['folder'] : 0);
if (empty($fileUmask) && empty($folderUmask)) {
return;
}
$repositoryFinder = new Finder();
$repositoryFinder->ignoreUnreadableDirs(true)->ignoreDotFiles(false)->ignoreVCS(true)->in($directoryPath);
if (empty($fileUmask)) {
$repositoryFinder->directories();
} elseif (empty($folderUmask)) {
$repositoryFinder->files();
}
/** @var SplFileInfo $repositoryItem */
foreach ($repositoryFinder as $repositoryItem) {
if (!empty($fileUmask) && $repositoryItem->isFile()) {
chmod($repositoryItem->getPathname(), octdec($fileUmask));
} elseif (!empty($folderUmask) && $repositoryItem->isDir()) {
chmod($repositoryItem->getPathname(), octdec($folderUmask));
}
}
}
示例15: ignoreUnreadableDirs
/**
* @return Finder
*/
public function ignoreUnreadableDirs($ignore = true)
{
return parent::ignoreUnreadableDirs($ignore);
}