aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-08-22 02:17:00 -0400
committerNils Adermann <naderman@naderman.de>2011-09-29 15:42:47 +0200
commitf6632fcfd08650f13560529a6a04c152aefd4e3c (patch)
tree92560ddafc08aaffec333149df60986b83e10744
parent60ad0e21b5d4f940740650df69b7134a573f2a97 (diff)
downloadforums-f6632fcfd08650f13560529a6a04c152aefd4e3c.tar
forums-f6632fcfd08650f13560529a6a04c152aefd4e3c.tar.gz
forums-f6632fcfd08650f13560529a6a04c152aefd4e3c.tar.bz2
forums-f6632fcfd08650f13560529a6a04c152aefd4e3c.tar.xz
forums-f6632fcfd08650f13560529a6a04c152aefd4e3c.zip
[feature/extension-manager] Add filename prefix matching in extension finder
PHPBB3-10323
-rw-r--r--phpBB/includes/extension/finder.php47
-rw-r--r--tests/extension/finder_test.php20
2 files changed, 62 insertions, 5 deletions
diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php
index 4180b84dd3..fbc8a3aefb 100644
--- a/phpBB/includes/extension/finder.php
+++ b/phpBB/includes/extension/finder.php
@@ -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)
@@ -103,6 +105,38 @@ class phpbb_extension_finder
}
/**
+ * 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
*
* Automatically sets the default_directory if its value does not differ from
@@ -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);
}
}
}
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php
index b0c98da554..4acfe53937 100644
--- a/tests/extension/finder_test.php
+++ b/tests/extension/finder_test.php
@@ -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,
);