Browse Source

lu int dbo

tags/0.1.6^0
Robin Thoni 8 years ago
parent
commit
6e5b803da5
2 changed files with 110 additions and 0 deletions
  1. 57
    0
      src/Utils/Dbo/LuIntDbo.php
  2. 53
    0
      src/Utils/Dbo/LuIntDboArray.php

+ 57
- 0
src/Utils/Dbo/LuIntDbo.php View File

@@ -0,0 +1,57 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 2/22/16
6
+ * Time: 9:25 PM
7
+ */
8
+
9
+namespace Luticate\Utils\Dbo;
10
+
11
+
12
+use Luticate\Utils\LuBusiness;
13
+use Luticate\Utils\LuDbo;
14
+
15
+class LuIntDbo extends LuDbo
16
+{
17
+    /**
18
+     * @var int
19
+     */
20
+    private $_value;
21
+
22
+    /**
23
+     * @return int
24
+     */
25
+    public function getInt()
26
+    {
27
+        return $this->_value;
28
+    }
29
+
30
+    /**
31
+     * @param int $value
32
+     */
33
+    public function setInt($value)
34
+    {
35
+        $this->_value = $value;
36
+    }
37
+
38
+    function jsonSerialize()
39
+    {
40
+        return $this->_value;
41
+    }
42
+
43
+    public static function jsonDeserialize($json)
44
+    {
45
+        if (!is_numeric($json) || intval($json) != $json) {
46
+            LuBusiness::badInput("Invalid integer value");
47
+        }
48
+        $val = new LuIntDBo();
49
+        $val->setInt(intval($json));
50
+        return $val;
51
+    }
52
+
53
+    public static function generateSample()
54
+    {
55
+        return 42;
56
+    }
57
+}

+ 53
- 0
src/Utils/Dbo/LuIntDboArray.php View File

@@ -0,0 +1,53 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 2/22/16
6
+ * Time: 9:40 PM
7
+ */
8
+
9
+namespace Luticate\Utils\Dbo;
10
+
11
+
12
+use Luticate\Utils\LuDbo;
13
+
14
+class LuIntDboArray extends LuDbo
15
+{
16
+    /**
17
+     * @var int[]
18
+     */
19
+    protected $_array;
20
+    public function getArray()
21
+    {
22
+        return $this->_array;
23
+    }
24
+    public function setArray($value)
25
+    {
26
+        $this->_array = $value;
27
+    }
28
+
29
+    public function jsonSerialize()
30
+    {
31
+        return $this->_array;
32
+    }
33
+
34
+    public static function jsonDeserialize($json)
35
+    {
36
+        $dbo = new LuIntDboArray();
37
+        $array = [];
38
+        foreach ($json as $data) {
39
+            $array[] = LuIntDbo::jsonDeserialize($data)->getInt();
40
+        }
41
+        $dbo->setArray($array);
42
+        return $dbo;
43
+    }
44
+
45
+    public static function generateSample()
46
+    {
47
+        return [
48
+            LuIntDbo::generateSample(),
49
+            LuIntDbo::generateSample()
50
+        ];
51
+    }
52
+
53
+}

Loading…
Cancel
Save