Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hydephp/develop into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 6, 2024
2 parents 33ef708 + d2c74bf commit d69fa97
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/framework/src/Support/Concerns/Serializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ trait Serializable
/** Default implementation to dynamically serialize all public properties. Can be overridden for increased control. */
public function toArray(): array
{
// Calling the function from a different scope means we only get the public properties.

return get_object_vars(...)->__invoke($this);
return $this->automaticallySerialize();
}

/** Recursively serialize Arrayables */
Expand All @@ -39,4 +37,12 @@ public function toJson($options = 0): string
{
return json_encode($this->jsonSerialize(), $options);
}

/** Automatically serialize all public properties. */
protected function automaticallySerialize(): array
{
// Calling the function from a different scope means we only get the public properties.

return get_object_vars(...)->__invoke($this);
}
}

0 comments on commit d69fa97

Please sign in to comment.