mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +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();
|
||||
|
||||
$modules = $finder
|
||||
->suffix('_module')
|
||||
->directory("/$module_class")
|
||||
->default_path("includes/$module_class/info/")
|
||||
->default_suffix('')
|
||||
->default_prefix($module_class . '_')
|
||||
->default_directory('')
|
||||
->extension_suffix('_module')
|
||||
->extension_directory("/$module_class")
|
||||
->core_path("includes/$module_class/info/")
|
||||
->core_prefix($module_class . '_')
|
||||
->get_classes();
|
||||
|
||||
foreach ($modules as $module)
|
||||
|
|
|
@ -559,11 +559,9 @@ class acp_search
|
|||
$finder = $phpbb_extension_manager->get_finder();
|
||||
|
||||
return $finder
|
||||
->suffix('_backend')
|
||||
->directory('/search')
|
||||
->default_path('includes/search/')
|
||||
->default_suffix('')
|
||||
->default_directory('')
|
||||
->extension_suffix('_backend')
|
||||
->extension_directory('/search')
|
||||
->core_path('includes/search/')
|
||||
->get_classes();
|
||||
|
||||
/*
|
||||
|
|
|
@ -68,10 +68,9 @@ class phpbb_captcha_factory
|
|||
|
||||
$finder = $phpbb_extension_manager->get_finder();
|
||||
$captcha_plugin_classes = $finder
|
||||
->directory('/captcha')
|
||||
->extension_directory('/captcha')
|
||||
->suffix('_plugin')
|
||||
->default_path('includes/captcha/plugins/')
|
||||
->default_directory('')
|
||||
->core_path('includes/captcha/plugins/')
|
||||
->get_classes();
|
||||
|
||||
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();
|
||||
|
||||
return $finder
|
||||
->suffix('_task')
|
||||
->directory('/cron')
|
||||
->default_path('includes/cron/task/core/')
|
||||
->default_suffix('')
|
||||
->default_directory('')
|
||||
->extension_suffix('_task')
|
||||
->extension_directory('/cron')
|
||||
->core_path('includes/cron/task/core/')
|
||||
->get_classes();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,112 +62,163 @@ class phpbb_extension_finder
|
|||
$this->cache_name = $cache_name;
|
||||
|
||||
$this->query = array(
|
||||
'default_path' => false,
|
||||
'default_suffix' => false,
|
||||
'default_prefix' => false,
|
||||
'default_directory' => false,
|
||||
'suffix' => false,
|
||||
'prefix' => false,
|
||||
'directory' => false,
|
||||
'core_path' => false,
|
||||
'core_suffix' => false,
|
||||
'core_prefix' => false,
|
||||
'core_directory' => false,
|
||||
'extension_suffix' => false,
|
||||
'extension_prefix' => false,
|
||||
'extension_directory' => 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* have to specify .php as a suffix. However when using get_classes, the .php
|
||||
* 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
|
||||
* @return phpbb_extension_finder This object for chaining calls
|
||||
*/
|
||||
public function suffix($suffix)
|
||||
{
|
||||
if ($this->query['default_suffix'] === $this->query['suffix'])
|
||||
{
|
||||
$this->query['default_suffix'] = $suffix;
|
||||
}
|
||||
|
||||
$this->query['suffix'] = $suffix;
|
||||
$this->core_suffix($suffix);
|
||||
$this->extension_suffix($suffix);
|
||||
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
|
||||
* have to specify .php as a suffix. However when using get_classes, the .php
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* the current prefix.
|
||||
* 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
|
||||
* 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
|
||||
* @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;
|
||||
$this->core_prefix($prefix);
|
||||
$this->extension_prefix($prefix);
|
||||
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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return phpbb_extension_finder This object for chaining calls
|
||||
*/
|
||||
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);
|
||||
$dir_len = strlen($directory);
|
||||
|
@ -177,30 +228,7 @@ class phpbb_extension_finder
|
|||
$directory = substr($directory, 0, -1);
|
||||
}
|
||||
|
||||
if ($this->query['default_directory'] === $this->query['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;
|
||||
return $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,8 +244,8 @@ class phpbb_extension_finder
|
|||
*/
|
||||
public function get_classes($cache = true)
|
||||
{
|
||||
$this->query['suffix'] .= $this->phpEx;
|
||||
$this->query['default_suffix'] .= $this->phpEx;
|
||||
$this->query['extension_suffix'] .= $this->phpEx;
|
||||
$this->query['core_suffix'] .= $this->phpEx;
|
||||
|
||||
$files = $this->find($cache, false);
|
||||
|
||||
|
@ -296,9 +324,9 @@ class phpbb_extension_finder
|
|||
|
||||
$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)
|
||||
|
@ -312,19 +340,19 @@ class phpbb_extension_finder
|
|||
|
||||
if ($name === '/')
|
||||
{
|
||||
$location = $this->query['default_path'];
|
||||
$location = $this->query['core_path'];
|
||||
$name = '';
|
||||
$suffix = $this->query['default_suffix'];
|
||||
$prefix = $this->query['default_prefix'];
|
||||
$directory = $this->query['default_directory'];
|
||||
$suffix = $this->query['core_suffix'];
|
||||
$prefix = $this->query['core_prefix'];
|
||||
$directory = $this->query['core_directory'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$location = 'ext/';
|
||||
$name .= '/';
|
||||
$suffix = $this->query['suffix'];
|
||||
$prefix = $this->query['prefix'];
|
||||
$directory = $this->query['directory'];
|
||||
$suffix = $this->query['extension_suffix'];
|
||||
$prefix = $this->query['extension_prefix'];
|
||||
$directory = $this->query['extension_directory'];
|
||||
}
|
||||
|
||||
// match only first directory if leading slash is given
|
||||
|
|
|
@ -873,9 +873,8 @@ class p_master
|
|||
$lang_files = $finder
|
||||
->prefix('info_' . strtolower($module_class) . '_')
|
||||
->suffix(".$phpEx")
|
||||
->directory('/language/' . $user->lang_name)
|
||||
->default_path('language/' . $user->lang_name . '/mods/')
|
||||
->default_directory('')
|
||||
->extension_directory('/language/' . $user->lang_name)
|
||||
->core_path('language/' . $user->lang_name . '/mods/')
|
||||
->find();
|
||||
|
||||
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()
|
||||
{
|
||||
$classes = $this->finder
|
||||
->default_path('includes/default/')
|
||||
->suffix('_class')
|
||||
->default_suffix('')
|
||||
->core_path('includes/default/')
|
||||
->extension_suffix('_class')
|
||||
->get_classes();
|
||||
|
||||
sort($classes);
|
||||
|
@ -84,9 +83,8 @@ 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('')
|
||||
->core_path('includes/default/')
|
||||
->extension_prefix('hidden_')
|
||||
->get_classes();
|
||||
|
||||
sort($classes);
|
||||
|
@ -102,9 +100,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
public function test_directory_get_classes()
|
||||
{
|
||||
$classes = $this->finder
|
||||
->default_path('includes/default/')
|
||||
->directory('type')
|
||||
->default_directory('')
|
||||
->core_path('includes/default/')
|
||||
->extension_directory('type')
|
||||
->get_classes();
|
||||
|
||||
sort($classes);
|
||||
|
@ -161,13 +158,13 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
);
|
||||
|
||||
$query = array(
|
||||
'default_path' => false,
|
||||
'default_suffix' => '_class.php',
|
||||
'default_prefix' => false,
|
||||
'default_directory' => false,
|
||||
'suffix' => '_class.php',
|
||||
'prefix' => false,
|
||||
'directory' => false,
|
||||
'core_path' => false,
|
||||
'core_suffix' => '_class.php',
|
||||
'core_prefix' => false,
|
||||
'core_directory' => false,
|
||||
'extension_suffix' => '_class.php',
|
||||
'extension_prefix' => false,
|
||||
'extension_directory' => false,
|
||||
'is_dir' => false,
|
||||
);
|
||||
|
||||
|
@ -179,13 +176,13 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
public function test_cached_get_files()
|
||||
{
|
||||
$query = array(
|
||||
'default_path' => 'includes/foo',
|
||||
'default_suffix' => false,
|
||||
'default_prefix' => false,
|
||||
'default_directory' => 'bar',
|
||||
'suffix' => false,
|
||||
'prefix' => false,
|
||||
'directory' => false,
|
||||
'core_path' => 'includes/foo',
|
||||
'core_suffix' => false,
|
||||
'core_prefix' => false,
|
||||
'core_directory' => 'bar',
|
||||
'extension_suffix' => false,
|
||||
'extension_prefix' => false,
|
||||
'extension_directory' => false,
|
||||
'is_dir' => false,
|
||||
);
|
||||
|
||||
|
@ -196,8 +193,8 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
|||
)));
|
||||
|
||||
$classes = $finder
|
||||
->default_path($query['default_path'])
|
||||
->default_directory($query['default_directory'])
|
||||
->core_path($query['core_path'])
|
||||
->core_directory($query['core_directory'])
|
||||
->get_files();
|
||||
|
||||
sort($classes);
|
||||
|
|
Loading…
Add table
Reference in a new issue