Pārlūkot izejas kodu

fixed datetime serialization

develop
Robin Thoni 8 gadus atpakaļ
vecāks
revīzija
8e7b6327de

+ 1
- 1
src/Utils/DataAccess/LuDataAccess.php Parādīt failu

@@ -95,7 +95,7 @@ abstract class LuDataAccess {
95 95
         }
96 96
         $data = LuStringUtils::convertJsonString($string);
97 97
         
98
-        return call_user_func([static::$_dboArrayClass, 'jsonDeserialize'], $data);
98
+        return call_user_func([static::$_dboArrayClass, 'jsonDeserialize'], $data)->getArray();
99 99
     }
100 100
 
101 101
     /**

+ 7
- 0
src/Utils/Dbo/LuDbo.php Parādīt failu

@@ -2,6 +2,7 @@
2 2
 
3 3
 namespace Luticate\Utils\Dbo;
4 4
 
5
+use Carbon\Carbon;
5 6
 use Luticate\Utils\Business\LuPropertyDocParser;
6 7
 use Luticate\Utils\Business\LuStringUtils;
7 8
 
@@ -32,6 +33,9 @@ abstract class LuDbo implements \JsonSerializable {
32 33
                     if ($v instanceof LuDbo) {
33 34
                         $array[$key] = $v->jsonSerialize();
34 35
                     }
36
+                    else if ($v instanceof Carbon) {
37
+                        $array[$key] = $v->__toString();
38
+                    }
35 39
                     else {
36 40
                         $array[$key] = $v;
37 41
                     }
@@ -43,6 +47,9 @@ abstract class LuDbo implements \JsonSerializable {
43 47
                 if ($value instanceof LuDbo) {
44 48
                     $json[$name] = $value->jsonSerialize();
45 49
                 }
50
+                else if ($value instanceof Carbon) {
51
+                    $json[$name] = $value->__toString();
52
+                }
46 53
                 else {
47 54
                     $json[$name] = $value;
48 55
                 }

+ 25
- 2
tests/DatabaseTest.php Parādīt failu

@@ -1,4 +1,5 @@
1 1
 <?php
2
+use Carbon\Carbon;
2 3
 use Illuminate\Database\Query\Builder;
3 4
 use Luticate\Utils\Controller\LuticateApplication;
4 5
 use Illuminate\Database\Capsule\Manager as Capsule;
@@ -31,6 +32,11 @@ class TestTableDbo extends LuDbo
31 32
      */
32 33
     private $_someIntegerArray;
33 34
 
35
+    /**
36
+     * @var $_createdAt Carbon
37
+     */
38
+    private $_createdAt;
39
+
34 40
     /**
35 41
      * @return int
36 42
      */
@@ -78,6 +84,23 @@ class TestTableDbo extends LuDbo
78 84
     {
79 85
         $this->_someIntegerArray = $someIntegerArray;
80 86
     }
87
+
88
+    /**
89
+     * @return Carbon
90
+     */
91
+    public function getCreatedAt()
92
+    {
93
+        return $this->_createdAt;
94
+    }
95
+
96
+    /**
97
+     * @param Carbon $createdAt
98
+     */
99
+    public function setCreatedAt($createdAt)
100
+    {
101
+        $this->_createdAt = $createdAt;
102
+    }
103
+
81 104
 }
82 105
 
83 106
 class TestTableDboArray extends LuDbo
@@ -148,7 +171,7 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
148 171
 //        ]];
149 172
 //        $app = new LuticateApplication($config);
150 173
 //        $app->setupDatabases();
151
-//        
174
+//
152 175
 //        $dbo = new TestTableDbo();
153 176
 //        $dbo->setId(11);
154 177
 //        $dbo->setSomeIntegerArray('{}');
@@ -157,7 +180,7 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
157 180
 //        var_dump(TestTableDataAccess::getMultiple(function(Builder $q)
158 181
 //        {
159 182
 //            return $q->where("id", "=", 1);
160
-//        }));
183
+//        })[0]->jsonSerialize());
161 184
 //        var_dump(TestTableDataAccess::getSingleById(1));
162 185
 //        var_dump(TestTableDataAccess::deleteMultiple(function($q)
163 186
 //        {

Notiek ielāde…
Atcelt
Saglabāt