Bläddra i källkod

String utils

develop
Robin Thoni 8 år sedan
förälder
incheckning
9995ef41eb
2 ändrade filer med 10 tillägg och 6 borttagningar
  1. 9
    0
      src/Utils/Business/LuStringUtils.php
  2. 1
    6
      src/Utils/Dbo/LuDbo.php

+ 9
- 0
src/Utils/Business/LuStringUtils.php Visa fil

@@ -50,4 +50,13 @@ class LuStringUtils
50 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 Visa fil

@@ -60,11 +60,6 @@ abstract class LuDbo implements \JsonSerializable {
60 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 63
     public static function deserializeValue($value, $type) {
69 64
         if (is_null($value)) {
70 65
             return null;
@@ -96,7 +91,7 @@ abstract class LuDbo implements \JsonSerializable {
96 91
         else if ($type == "mixed") {
97 92
             return $value;
98 93
         }
99
-        else if (self::endsWith($type, "[]")) {
94
+        else if (LuStringUtils::endsWith($type, "[]")) {
100 95
             if (!is_array($value)) {
101 96
                 throw new LuDboDeserializeException("Invalid array value");
102 97
             }

Laddar…
Avbryt
Spara