Adding pluginSplit and test case. pluginSplit consolidates a number of repeated code blocks.

This commit is contained in:
mark_story 2009-11-15 18:16:12 -05:00
parent 28d3488cb2
commit db0c030557
2 changed files with 29 additions and 0 deletions

View file

@ -212,6 +212,22 @@ if (!function_exists('array_combine')) {
return htmlspecialchars($text, ENT_QUOTES, $charset);
}
/**
* 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);
*
* @param string $name The name you want to plugin split.
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname
*/
function pluginSplit($name) {
if (strpos($name, '.') !== false) {
return explode('.', $name, 2);
}
return array(null, $name);
}
/**
* Returns an array of all the given parameters.
*

View file

@ -764,5 +764,18 @@ class BasicsTest extends CakeTestCase {
$this->assertEqual(ife(0, 'a', 'b'), 'b');
$this->assertEqual(ife(array(), 'a', 'b'), 'b');
}
/**
* test pluginSplit
*
* @return void
*/
function testPluginSplit() {
$result = pluginSplit('Something.else');
$this->assertEqual($result, array('Something', 'else'));
$result = pluginSplit('Somethingelse');
$this->assertEqual($result, array(null, 'Somethingelse'));
}
}
?>