@@ -26,7 +26,7 @@ public function __construct($data = null, string $transformer = null)
26
26
$ this ->generatedData = $ this ->handle ();
27
27
}
28
28
29
- public function __invoke () : array
29
+ public function __invoke ()
30
30
{
31
31
return $ this ->generatedData ;
32
32
}
@@ -36,6 +36,19 @@ public function __toString() : string
36
36
return json_encode ($ this ->generatedData );
37
37
}
38
38
39
+ public function setPresent (array $ present )
40
+ {
41
+ $ this ->presentScheme = $ present ;
42
+ return $ this ;
43
+ }
44
+
45
+
46
+ public function setTransformer (string $ transformer )
47
+ {
48
+ $ this ->transformer = $ transformer ;
49
+ return $ this ;
50
+ }
51
+
39
52
abstract public function present () : array ;
40
53
41
54
/**
@@ -63,13 +76,7 @@ public function handle()
63
76
if (is_collection ($ this ->data )) {
64
77
$ generatedData = [];
65
78
foreach ($ this ->data as $ property => $ data ) {
66
- if (!$ this ->isBlank ($ data )) {
67
- $ generatedData [$ property ] = $ this ->transform ($ this ->process ($ this ->convert ($ data )));
68
- }
69
-
70
- if ($ this ->isBlank ($ data )) {
71
- $ generatedData [$ property ] = $ this ->handleDefault ($ this ->convert ($ data ));
72
- }
79
+ $ generatedData [$ property ] = $ this ->handleDefault ($ this ->convert ($ data ));
73
80
}
74
81
75
82
return $ generatedData ;
@@ -80,12 +87,11 @@ public function handle()
80
87
81
88
protected function handleDefault ($ data )
82
89
{
83
-
84
- if (is_null ($ this ->default ) || $ this ->default == '' ) {
85
- return $ this ->default ;
90
+ if (!$ this ->isBlank ($ data )) {
91
+ return $ this ->transform ($ this ->process ($ data ));
86
92
}
87
93
88
- if (is_array ($ this ->default ) && count ($ this ->default )> 0 ) {
94
+ if (is_array ($ this ->default ) && count ($ this ->default ) > 0 ) {
89
95
$ this ->presentScheme = $ this ->default ;
90
96
return $ this ->transform ($ this ->process ($ data ));
91
97
}
0 commit comments