This repository was archived by the owner on Apr 7, 2025. It is now read-only.
File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace DragonCode \SimpleDataTransferObject \Concerns ;
6
+
7
+ trait To
8
+ {
9
+ public function toJson ($ flags = JSON_UNESCAPED_UNICODE ): string
10
+ {
11
+ return json_encode ($ this ->toArray (), $ flags );
12
+ }
13
+ }
Original file line number Diff line number Diff line change 8
8
use DragonCode \SimpleDataTransferObject \Concerns \Castable ;
9
9
use DragonCode \SimpleDataTransferObject \Concerns \From ;
10
10
use DragonCode \SimpleDataTransferObject \Concerns \Reflection ;
11
+ use DragonCode \SimpleDataTransferObject \Concerns \To ;
11
12
use DragonCode \Support \Concerns \Makeable ;
12
13
use DragonCode \Support \Facades \Helpers \Arr ;
13
14
use DragonCode \Support \Facades \Helpers \Str ;
@@ -23,6 +24,7 @@ abstract class DataTransferObject implements Contract
23
24
use From;
24
25
use Makeable;
25
26
use Reflection;
27
+ use To;
26
28
27
29
protected $ map = [];
28
30
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Tests \Unit ;
6
+
7
+ use Tests \Fixtures \Simple ;
8
+ use Tests \TestCase ;
9
+
10
+ class ToJsonTest extends TestCase
11
+ {
12
+ public function testToJson ()
13
+ {
14
+ $ object = new Simple ([
15
+ 'foo ' => $ this ->foo ,
16
+ 'bar ' => $ this ->bar ,
17
+ 'baz ' => $ this ->baz ,
18
+ ]);
19
+
20
+ $ this ->assertJson ($ object ->toJson ());
21
+
22
+ $ this ->assertSame ('{"foo":"Foo"} ' , $ object ->toJson ());
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments