File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -61,14 +61,14 @@ public function __construct(
61
61
CustomerInterface $ customer ,
62
62
?PlanInterface $ plan = null ,
63
63
?DateTimeImmutable $ time = null ,
64
- ? string $ data = null ,
64
+ $ data = null ,
65
65
) {
66
66
$ this ->id = $ id ;
67
67
$ this ->target = $ target ;
68
68
$ this ->customer = $ customer ;
69
69
$ this ->plan = $ plan ;
70
70
$ this ->time = $ time ?? new DateTimeImmutable ();
71
- $ this ->data = $ data ;
71
+ $ this ->data = $ this -> setData ( $ data) ;
72
72
}
73
73
74
74
public function getId ()
@@ -130,6 +130,26 @@ public function setId($id)
130
130
$ this ->id = $ id ;
131
131
}
132
132
133
+ public function setData ($ data ): self
134
+ {
135
+ if (empty ($ data )) {
136
+ $ this ->data = null ;
137
+ return $ this ;
138
+ }
139
+
140
+ if (is_string ($ data ) && json_validate ($ data )) {
141
+ $ this ->data = $ data ;
142
+ return $ this ;
143
+ }
144
+
145
+ if (is_array ($ data )) {
146
+ $ this ->data = Json::encode ($ data );
147
+ return $ this ;
148
+ }
149
+
150
+ throw new \Exception ("Cannot assign data " );
151
+ }
152
+
133
153
public function getData (): ?array
134
154
{
135
155
return !empty ($ this ->data ) ? Json::decode ($ this ->data , true ) : null ;
You can’t perform that action at this time.
0 commit comments