-
Notifications
You must be signed in to change notification settings - Fork 1
toArray
Converts Entity and it's references to nested array structure.
You can format the field using the Policy\To\FormatDateTime OTR always works with UTC timezone type.
This type is converted as any array type with one exception: https://github.com/doctrine/doctrine2/issues/4673
OTR has a fix for that - it saves empty array as [null] and loads it as empty array again. To enable this fix instantiate a new Indaxia\OTR\Annotations\PolicyResolver with the option SIMPLE_ARRAY_FIX:
use Indaxia\OTR\Annotations\PolicyResolver;
// ...
$pr = new PolicyResolver(PolicyResolver::SIMPLE_ARRAY_FIX);
$result = $e->toArray(null, null, $pr);It keeps the source original for other Doctrine and non-Doctrine types.
OTR calls toArray for each sub-Entity or Collection. Don't forget to create a new ArrayCollection in your Entity constructor.
You can paginate your Collection's results using Policy\To\FetchPaginate.
Read Policies to get more info how to control your transformations.