toArray - Indaxia/doctrine-orm-transformations GitHub Wiki

Converts Entity and it's references to nested array structure.

Scalar Types

datetime, datetimez, date, time

You can format the field using the Policy\To\FormatDateTime OTR always works with UTC timezone type.

simple_array

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);

Other

It keeps the source original for other Doctrine and non-Doctrine types.

Relations

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.