mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[feature/extension-manager] Rename default methods to core methods on finder.
There are now extension_ and core_ methods for all finder settings as well as a generic method which overwrites both. PHPBB3-10323
This commit is contained in:
parent
d8e5783e8c
commit
0d296785b2
7 changed files with 139 additions and 122 deletions
|
@ -544,12 +544,10 @@ class acp_modules
|
||||||
$finder = $phpbb_extension_manager->get_finder();
|
$finder = $phpbb_extension_manager->get_finder();
|
||||||
|
|
||||||
$modules = $finder
|
$modules = $finder
|
||||||
->suffix('_module')
|
->extension_suffix('_module')
|
||||||
->directory("/$module_class")
|
->extension_directory("/$module_class")
|
||||||
->default_path("includes/$module_class/info/")
|
->core_path("includes/$module_class/info/")
|
||||||
->default_suffix('')
|
->core_prefix($module_class . '_')
|
||||||
->default_prefix($module_class . '_')
|
|
||||||
->default_directory('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
foreach ($modules as $module)
|
foreach ($modules as $module)
|
||||||
|
|
|
@ -559,11 +559,9 @@ class acp_search
|
||||||
$finder = $phpbb_extension_manager->get_finder();
|
$finder = $phpbb_extension_manager->get_finder();
|
||||||
|
|
||||||
return $finder
|
return $finder
|
||||||
->suffix('_backend')
|
->extension_suffix('_backend')
|
||||||
->directory('/search')
|
->extension_directory('/search')
|
||||||
->default_path('includes/search/')
|
->core_path('includes/search/')
|
||||||
->default_suffix('')
|
|
||||||
->default_directory('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -68,10 +68,9 @@ class phpbb_captcha_factory
|
||||||
|
|
||||||
$finder = $phpbb_extension_manager->get_finder();
|
$finder = $phpbb_extension_manager->get_finder();
|
||||||
$captcha_plugin_classes = $finder
|
$captcha_plugin_classes = $finder
|
||||||
->directory('/captcha')
|
->extension_directory('/captcha')
|
||||||
->suffix('_plugin')
|
->suffix('_plugin')
|
||||||
->default_path('includes/captcha/plugins/')
|
->core_path('includes/captcha/plugins/')
|
||||||
->default_directory('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
foreach ($captcha_plugin_classes as $class)
|
foreach ($captcha_plugin_classes as $class)
|
||||||
|
|
|
@ -40,11 +40,9 @@ class phpbb_cron_task_provider extends phpbb_extension_provider
|
||||||
$finder = $this->extension_manager->get_finder();
|
$finder = $this->extension_manager->get_finder();
|
||||||
|
|
||||||
return $finder
|
return $finder
|
||||||
->suffix('_task')
|
->extension_suffix('_task')
|
||||||
->directory('/cron')
|
->extension_directory('/cron')
|
||||||
->default_path('includes/cron/task/core/')
|
->core_path('includes/cron/task/core/')
|
||||||
->default_suffix('')
|
|
||||||
->default_directory('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,112 +62,163 @@ class phpbb_extension_finder
|
||||||
$this->cache_name = $cache_name;
|
$this->cache_name = $cache_name;
|
||||||
|
|
||||||
$this->query = array(
|
$this->query = array(
|
||||||
'default_path' => false,
|
'core_path' => false,
|
||||||
'default_suffix' => false,
|
'core_suffix' => false,
|
||||||
'default_prefix' => false,
|
'core_prefix' => false,
|
||||||
'default_directory' => false,
|
'core_directory' => false,
|
||||||
'suffix' => false,
|
'extension_suffix' => false,
|
||||||
'prefix' => false,
|
'extension_prefix' => false,
|
||||||
'directory' => false,
|
'extension_directory' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false;
|
$this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a default path to be searched in addition to extensions
|
* Sets a core path to be searched in addition to extensions
|
||||||
*
|
*
|
||||||
* @param string $default_path The path relative to phpbb_root_path
|
* @param string $core_path The path relative to phpbb_root_path
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function default_path($default_path)
|
public function core_path($core_path)
|
||||||
{
|
{
|
||||||
$this->query['default_path'] = $default_path;
|
$this->query['core_path'] = $core_path;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a suffix all files found in extensions must match.
|
* Sets the suffix all files found in extensions and core must match.
|
||||||
*
|
*
|
||||||
* There is no default file extension, so to find PHP files only, you will
|
* There is no default file extension, so to find PHP files only, you will
|
||||||
* have to specify .php as a suffix. However when using get_classes, the .php
|
* have to specify .php as a suffix. However when using get_classes, the .php
|
||||||
* file extension is automatically added to suffixes.
|
* file extension is automatically added to suffixes.
|
||||||
*
|
*
|
||||||
* Automatically sets the default_suffix if its value does not differ from
|
|
||||||
* the current suffix.
|
|
||||||
*
|
|
||||||
* @param string $suffix A filename suffix
|
* @param string $suffix A filename suffix
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function suffix($suffix)
|
public function suffix($suffix)
|
||||||
{
|
{
|
||||||
if ($this->query['default_suffix'] === $this->query['suffix'])
|
$this->core_suffix($suffix);
|
||||||
{
|
$this->extension_suffix($suffix);
|
||||||
$this->query['default_suffix'] = $suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->query['suffix'] = $suffix;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a suffix all files found in the default path must match
|
* Sets a suffix all files found in extensions must match
|
||||||
*
|
*
|
||||||
* There is no default file extension, so to find PHP files only, you will
|
* There is no default file extension, so to find PHP files only, you will
|
||||||
* have to specify .php as a suffix. However when using get_classes, the .php
|
* have to specify .php as a suffix. However when using get_classes, the .php
|
||||||
* file extension is automatically added to suffixes.
|
* file extension is automatically added to suffixes.
|
||||||
*
|
*
|
||||||
* @param string $default_suffix A filename suffix
|
* @param string $extension_suffix A filename suffix
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function default_suffix($default_suffix)
|
public function extension_suffix($extension_suffix)
|
||||||
{
|
{
|
||||||
$this->query['default_suffix'] = $default_suffix;
|
$this->query['extension_suffix'] = $extension_suffix;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a prefix all files found in extensions must match
|
* Sets a suffix all files found in the core path must match
|
||||||
*
|
*
|
||||||
* Automatically sets the default_prefix if its value does not differ from
|
* There is no default file extension, so to find PHP files only, you will
|
||||||
* the current prefix.
|
* have to specify .php as a suffix. However when using get_classes, the .php
|
||||||
|
* file extension is automatically added to suffixes.
|
||||||
|
*
|
||||||
|
* @param string $core_suffix A filename suffix
|
||||||
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
|
*/
|
||||||
|
public function core_suffix($core_suffix)
|
||||||
|
{
|
||||||
|
$this->query['core_suffix'] = $core_suffix;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the prefix all files found in extensions and core must match
|
||||||
*
|
*
|
||||||
* @param string $prefix A filename prefix
|
* @param string $prefix A filename prefix
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function prefix($prefix)
|
public function prefix($prefix)
|
||||||
{
|
{
|
||||||
if ($this->query['default_prefix'] === $this->query['prefix'])
|
$this->core_prefix($prefix);
|
||||||
{
|
$this->extension_prefix($prefix);
|
||||||
$this->query['default_prefix'] = $prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->query['prefix'] = $prefix;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a prefix all files found in the default path must match
|
* Sets a prefix all files found in extensions must match
|
||||||
*
|
*
|
||||||
* @param string $default_prefix A filename prefix
|
* @param string $extension_prefix A filename prefix
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function default_prefix($default_prefix)
|
public function extension_prefix($extension_prefix)
|
||||||
{
|
{
|
||||||
$this->query['default_prefix'] = $default_prefix;
|
$this->query['extension_prefix'] = $extension_prefix;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a directory all files found in extensions must be contained in
|
* Sets a prefix all files found in the core path must match
|
||||||
*
|
*
|
||||||
* Automatically sets the default_directory if its value does not differ from
|
* @param string $core_prefix A filename prefix
|
||||||
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
|
*/
|
||||||
|
public function core_prefix($core_prefix)
|
||||||
|
{
|
||||||
|
$this->query['core_prefix'] = $core_prefix;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a directory all files found in extensions and core must be contained in
|
||||||
|
*
|
||||||
|
* Automatically sets the core_directory if its value does not differ from
|
||||||
* the current directory.
|
* the current directory.
|
||||||
*
|
*
|
||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
*/
|
*/
|
||||||
public function directory($directory)
|
public function directory($directory)
|
||||||
|
{
|
||||||
|
$this->core_directory($directory);
|
||||||
|
$this->extension_directory($directory);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a directory all files found in extensions must be contained in
|
||||||
|
*
|
||||||
|
* @param string $extension_directory
|
||||||
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
|
*/
|
||||||
|
public function extension_directory($extension_directory)
|
||||||
|
{
|
||||||
|
$this->query['extension_directory'] = $this->sanitise_directory($extension_directory);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a directory all files found in the core path must be contained in
|
||||||
|
*
|
||||||
|
* @param string $core_directory
|
||||||
|
* @return phpbb_extension_finder This object for chaining calls
|
||||||
|
*/
|
||||||
|
public function core_directory($core_directory)
|
||||||
|
{
|
||||||
|
$this->query['core_directory'] = $this->sanitise_directory($core_directory);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes occurances of /./ and makes sure path ends without trailing slash
|
||||||
|
*
|
||||||
|
* @param string $directory A directory pattern
|
||||||
|
* @return string A cleaned up directory pattern
|
||||||
|
*/
|
||||||
|
protected function sanitise_directory($directory)
|
||||||
{
|
{
|
||||||
$directory = preg_replace('#(?:^|/)\./#', '/', $directory);
|
$directory = preg_replace('#(?:^|/)\./#', '/', $directory);
|
||||||
$dir_len = strlen($directory);
|
$dir_len = strlen($directory);
|
||||||
|
@ -177,30 +228,7 @@ class phpbb_extension_finder
|
||||||
$directory = substr($directory, 0, -1);
|
$directory = substr($directory, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->query['default_directory'] === $this->query['directory'])
|
return $directory;
|
||||||
{
|
|
||||||
$this->query['default_directory'] = $directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->query['directory'] = $directory;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a directory all files found in the default path must be contained in
|
|
||||||
*
|
|
||||||
* @param string $default_directory
|
|
||||||
* @return phpbb_extension_finder This object for chaining calls
|
|
||||||
*/
|
|
||||||
public function default_directory($default_directory)
|
|
||||||
{
|
|
||||||
if (strlen($default_directory) > 1 && $default_directory[strlen($default_directory) - 1] === '/')
|
|
||||||
{
|
|
||||||
$default_directory = substr($default_directory, 0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->query['default_directory'] = $default_directory;
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,8 +244,8 @@ class phpbb_extension_finder
|
||||||
*/
|
*/
|
||||||
public function get_classes($cache = true)
|
public function get_classes($cache = true)
|
||||||
{
|
{
|
||||||
$this->query['suffix'] .= $this->phpEx;
|
$this->query['extension_suffix'] .= $this->phpEx;
|
||||||
$this->query['default_suffix'] .= $this->phpEx;
|
$this->query['core_suffix'] .= $this->phpEx;
|
||||||
|
|
||||||
$files = $this->find($cache, false);
|
$files = $this->find($cache, false);
|
||||||
|
|
||||||
|
@ -296,9 +324,9 @@ class phpbb_extension_finder
|
||||||
|
|
||||||
$extensions = $this->extension_manager->all_enabled();
|
$extensions = $this->extension_manager->all_enabled();
|
||||||
|
|
||||||
if ($this->query['default_path'])
|
if ($this->query['core_path'])
|
||||||
{
|
{
|
||||||
$extensions['/'] = $this->phpbb_root_path . $this->query['default_path'];
|
$extensions['/'] = $this->phpbb_root_path . $this->query['core_path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($extensions as $name => $path)
|
foreach ($extensions as $name => $path)
|
||||||
|
@ -312,19 +340,19 @@ class phpbb_extension_finder
|
||||||
|
|
||||||
if ($name === '/')
|
if ($name === '/')
|
||||||
{
|
{
|
||||||
$location = $this->query['default_path'];
|
$location = $this->query['core_path'];
|
||||||
$name = '';
|
$name = '';
|
||||||
$suffix = $this->query['default_suffix'];
|
$suffix = $this->query['core_suffix'];
|
||||||
$prefix = $this->query['default_prefix'];
|
$prefix = $this->query['core_prefix'];
|
||||||
$directory = $this->query['default_directory'];
|
$directory = $this->query['core_directory'];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$location = 'ext/';
|
$location = 'ext/';
|
||||||
$name .= '/';
|
$name .= '/';
|
||||||
$suffix = $this->query['suffix'];
|
$suffix = $this->query['extension_suffix'];
|
||||||
$prefix = $this->query['prefix'];
|
$prefix = $this->query['extension_prefix'];
|
||||||
$directory = $this->query['directory'];
|
$directory = $this->query['extension_directory'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// match only first directory if leading slash is given
|
// match only first directory if leading slash is given
|
||||||
|
|
|
@ -873,9 +873,8 @@ class p_master
|
||||||
$lang_files = $finder
|
$lang_files = $finder
|
||||||
->prefix('info_' . strtolower($module_class) . '_')
|
->prefix('info_' . strtolower($module_class) . '_')
|
||||||
->suffix(".$phpEx")
|
->suffix(".$phpEx")
|
||||||
->directory('/language/' . $user->lang_name)
|
->extension_directory('/language/' . $user->lang_name)
|
||||||
->default_path('language/' . $user->lang_name . '/mods/')
|
->core_path('language/' . $user->lang_name . '/mods/')
|
||||||
->default_directory('')
|
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
foreach ($lang_files as $lang_file => $ext_name)
|
foreach ($lang_files as $lang_file => $ext_name)
|
||||||
|
|
|
@ -38,9 +38,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
public function test_suffix_get_classes()
|
public function test_suffix_get_classes()
|
||||||
{
|
{
|
||||||
$classes = $this->finder
|
$classes = $this->finder
|
||||||
->default_path('includes/default/')
|
->core_path('includes/default/')
|
||||||
->suffix('_class')
|
->extension_suffix('_class')
|
||||||
->default_suffix('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
sort($classes);
|
sort($classes);
|
||||||
|
@ -84,9 +83,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
public function test_prefix_get_classes()
|
public function test_prefix_get_classes()
|
||||||
{
|
{
|
||||||
$classes = $this->finder
|
$classes = $this->finder
|
||||||
->default_path('includes/default/')
|
->core_path('includes/default/')
|
||||||
->prefix('hidden_')
|
->extension_prefix('hidden_')
|
||||||
->default_prefix('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
sort($classes);
|
sort($classes);
|
||||||
|
@ -102,9 +100,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
public function test_directory_get_classes()
|
public function test_directory_get_classes()
|
||||||
{
|
{
|
||||||
$classes = $this->finder
|
$classes = $this->finder
|
||||||
->default_path('includes/default/')
|
->core_path('includes/default/')
|
||||||
->directory('type')
|
->extension_directory('type')
|
||||||
->default_directory('')
|
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
sort($classes);
|
sort($classes);
|
||||||
|
@ -161,13 +158,13 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = array(
|
$query = array(
|
||||||
'default_path' => false,
|
'core_path' => false,
|
||||||
'default_suffix' => '_class.php',
|
'core_suffix' => '_class.php',
|
||||||
'default_prefix' => false,
|
'core_prefix' => false,
|
||||||
'default_directory' => false,
|
'core_directory' => false,
|
||||||
'suffix' => '_class.php',
|
'extension_suffix' => '_class.php',
|
||||||
'prefix' => false,
|
'extension_prefix' => false,
|
||||||
'directory' => false,
|
'extension_directory' => false,
|
||||||
'is_dir' => false,
|
'is_dir' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -179,13 +176,13 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
public function test_cached_get_files()
|
public function test_cached_get_files()
|
||||||
{
|
{
|
||||||
$query = array(
|
$query = array(
|
||||||
'default_path' => 'includes/foo',
|
'core_path' => 'includes/foo',
|
||||||
'default_suffix' => false,
|
'core_suffix' => false,
|
||||||
'default_prefix' => false,
|
'core_prefix' => false,
|
||||||
'default_directory' => 'bar',
|
'core_directory' => 'bar',
|
||||||
'suffix' => false,
|
'extension_suffix' => false,
|
||||||
'prefix' => false,
|
'extension_prefix' => false,
|
||||||
'directory' => false,
|
'extension_directory' => false,
|
||||||
'is_dir' => false,
|
'is_dir' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -196,8 +193,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$classes = $finder
|
$classes = $finder
|
||||||
->default_path($query['default_path'])
|
->core_path($query['core_path'])
|
||||||
->default_directory($query['default_directory'])
|
->core_directory($query['core_directory'])
|
||||||
->get_files();
|
->get_files();
|
||||||
|
|
||||||
sort($classes);
|
sort($classes);
|
||||||
|
|
Loading…
Add table
Reference in a new issue