Browse Source

String utils

develop
Robin Thoni 8 years ago
parent
commit
9995ef41eb
2 changed files with 10 additions and 6 deletions
  1. 9
    0
      src/Utils/Business/LuStringUtils.php
  2. 1
    6
      src/Utils/Dbo/LuDbo.php

+ 9
- 0
src/Utils/Business/LuStringUtils.php View File

50
             return null;
50
             return null;
51
         }
51
         }
52
     }
52
     }
53
+
54
+    public static function endsWith($haystack, $needle) {
55
+        return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0
56
+            && strpos($haystack, $needle, $temp) !== false);
57
+    }
58
+
59
+    public static function startsWith($haystack, $needle) {
60
+        return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
61
+    }
53
 }
62
 }

+ 1
- 6
src/Utils/Dbo/LuDbo.php View File

60
         return $obj;
60
         return $obj;
61
     }
61
     }
62
 
62
 
63
-    public static function endsWith($haystack, $needle) {
64
-        return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0
65
-            && strpos($haystack, $needle, $temp) !== false);
66
-    }
67
-
68
     public static function deserializeValue($value, $type) {
63
     public static function deserializeValue($value, $type) {
69
         if (is_null($value)) {
64
         if (is_null($value)) {
70
             return null;
65
             return null;
96
         else if ($type == "mixed") {
91
         else if ($type == "mixed") {
97
             return $value;
92
             return $value;
98
         }
93
         }
99
-        else if (self::endsWith($type, "[]")) {
94
+        else if (LuStringUtils::endsWith($type, "[]")) {
100
             if (!is_array($value)) {
95
             if (!is_array($value)) {
101
                 throw new LuDboDeserializeException("Invalid array value");
96
                 throw new LuDboDeserializeException("Invalid array value");
102
             }
97
             }

Loading…
Cancel
Save