mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16955] Use common code for path iterator generation
PHPBB3-16955
This commit is contained in:
parent
8faabb559d
commit
9a546c535c
10 changed files with 64 additions and 41 deletions
|
@ -65,7 +65,7 @@ require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../includes/functions.' . $phpEx;
|
require __DIR__ . '/../includes/functions.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
||||||
|
|
||||||
switch ($action)
|
switch ($action)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,7 +68,7 @@ require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../includes/functions.' . $phpEx;
|
require __DIR__ . '/../includes/functions.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
||||||
|
|
||||||
switch ($action)
|
switch ($action)
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,7 +67,7 @@ require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx;
|
||||||
require __DIR__ . '/../includes/functions.' . $phpEx;
|
require __DIR__ . '/../includes/functions.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx;
|
||||||
require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx;
|
||||||
|
|
||||||
switch ($action)
|
switch ($action)
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,15 +220,7 @@ class acp_language
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \phpbb\iterator\recursive_path_iterator($this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/');
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
|
||||||
new \RecursiveDirectoryIterator(
|
|
||||||
$this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/',
|
|
||||||
\FilesystemIterator::SKIP_DOTS
|
|
||||||
)
|
|
||||||
),
|
|
||||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -237,7 +229,6 @@ class acp_language
|
||||||
|
|
||||||
foreach ($iterator as $file_info)
|
foreach ($iterator as $file_info)
|
||||||
{
|
{
|
||||||
/** @var \RecursiveDirectoryIterator $file_info */
|
|
||||||
$relative_path = $iterator->getInnerIterator()->getSubPathname();
|
$relative_path = $iterator->getInnerIterator()->getSubPathname();
|
||||||
$relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
|
$relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
|
||||||
|
|
||||||
|
|
|
@ -646,14 +646,10 @@ function phpbb_email_hash($email)
|
||||||
*/
|
*/
|
||||||
function phpbb_load_extensions_autoloaders($phpbb_root_path)
|
function phpbb_load_extensions_autoloaders($phpbb_root_path)
|
||||||
{
|
{
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \phpbb\iterator\recursive_path_iterator(
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
|
||||||
new \RecursiveDirectoryIterator(
|
|
||||||
$phpbb_root_path . 'ext/',
|
$phpbb_root_path . 'ext/',
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST,
|
||||||
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
|
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
|
||||||
)
|
|
||||||
),
|
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
|
||||||
);
|
);
|
||||||
$iterator->setMaxDepth(2);
|
$iterator->setMaxDepth(2);
|
||||||
|
|
||||||
|
|
|
@ -658,13 +658,8 @@ class md_exporter
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \phpbb\iterator\recursive_path_iterator(
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
|
||||||
new \RecursiveDirectoryIterator(
|
|
||||||
$dir,
|
$dir,
|
||||||
\FilesystemIterator::SKIP_DOTS
|
|
||||||
)
|
|
||||||
),
|
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
\RecursiveIteratorIterator::SELF_FIRST
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,11 +380,10 @@ class manager
|
||||||
return $available;
|
return $available;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \phpbb\iterator\recursive_path_iterator(
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
$this->phpbb_root_path . 'ext/',
|
||||||
new \RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS)
|
\RecursiveIteratorIterator::SELF_FIRST,
|
||||||
),
|
\FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
|
||||||
);
|
);
|
||||||
$iterator->setMaxDepth(2);
|
$iterator->setMaxDepth(2);
|
||||||
|
|
||||||
|
|
|
@ -486,13 +486,8 @@ class finder
|
||||||
|
|
||||||
if (is_dir($path))
|
if (is_dir($path))
|
||||||
{
|
{
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \phpbb\iterator\recursive_path_iterator(
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
|
||||||
new \RecursiveDirectoryIterator(
|
|
||||||
$path,
|
$path,
|
||||||
\FilesystemIterator::SKIP_DOTS
|
|
||||||
)
|
|
||||||
),
|
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
\RecursiveIteratorIterator::SELF_FIRST
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpbb;
|
namespace phpbb\iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class recursive_dot_prefix_filter_iterator
|
* Class recursive_dot_prefix_filter_iterator
|
47
phpBB/phpbb/iterator/recursive_path_iterator.php
Normal file
47
phpBB/phpbb/iterator/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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue