mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding pluginSplit and test case. pluginSplit consolidates a number of repeated code blocks.
This commit is contained in:
parent
28d3488cb2
commit
db0c030557
2 changed files with 29 additions and 0 deletions
|
@ -212,6 +212,22 @@ if (!function_exists('array_combine')) {
|
||||||
return htmlspecialchars($text, ENT_QUOTES, $charset);
|
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.
|
* Returns an array of all the given parameters.
|
||||||
*
|
*
|
||||||
|
|
|
@ -764,5 +764,18 @@ class BasicsTest extends CakeTestCase {
|
||||||
$this->assertEqual(ife(0, 'a', 'b'), 'b');
|
$this->assertEqual(ife(0, 'a', 'b'), 'b');
|
||||||
$this->assertEqual(ife(array(), '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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue