@@ -76,7 +76,7 @@ public function fill(array $data): static
7676 $ property ->setValue ($ this , $ value );
7777 } elseif (PHP_VERSION_ID > 80100 && enum_exists ($ type ->getName ())) {
7878 if (is_int ($ value ) || is_string ($ value )) {
79- $ value = $ type ->getName ()::from ($ value );
79+ $ value = $ type ->getName ()::{ ' from ' } ($ value );
8080 }
8181 $ property ->setValue ($ this , $ value );
8282 } elseif (class_exists ($ type ->getName ())) {
@@ -135,6 +135,9 @@ protected function forValue(mixed $value, bool $toSnake)
135135 return array_map (fn ($ item ) => $ this ->forValue ($ item , $ toSnake ), $ value );
136136 }
137137 if (is_object ($ value )) {
138+ if (PHP_VERSION_ID > 80100 && enum_exists (get_class ($ value ))) {
139+ return $ value ->value ;
140+ }
138141 if ($ this ->isArrayAble ($ value )) {
139142 return $ value ->toArray ();
140143 }
@@ -175,7 +178,22 @@ protected function isArrayAble($data): bool
175178 return $ data instanceof ArrayAble || is_object ($ data ) && method_exists ($ data , 'toArray ' );
176179 }
177180
178- protected function beforeFill (array $ data ): void {}
181+ protected function beforeFill (array $ data ): void
182+ {
183+ }
184+
185+ protected function afterFill (array $ data )
186+ {
187+ }
179188
180- protected function afterFill (array $ data ) {}
189+ public function __serialize (): array
190+ {
191+ $ data = [];
192+ foreach ($ this ->getStaticReflection ()->getProperties () as $ property ) {
193+ if (!$ this ->isInsideProperty ($ property )) {
194+ $ data [$ property ->getName ()] = $ property ->getValue ($ this );
195+ }
196+ }
197+ return $ data ;
198+ }
181199}
0 commit comments