Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding pluginSplit and test case. pluginSplit consolidates a number o…

…f repeated code blocks.
  • Loading branch information...
commit db0c030557218d8693750f7499c2647a8aa02ad5 1 parent 28d3488
@markstory markstory authored
Showing with 29 additions and 0 deletions.
  1. +16 −0 cake/basics.php
  2. +13 −0 cake/tests/cases/basics.test.php
View
16 cake/basics.php
@@ -213,6 +213,22 @@ function h($text, $charset = null) {
}
/**
+ * 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.
*
* Example:
View
13 cake/tests/cases/basics.test.php
@@ -764,5 +764,18 @@ function testIfe() {
$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'));
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.