浏览代码

String utils

develop
Robin Thoni 8 年前
父节点
当前提交
9995ef41eb
共有 2 个文件被更改,包括 10 次插入6 次删除
  1. 9
    0
      src/Utils/Business/LuStringUtils.php
  2. 1
    6
      src/Utils/Dbo/LuDbo.php

+ 9
- 0
src/Utils/Business/LuStringUtils.php 查看文件

@@ -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 查看文件

@@ -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
             }

正在加载...
取消
保存