mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 05:38:52 +00:00
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/12589] Add test searching in a non absolute directory [ticket/12589] Fix tests [ticket/12589] Search directly in $directory if it's an absolute sub-path
This commit is contained in:
commit
93c310f66b
2 changed files with 65 additions and 34 deletions
|
@ -465,6 +465,10 @@ class finder
|
||||||
}
|
}
|
||||||
else if ($directory && $directory[0] === '/')
|
else if ($directory && $directory[0] === '/')
|
||||||
{
|
{
|
||||||
|
if (!$is_dir)
|
||||||
|
{
|
||||||
|
$path .= substr($directory, 1);
|
||||||
|
}
|
||||||
$directory_pattern = '^' . preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#');
|
$directory_pattern = '^' . preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -477,45 +481,56 @@ class finder
|
||||||
}
|
}
|
||||||
$directory_pattern = '#' . $directory_pattern . '#';
|
$directory_pattern = '#' . $directory_pattern . '#';
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
if (is_dir($path))
|
||||||
new \phpbb\recursive_dot_prefix_filter_iterator(
|
|
||||||
new \RecursiveDirectoryIterator(
|
|
||||||
$path,
|
|
||||||
\FilesystemIterator::SKIP_DOTS
|
|
||||||
)
|
|
||||||
),
|
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($iterator as $file_info)
|
|
||||||
{
|
{
|
||||||
$filename = $file_info->getFilename();
|
$iterator = new \RecursiveIteratorIterator(
|
||||||
|
new \phpbb\recursive_dot_prefix_filter_iterator(
|
||||||
|
new \RecursiveDirectoryIterator(
|
||||||
|
$path,
|
||||||
|
\FilesystemIterator::SKIP_DOTS
|
||||||
|
)
|
||||||
|
),
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST
|
||||||
|
);
|
||||||
|
|
||||||
if ($file_info->isDir() == $is_dir)
|
foreach ($iterator as $file_info)
|
||||||
{
|
{
|
||||||
if ($is_dir)
|
$filename = $file_info->getFilename();
|
||||||
{
|
|
||||||
$relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($filename) . DIRECTORY_SEPARATOR;
|
|
||||||
if ($relative_path[0] !== DIRECTORY_SEPARATOR)
|
|
||||||
{
|
|
||||||
$relative_path = DIRECTORY_SEPARATOR . $relative_path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$relative_path = DIRECTORY_SEPARATOR . $iterator->getInnerIterator()->getSubPathname();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) &&
|
if ($file_info->isDir() == $is_dir)
|
||||||
(!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) &&
|
|
||||||
(!$directory || preg_match($directory_pattern, $relative_path)))
|
|
||||||
{
|
{
|
||||||
$files[] = array(
|
if ($is_dir)
|
||||||
'named_path' => str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)),
|
{
|
||||||
'ext_name' => $ext_name,
|
$relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($filename) . DIRECTORY_SEPARATOR;
|
||||||
'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/',
|
if ($relative_path[0] !== DIRECTORY_SEPARATOR)
|
||||||
'filename' => $filename,
|
{
|
||||||
);
|
$relative_path = DIRECTORY_SEPARATOR . $relative_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$relative_path = $iterator->getInnerIterator()->getSubPathname();
|
||||||
|
if ($directory && $directory[0] === '/')
|
||||||
|
{
|
||||||
|
$relative_path = str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR . $relative_path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$relative_path = DIRECTORY_SEPARATOR . $relative_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) &&
|
||||||
|
(!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) &&
|
||||||
|
(!$directory || preg_match($directory_pattern, $relative_path)))
|
||||||
|
{
|
||||||
|
$files[] = array(
|
||||||
|
'named_path' => str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)),
|
||||||
|
'ext_name' => $ext_name,
|
||||||
|
'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/',
|
||||||
|
'filename' => $filename,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,22 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_non_absolute_directory_get_classes()
|
||||||
|
{
|
||||||
|
$classes = $this->finder
|
||||||
|
->directory('type/')
|
||||||
|
->get_classes();
|
||||||
|
|
||||||
|
sort($classes);
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'\vendor2\foo\sub\type\alternative',
|
||||||
|
'\vendor2\foo\type\alternative',
|
||||||
|
),
|
||||||
|
$classes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_sub_directory_get_classes()
|
public function test_sub_directory_get_classes()
|
||||||
{
|
{
|
||||||
$classes = $this->finder
|
$classes = $this->finder
|
||||||
|
|
Loading…
Add table
Reference in a new issue