mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[feature/extension-manager] Add filename prefix matching in extension finder
PHPBB3-10323
This commit is contained in:
parent
60ad0e21b5
commit
f6632fcfd0
2 changed files with 62 additions and 5 deletions
|
@ -50,8 +50,10 @@ class phpbb_extension_finder
|
|||
$this->query = array(
|
||||
'default_path' => false,
|
||||
'default_suffix' => false,
|
||||
'default_prefix' => false,
|
||||
'default_directory' => false,
|
||||
'suffix' => false,
|
||||
'prefix' => false,
|
||||
'directory' => false,
|
||||
);
|
||||
|
||||
|
@ -76,7 +78,7 @@ class phpbb_extension_finder
|
|||
* Automatically sets the default_suffix if its value does not differ from
|
||||
* the current suffix.
|
||||
*
|
||||
* @param string $default_path A filename suffix
|
||||
* @param string $suffix A filename suffix
|
||||
* @return phpbb_extension_finder This object for chaining calls
|
||||
*/
|
||||
public function suffix($suffix)
|
||||
|
@ -102,6 +104,38 @@ class phpbb_extension_finder
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a prefix all files found in extensions must match
|
||||
*
|
||||
* Automatically sets the default_prefix if its value does not differ from
|
||||
* the current prefix.
|
||||
*
|
||||
* @param string $prefix A filename prefix
|
||||
* @return phpbb_extension_finder This object for chaining calls
|
||||
*/
|
||||
public function prefix($prefix)
|
||||
{
|
||||
if ($this->query['default_prefix'] === $this->query['prefix'])
|
||||
{
|
||||
$this->query['default_prefix'] = $prefix;
|
||||
}
|
||||
|
||||
$this->query['prefix'] = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a prefix all files found in the default path must match
|
||||
*
|
||||
* @param string $default_prefix A filename prefix
|
||||
* @return phpbb_extension_finder This object for chaining calls
|
||||
*/
|
||||
public function default_prefix($default_prefix)
|
||||
{
|
||||
$this->query['default_prefix'] = $default_prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a directory all files found in extensions must be contained in
|
||||
*
|
||||
|
@ -202,16 +236,18 @@ class phpbb_extension_finder
|
|||
|
||||
if ($name === '/')
|
||||
{
|
||||
$prefix = $this->query['default_path'];
|
||||
$location = $this->query['default_path'];
|
||||
$name = '';
|
||||
$suffix = $this->query['default_suffix'];
|
||||
$prefix = $this->query['default_prefix'];
|
||||
$directory = $this->query['default_directory'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$prefix = 'ext/';
|
||||
$location = 'ext/';
|
||||
$name .= '/';
|
||||
$suffix = $this->query['suffix'];
|
||||
$prefix = $this->query['prefix'];
|
||||
$directory = $this->query['directory'];
|
||||
}
|
||||
|
||||
|
@ -226,10 +262,11 @@ class phpbb_extension_finder
|
|||
{
|
||||
$relative_path = $iterator->getInnerIterator()->getSubPathname();
|
||||
|
||||
if ((!$suffix || substr($relative_path, -strlen($suffix)) == $suffix) &&
|
||||
if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) &&
|
||||
(!$prefix || substr($file_info->getFilename(), 0, strlen($prefix)) === $prefix) &&
|
||||
(!$directory || preg_match($directory_pattern, DIRECTORY_SEPARATOR . $relative_path)))
|
||||
{
|
||||
$files[] = str_replace(DIRECTORY_SEPARATOR, '/', $prefix . $name . $relative_path);
|
||||
$files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . $relative_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,24 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
);
|
||||
}
|
||||
|
||||
public function test_prefix_get_classes()
|
||||
{
|
||||
$classes = $this->finder
|
||||
->default_path('includes/default/')
|
||||
->prefix('hidden_')
|
||||
->default_prefix('')
|
||||
->get_classes();
|
||||
|
||||
sort($classes);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'phpbb_default_implementation',
|
||||
'phpbb_ext_bar_my_hidden_class',
|
||||
),
|
||||
$classes
|
||||
);
|
||||
}
|
||||
|
||||
public function test_directory_get_classes()
|
||||
{
|
||||
$classes = $this->finder
|
||||
|
@ -109,8 +127,10 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
$query = array(
|
||||
'default_path' => 'includes/foo',
|
||||
'default_suffix' => false,
|
||||
'default_prefix' => false,
|
||||
'default_directory' => 'bar',
|
||||
'suffix' => false,
|
||||
'prefix' => false,
|
||||
'directory' => false,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue