@@ -10,10 +10,10 @@ class StringUtils
10
10
/**
11
11
* Method that checks if a string starts with another one.
12
12
*
13
- * @param string $haystack The string in which we're searching in.
14
- * @param string $needle The string we are searching.
15
- * @param boolean $case If it's case sensitive or not.
16
- * @return boolean If the haystack starts by the needle.
13
+ * @param string $haystack The string in which we're searching in.
14
+ * @param string $needle The string we are searching.
15
+ * @param boolean $case If it's case sensitive or not.
16
+ * @return boolean If the haystack starts by the needle.
17
17
*/
18
18
public static function startsWith ($ haystack , $ needle , $ case = true )
19
19
{
@@ -24,10 +24,10 @@ public static function startsWith($haystack, $needle, $case = true)
24
24
/**
25
25
* Method that checks if a string ends with another one.
26
26
*
27
- * @param string $haystack The string in which we're searching in.
28
- * @param string $needle The string we are searching.
29
- * @param boolean $case If it's case sensitive or not.
30
- * @return boolean If the haystack ends by the needle.
27
+ * @param string $haystack The string in which we're searching in.
28
+ * @param string $needle The string we are searching.
29
+ * @param boolean $case If it's case sensitive or not.
30
+ * @return boolean If the haystack ends by the needle.
31
31
*/
32
32
public static function endsWith ($ haystack , $ needle , $ case = true )
33
33
{
@@ -38,9 +38,9 @@ public static function endsWith($haystack, $needle, $case = true)
38
38
/**
39
39
* Method that returns a substring from the start of the haystack to the needle.
40
40
*
41
- * @param string $haystack The string in which we're searching in.
42
- * @param string $needle The string we are searching.
43
- * @return string The string.
41
+ * @param string $haystack The string in which we're searching in.
42
+ * @param string $needle The string we are searching.
43
+ * @return string The string.
44
44
*/
45
45
public static function cutBefore ($ haystack , $ needle )
46
46
{
@@ -51,9 +51,9 @@ public static function cutBefore($haystack, $needle)
51
51
/**
52
52
* Method that returns a substring from the end of the haystack to the needle.
53
53
*
54
- * @param string $haystack The string in which we're searching in.
55
- * @param string $needle The string we are searching.
56
- * @return string The string.
54
+ * @param string $haystack The string in which we're searching in.
55
+ * @param string $needle The string we are searching.
56
+ * @return string The string.
57
57
*/
58
58
public static function cutAfter ($ haystack , $ needle )
59
59
{
@@ -63,18 +63,34 @@ public static function cutAfter($haystack, $needle)
63
63
}
64
64
65
65
/**
66
- * Returns the className of an object without its namespace
66
+ * Method that returns the class name of an object without its namespace.
67
67
*
68
- * @param $object
69
- * @param bool $lowerCase
70
- * @return string
68
+ * @param mixed $object The object for which we want the class name.
69
+ * @param bool $lowerCase If the class name should have the first char to lower case or not.
70
+ * @return string The class name.
71
71
*/
72
72
public static function getClassName ($ object , $ lowerCase = false )
73
73
{
74
74
$ className = substr (strrchr (get_class ($ object ), "\\" ), 1 );
75
75
if ($ lowerCase ) {
76
76
$ className = lcfirst ($ className );
77
77
}
78
+
78
79
return $ className ;
79
80
}
81
+
82
+ /**
83
+ * Method that reverses a camel case string.
84
+ *
85
+ * @param string $content The camel case string.
86
+ * @param string $glue The glue for the compound words. Defaults to '_'.
87
+ * @return string The un-camelcased string.
88
+ */
89
+ public static function unCamelCase($ content , $ glue = '_ ' )
90
+ {
91
+ $ content = preg_replace ('#(?<=[a-zA-Z])([A-Z])(?=[a-zA-Z])#e ' , "' $ glue' . strtolower('$1') " , $ content );
92
+ $ content {0 } = strtolower($ content {0 });
93
+
94
+ return $ content ;
95
+ }
80
96
}
0 commit comments