From 20a114a1cd922b2027beb258215a258af3af0ea5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 15 Nov 2009 19:12:00 -0500 Subject: [PATCH] Adding $dotAppend to pluginSplit() --- cake/basics.php | 11 ++++++++--- cake/tests/cases/basics.test.php | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index b18e415a7..039d1c42e 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -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); } diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 01860d2dc..ff39e9fa1 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -773,9 +773,18 @@ 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')); } } ?> \ No newline at end of file