Adding $dotAppend to pluginSplit()

This commit is contained in:
mark_story 2009-11-15 19:12:00 -05:00
parent db0c030557
commit 20a114a1cd
2 changed files with 17 additions and 3 deletions

View file

@ -216,14 +216,19 @@ if (!function_exists('array_combine')) {
* Splits a dot syntax plugin name into its plugin and classname.
* If $name does not have a dot, then index 0 will be null.
*
* Commonly used like `list($plugin, $name) = pluginSplit($name);
* Commonly used like `list($plugin, $name) = pluginSplit($name);`
*
* @param string $name The name you want to plugin split.
* @param boolean $dotAppend Set to true if you want the plugin to have a '.' appended to it.
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname
*/
function pluginSplit($name) {
function pluginSplit($name, $dotAppend = false) {
if (strpos($name, '.') !== false) {
return explode('.', $name, 2);
$parts = explode('.', $name, 2);
if ($dotAppend) {
$parts[0] .= '.';
}
return $parts;
}
return array(null, $name);
}

View file

@ -774,8 +774,17 @@ class BasicsTest extends CakeTestCase {
$result = pluginSplit('Something.else');
$this->assertEqual($result, array('Something', 'else'));
$result = pluginSplit('Something.else.more.dots');
$this->assertEqual($result, array('Something', 'else.more.dots'));
$result = pluginSplit('Somethingelse');
$this->assertEqual($result, array(null, 'Somethingelse'));
$result = pluginSplit('Something.else', true);
$this->assertEqual($result, array('Something.', 'else'));
$result = pluginSplit('Something.else.more.dots', true);
$this->assertEqual($result, array('Something.', 'else.more.dots'));
}
}
?>