diff options
author | Nils Adermann <naderman@naderman.de> | 2011-11-18 16:42:53 +0100 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2011-11-18 16:44:42 +0100 |
commit | 0d296785b2364f894f34171d054341cc4979223f (patch) | |
tree | b5ae025f4d24c61a34602f7bf9facffca952bfe9 /phpBB/includes/extension | |
parent | d8e5783e8c341e38a0b8d572c8482b264cacb9c0 (diff) | |
download | forums-0d296785b2364f894f34171d054341cc4979223f.tar forums-0d296785b2364f894f34171d054341cc4979223f.tar.gz forums-0d296785b2364f894f34171d054341cc4979223f.tar.bz2 forums-0d296785b2364f894f34171d054341cc4979223f.tar.xz forums-0d296785b2364f894f34171d054341cc4979223f.zip |
[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
Diffstat (limited to 'phpBB/includes/extension')
-rw-r--r-- | phpBB/includes/extension/finder.php | 168 |
1 files changed, 98 insertions, 70 deletions
diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index f3a9900a67..5850ebe406 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -62,106 +62,120 @@ 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->core_prefix($prefix); + $this->extension_prefix($prefix); + return $this; + } - $this->query['prefix'] = $prefix; + /** + * Sets a prefix all files found in extensions must match + * + * @param string $extension_prefix A filename prefix + * @return phpbb_extension_finder This object for chaining calls + */ + public function extension_prefix($extension_prefix) + { + $this->query['extension_prefix'] = $extension_prefix; return $this; } /** - * Sets a prefix all files found in the default path must match + * Sets a prefix all files found in the core path must match * - * @param string $default_prefix A filename prefix + * @param string $core_prefix A filename prefix * @return phpbb_extension_finder This object for chaining calls */ - public function default_prefix($default_prefix) + public function core_prefix($core_prefix) { - $this->query['default_prefix'] = $default_prefix; + $this->query['core_prefix'] = $core_prefix; return $this; } /** - * Sets a directory all files found in extensions must be contained in + * Sets a directory all files found in extensions and core must be contained in * - * Automatically sets the default_directory if its value does not differ from + * Automatically sets the core_directory if its value does not differ from * the current directory. * * @param string $directory @@ -169,38 +183,52 @@ class phpbb_extension_finder */ public function directory($directory) { - $directory = preg_replace('#(?:^|/)\./#', '/', $directory); - $dir_len = strlen($directory); - - if ($dir_len > 1 && $directory[$dir_len - 1] === '/') - { - $directory = substr($directory, 0, -1); - } - - if ($this->query['default_directory'] === $this->query['directory']) - { - $this->query['default_directory'] = $directory; - } + $this->core_directory($directory); + $this->extension_directory($directory); + return $this; + } - $this->query['directory'] = $directory; + /** + * 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 default path must be contained in + * Sets a directory all files found in the core path must be contained in * - * @param string $default_directory + * @param string $core_directory * @return phpbb_extension_finder This object for chaining calls */ - public function default_directory($default_directory) + 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) { - if (strlen($default_directory) > 1 && $default_directory[strlen($default_directory) - 1] === '/') + $directory = preg_replace('#(?:^|/)\./#', '/', $directory); + $dir_len = strlen($directory); + + if ($dir_len > 1 && $directory[$dir_len - 1] === '/') { - $default_directory = substr($default_directory, 0, -1); + $directory = substr($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 |