@@ -98,18 +98,12 @@ public function toArray()
98
98
99
99
private function deepArray ($ array )
100
100
{
101
+ $ useOptimization = !empty ($ this ->uuidOptimization );
101
102
foreach ($ array as $ key => $ value ) {
102
- $ value = $ array [$ key ];
103
- if (is_array ($ value )) {
104
- $ array [$ key ] = $ this ->deepArray ($ value );
105
- } elseif (!preg_match ('//u ' , $ value )) {
106
- // TODO: drop the preg_match because it's slow and
107
- // what if a binary value in the uuid gets represented
108
- // by valid ASCII or UTF symbols?
109
- $ array [$ key ] = (property_exists ($ this , 'uuidOptimization ' ) && $ this ::$ uuidOptimization ) ?
110
- self ::toNormal ($ value ) :
111
- bin2hex ($ value )
112
- ;
103
+ if (!is_string ($ value )) {
104
+ $ array [$ key ] = $ this ->deepArray ((array )$ value );
105
+ } elseif (!ctype_print ($ value )) {
106
+ $ array [$ key ] = $ useOptimization ? self ::toNormal ($ value ) : bin2hex ($ value );
113
107
}
114
108
}
115
109
return $ array ;
@@ -143,4 +137,17 @@ public static function toNormal($uuid)
143
137
bin2hex (substr ($ uuid , 8 , 2 )) .
144
138
bin2hex (substr ($ uuid , 10 ));
145
139
}
140
+
141
+ public function fromJson ($ json , $ asObject = false )
142
+ {
143
+ $ mixed = parent ::fromJson ($ json , $ asObject );
144
+ $ key = $ this ->getKeyName ();
145
+ if ($ asObject ) {
146
+ $ mixed ->{$ key } = static ::toOptimized ($ mixed ->{$ key });
147
+ } else {
148
+ $ mixed [$ key ] = static ::toOptimized ($ mixed [$ key ]);
149
+ }
150
+
151
+ return $ mixed ;
152
+ }
146
153
}
0 commit comments