Skip to content
This repository
Browse code

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

…f repeated code blocks.
  • Loading branch information...
commit db0c030557218d8693750f7499c2647a8aa02ad5 1 parent 28d3488
Mark Story authored November 15, 2009
16  cake/basics.php
@@ -213,6 +213,22 @@ function h($text, $charset = null) {
213 213
 	}
214 214
 
215 215
 /**
  216
+ * Splits a dot syntax plugin name into its plugin and classname.
  217
+ * If $name does not have a dot, then index 0 will be null.
  218
+ *
  219
+ * Commonly used like `list($plugin, $name) = pluginSplit($name);
  220
+ *
  221
+ * @param string $name The name you want to plugin split.
  222
+ * @return array Array with 2 indexes.  0 => plugin name, 1 => classname
  223
+ */
  224
+	function pluginSplit($name) {
  225
+		if (strpos($name, '.') !== false) {
  226
+			return explode('.', $name, 2);
  227
+		}
  228
+		return array(null, $name);
  229
+	}
  230
+
  231
+/**
216 232
  * Returns an array of all the given parameters.
217 233
  *
218 234
  * Example:
13  cake/tests/cases/basics.test.php
@@ -764,5 +764,18 @@ function testIfe() {
764 764
 		$this->assertEqual(ife(0, 'a', 'b'), 'b');
765 765
 		$this->assertEqual(ife(array(), 'a', 'b'), 'b');
766 766
 	}
  767
+
  768
+/**
  769
+ * test pluginSplit
  770
+ *
  771
+ * @return void
  772
+ */
  773
+	function testPluginSplit() {
  774
+		$result = pluginSplit('Something.else');
  775
+		$this->assertEqual($result, array('Something', 'else'));
  776
+
  777
+		$result = pluginSplit('Somethingelse');
  778
+		$this->assertEqual($result, array(null, 'Somethingelse'));
  779
+	}
767 780
 }
768 781
 ?>

0 notes on commit db0c030

Please sign in to comment.
Something went wrong with that request. Please try again.