Skip to content

Commit

Permalink
Adding ability to provide default plugin value to pluginSplit().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2009
1 parent 20a114a commit a292ef0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cake/basics.php
Expand Up @@ -220,17 +220,18 @@ function h($text, $charset = null) {
*
* @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) {
$parts[0] .= '.';
}
return $parts;
}
return array(null, $name);
return array($plugin, $name);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions cake/tests/cases/basics.test.php
Expand Up @@ -773,18 +773,24 @@ function testIfe() {
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'));
}
}
?>

0 comments on commit a292ef0

Please sign in to comment.