Skip to content

Commit

Permalink
[ticket/16955] Use common code for path iterator generation
Browse files Browse the repository at this point in the history
PHPBB3-16955
  • Loading branch information
marc1706 committed Dec 28, 2022
1 parent 8faabb5 commit 9a546c5
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion phpBB/develop/export_events_for_bbcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function validate_argument_count($arguments, $count)
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
require __DIR__ . '/../includes/functions.' . $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)
{
Expand Down
2 changes: 1 addition & 1 deletion phpBB/develop/export_events_for_rst.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function validate_argument_count($arguments, $count)
require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx;
require __DIR__ . '/../includes/functions.' . $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)
{
Expand Down
2 changes: 1 addition & 1 deletion phpBB/develop/export_events_for_wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function validate_argument_count($arguments, $count)
require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx;
require __DIR__ . '/../includes/functions.' . $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)
{
Expand Down
11 changes: 1 addition & 10 deletions phpBB/includes/acp/acp_language.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,7 @@ public function main($id, $mode)
{
try
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
$this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/',
\FilesystemIterator::SKIP_DOTS
)
),
\RecursiveIteratorIterator::LEAVES_ONLY
);
$iterator = new \phpbb\iterator\recursive_path_iterator($this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/');
}
catch (\Exception $e)
{
Expand All @@ -237,7 +229,6 @@ public function main($id, $mode)

foreach ($iterator as $file_info)
{
/** @var \RecursiveDirectoryIterator $file_info */
$relative_path = $iterator->getInnerIterator()->getSubPathname();
$relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);

Expand Down
12 changes: 4 additions & 8 deletions phpBB/includes/functions_compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,10 @@ function phpbb_email_hash($email)
*/
function phpbb_load_extensions_autoloaders($phpbb_root_path)
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
$phpbb_root_path . 'ext/',
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
)
),
\RecursiveIteratorIterator::SELF_FIRST
$iterator = new \phpbb\iterator\recursive_path_iterator(
$phpbb_root_path . 'ext/',
\RecursiveIteratorIterator::SELF_FIRST,
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
);
$iterator->setMaxDepth(2);

Expand Down
9 changes: 2 additions & 7 deletions phpBB/phpbb/event/md_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,8 @@ public function get_recursive_file_list($dir)
{
try
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
$dir,
\FilesystemIterator::SKIP_DOTS
)
),
$iterator = new \phpbb\iterator\recursive_path_iterator(
$dir,
\RecursiveIteratorIterator::SELF_FIRST
);
}
Expand Down
9 changes: 4 additions & 5 deletions phpBB/phpbb/extension/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ public function all_available()
return $available;
}

$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS)
),
\RecursiveIteratorIterator::SELF_FIRST
$iterator = new \phpbb\iterator\recursive_path_iterator(
$this->phpbb_root_path . 'ext/',
\RecursiveIteratorIterator::SELF_FIRST,
\FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS
);
$iterator->setMaxDepth(2);

Expand Down
9 changes: 2 additions & 7 deletions phpBB/phpbb/finder/finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,8 @@ public function find_from_paths($extensions, $cache = true, $is_dir = false)

if (is_dir($path))
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
$path,
\FilesystemIterator::SKIP_DOTS
)
),
$iterator = new \phpbb\iterator\recursive_path_iterator(
$path,
\RecursiveIteratorIterator::SELF_FIRST
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
*/

namespace phpbb;
namespace phpbb\iterator;

/**
* Class recursive_dot_prefix_filter_iterator
Expand Down
47 changes: 47 additions & 0 deletions phpBB/phpbb/iterator/recursive_path_iterator.php
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 9a546c5

Please sign in to comment.