mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/16955] Move iterators to finder folder
PHPBB3-16955
This commit is contained in:
59
phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php
Normal file
59
phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\iterator;
|
||||
|
||||
/**
|
||||
* Class recursive_dot_prefix_filter_iterator
|
||||
*
|
||||
* This filter ignores directories starting with a dot.
|
||||
* When searching for php classes and template files of extensions
|
||||
* we don't need to look inside these directories.
|
||||
*/
|
||||
class recursive_dot_prefix_filter_iterator extends \RecursiveFilterIterator
|
||||
{
|
||||
/**
|
||||
* Check whether the current element of the iterator is acceptable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function accept(): bool
|
||||
{
|
||||
$filename = $this->current()->getFilename();
|
||||
return $filename[0] !== '.' || !$this->current()->isDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sub path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubPath(): string
|
||||
{
|
||||
$directory_iterator = $this->getInnerIterator();
|
||||
assert($directory_iterator instanceof \RecursiveDirectoryIterator);
|
||||
return $directory_iterator->getSubPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sub path and name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubPathname(): string
|
||||
{
|
||||
$directory_iterator = $this->getInnerIterator();
|
||||
assert($directory_iterator instanceof \RecursiveDirectoryIterator);
|
||||
return $directory_iterator->getSubPathname();
|
||||
}
|
||||
}
|
47
phpBB/phpbb/finder/recursive_path_iterator.php
Normal file
47
phpBB/phpbb/finder/recursive_path_iterator.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpbb\iterator;
|
||||
|
||||
class recursive_path_iterator extends \RecursiveIteratorIterator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $path Path to iterate over
|
||||
* @param int $mode Iterator mode
|
||||
* @param int $flags Flags
|
||||
*/
|
||||
public function __construct(string $path, int $mode = self::LEAVES_ONLY, int $flags = \FilesystemIterator::SKIP_DOTS)
|
||||
{
|
||||
parent::__construct(
|
||||
new recursive_dot_prefix_filter_iterator(new \RecursiveDirectoryIterator($path, $flags)),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get inner iterator
|
||||
*
|
||||
* @return recursive_dot_prefix_filter_iterator
|
||||
*/
|
||||
public function getInnerIterator(): \RecursiveIterator
|
||||
{
|
||||
$inner_iterator = parent::getInnerIterator();
|
||||
|
||||
assert($inner_iterator instanceof recursive_dot_prefix_filter_iterator);
|
||||
return $inner_iterator;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user