Adding ability to provide default plugin value to pluginSplit().

This commit is contained in:
mark_story 2009-11-15 19:54:33 -05:00
parent 20a114a1cd
commit a292ef0f16
2 changed files with 12 additions and 5 deletions

View file

@ -220,9 +220,10 @@ if (!function_exists('array_combine')) {
*
* @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.
* @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname
*/
function pluginSplit($name, $dotAppend = false) {
function pluginSplit($name, $dotAppend = false, $plugin = null) {
if (strpos($name, '.') !== false) {
$parts = explode('.', $name, 2);
if ($dotAppend) {
@ -230,7 +231,7 @@ if (!function_exists('array_combine')) {
}
return $parts;
}
return array(null, $name);
return array($plugin, $name);
}
/**

View file

@ -773,18 +773,24 @@ class BasicsTest extends CakeTestCase {
function testPluginSplit() {
$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'));
$result = pluginSplit('Post', false, 'Blog');
$this->assertEqual($result, array('Blog', 'Post'));
$result = pluginSplit('Blog.Post', false, 'Ultimate');
$this->assertEqual($result, array('Blog', 'Post'));
}
}
?>