toArray Should Optionally Return Standard PHP Types
Closed this issue · 2 comments
Current Outcome
Currently toArray()
on resources and resource collections returns an array of objects such as SpinupWp\Resources\Site
, or SpinupWp\Resources\Server
.
Desired Outcome
Ideally we would have the choice to instead instruct these functions to return standard PHP data types of the same information. My use case is that in wanting to build a custom dashboard for SpinupWP inside of MainWP I'd want to cache server and site information. But in order to do this I'd need to pass these arrays to the WP function update_option
, which is currently throwing the following error:
Error: Serialization of 'Closure' is not allowed
This is because the objects can't be serialized, but standard data types could be, so having the choice to get the data in those would be great.
Acceptance Criteria
- A flag that can be passed in to
toArray()
that instructs it to return standard data types rather than SpinupWP objects.
I just realized that a way around this is to json_encode
the arrays.
Glad to hear you've found a solution for this!