Closed vsouz4 closed 3 years ago
The PR looks sane. @vsouz4 What about breaking change that @ivastly mentioned in the previous PR? With array of arrays instead of an array of entities? Is it valid? Unfortunately, I don't have a real client now to test it.
The PR looks sane. @vsouz4 What about breaking change that @ivastly mentioned in the previous PR? With array of arrays instead of an array of entities? Is it valid? Unfortunately, I don't have a real client now to test it.
I've spoken with @ivastly seems like he had some code like
array_map(
static function (SomeObject ...) {
...
},
$someCollection->toArray()
)
and had to change ->toArray()
to $someCollection->getIterator()->getArrayCopy()
or iterator_to_array($someCollection)
. Turns out the change I've introduced on that previous PR (3.0.3) should've been made together with the major version 3.0.0 update, because with the lack of jsonSerialize, we had to start using toArray to serialize our objects, and we needed toArray to call inner toArray's as well otherwise we would need to recursively/manually serialize these inner objects.
toArray
docblock, correct @return is array, not array of the inner entitiesjson_encode
with schema objects, now, if one wants to respond these objects directly, one needs usually to check if it's empty (e.g.json_encode(['myValue' => $myObject->getMyValue() === null ? null : $myObject->getMyValue()->toArray()])
, by implementingJsonSerializable
again, we offer one more way to serialize the api client structures, in a backwards compatible fashion.