PHPackages                             indaxia/doctrine-orm-transformations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. indaxia/doctrine-orm-transformations

ActiveLibrary[Database &amp; ORM](/categories/database)

indaxia/doctrine-orm-transformations
====================================

Provides JSON-ready Doctrine ORM Entity-Array transfomtaions

2.0.1-stable(9y ago)12103.0k↑177.5%1[5 issues](https://github.com/Indaxia/doctrine-orm-transformations/issues)1MITPHPPHP &gt;=5.4.0

Since Oct 17Pushed 8y ago3 watchersCompare

[ Source](https://github.com/Indaxia/doctrine-orm-transformations)[ Packagist](https://packagist.org/packages/indaxia/doctrine-orm-transformations)[ Docs](http://indaxia.github.io/doctrine-orm-transformations/)[ RSS](/packages/indaxia-doctrine-orm-transformations/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (36)Used By (1)

JSON-ready Doctrine ORM Entity-Array Transformations
====================================================

[](#json-ready-doctrine-orm-entity-array-transformations)

Features
--------

[](#features)

- JSON-ready toArray and fromArray Trait (**no need to extend class**);
- Manipulating fields and **nested** sub-fields using [Policy](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Policies) for each one;
- Supports all Doctrine ORM Column types;
- Supports JavaScript [ISO8601](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) format for "date", "time" and "datetime" types;
- Supports nested **Entities** and **Collections** for all the [Association](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html) types (be careful with self-referencing);
- **fromArray** asks EntityManager to find by "referencedColumnName" or creates new sub-entities (depends on Identifier emptiness and Policy);
- Same for [Collection](https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/ArrayCollection.php) members (OneToMany, ManyToMany);
- Static **toArrays** method transforms multiple entities at once;
- Has workarounds for [CVE-2015-0231](http://cve.mitre.org/cgi-bin/cvename.cgi?name=2015-0231) and [Doctrine issue #4673](https://github.com/doctrine/doctrine2/issues/4673);

Step 1: Installation
--------------------

[](#step-1-installation)

in **composer.json** add:

```
"require": {

    "Indaxia/doctrine-orm-transformations": "2.*"
}
```

then

```
> cd
> composer update
```

[Requirements &amp; Restrictions](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Requirements-and-Restrictions)

Step 2: Reference common classes
--------------------------------

[](#step-2-reference-common-classes)

```
use \Indaxia\OTR\ITransformable;
use \Indaxia\OTR\Traits\Transformable;
use \Indaxia\OTR\Annotations\Policy;
```

Documentation
-------------

[](#documentation)

[Full Documentation](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Indaxia-OTR-Documentation)

How to transform entities to arrays and vice versa
--------------------------------------------------

[](#how-to-transform-entities-to-arrays-and-vice-versa)

Let's say we have the following entities:

```
    class Car implements ITransformable {
        use Transformable;

        /** @ORM\Id
         * @ORM\Column(type="integer") */
        protected $id;

        /** @Policy\To\Skip
         * @ORM\Column(type="string") */
        protected $keys;

        /** @ORM\OneToMany(targetEntity="Wheel") ... */
        protected $wheels;

        public function getId();
        public function getKeys() ...
        public function setKeys($v) ...
        ...
    }

    class Engine implements ITransformable {
        use Transformable;

        /** @ORM\Id
         * @ORM\Column(type="integer") */
        protected $id;

        /** @Policy\To\Skip
         * @ORM\Column(type="string") */
        protected $serialNumber;

        public function getId();
        public function getSerialNumber() ...
        public function setSerialNumber($v) ...
        ...
    }

    class Wheel implements ITransformable {
        use Transformable;

        /** @ORM\Id
         * @ORM\Column(type="integer") */
        protected $id;

        /** @Policy\Skip
         * @ORM\Column(type="string") */
        protected $brakes;

        /** @ORM\Column(type="string") */
        protected $model;

        public function getId();
        public function getBrakes() ...
        public function setBrakes($v) ...
        public function getModel() ...
        public function setModel($v) ...
        ...
    }
```

Here we have some $car. Let's transform it to array.

```
// Using global policy
$result = $car->toArray();

// Using local policy
$result = $car->toArray((new Policy\Auto)->inside([
    'wheels' => new Policy\To\FetchPaginate(['offset'=0, 'limit'=4, 'fromTail'=false])
]));

// Local policy overrides global policy
$result = $car->toArray((new Policy\Auto)->inside([
    'keys' => new Policy\Auto
]));
```

[Policies Documentation](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Policies)

$result will be something like:

```
[
    '__meta' => ['class' => 'Car'],
    'id' => 1,
    'engine' => [
        '__meta' => ['class' => 'Engine', 'association' => 'OneToOne'],
        'id' => 83
    ],
    'wheels' => [
        '__meta' => ['class' => 'Wheel', 'association' => 'OneToMany'],
        'collection' => [
            [
                '_meta' => ['class' => 'Wheel'],
                'id' => 1,
                'model' => 'A'
            ],
            [
                '_meta' => ['class' => 'Wheel'],
                'id' => 2,
                'model' => 'A'
            ],
            [
                '_meta' => ['class' => 'Wheel'],
                'id' => 3,
                'model' => 'B'
            ],
            [
                '_meta' => ['class' => 'Wheel'],
                'id' => 4,
                'model' => 'B'
            ]
        ]
    ]
]
```

**It's ready for JSON transformation!**

```
    echo json_encode($result);
```

You can also use something like [array2XML](https://github.com/Jeckerson/array2xml) and more.

And we can transform it to Entity again. It will retrieve sub-entities by id using EntityManager. Don't forget to use try-catch block to avoid uncaught exceptions.

```
$carB = new Car();

// Simple way
$carB->fromArray($result, $entityManager);

// With Policy
$carB->fromArray($result, $entityManager, (new Policy\Auto())->inside([
    'keys' => mew Policy\Skip,
    'engine' => (new Policy\Auto())->inside([
        'serialNumber' => new Policy\From\DenyNewUnset
    ]),
    'wheels' => (new Policy\Auto())->inside([
        'brakes' => new Policy\From\Auto
    ])
]);
```

[Policies Documentation](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Policies)

Documentation
-------------

[](#documentation-1)

[Full Documentation](https://github.com/Indaxia/doctrine-orm-transformations/wiki/Indaxia-OTR-Documentation)

---

[Indaxia](http://indaxia.com) / 2016

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 99.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

35

Last Release

3550d ago

Major Versions

0.3.0 → 1.0.02016-11-10

1.0.4 → 2.0.0-stable2016-11-18

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1327866?v=4)[ScorpioT1000](/maintainers/ScorpioT1000)[@ScorpioT1000](https://github.com/ScorpioT1000)

![](https://www.gravatar.com/avatar/84d6d1dc1b5ce39ddba72017777bacbfa13ddee8370c5945af8287befdfcebe1?d=identicon)[Indaxia](/maintainers/Indaxia)

---

Top Contributors

[![ScorpioT1000](https://avatars.githubusercontent.com/u/1327866?v=4)](https://github.com/ScorpioT1000 "ScorpioT1000 (190 commits)")[![tschaible](https://avatars.githubusercontent.com/u/473143?v=4)](https://github.com/tschaible "tschaible (1 commits)")

---

Tags

jsonarrayormdoctrineentity

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/indaxia-doctrine-orm-transformations/health.svg)

```
[![Health](https://phpackages.com/badges/indaxia-doctrine-orm-transformations/health.svg)](https://phpackages.com/packages/indaxia-doctrine-orm-transformations)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58926.6M60](/packages/scienta-doctrine-json-functions)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

12017.1k](/packages/rcsofttech-audit-trail-bundle)[api-platform/doctrine-orm

Doctrine ORM bridge

314.8M105](/packages/api-platform-doctrine-orm)[ergebnis/factory-bot

Provides a fixture factory for doctrine/orm entities.

81709.6k](/packages/ergebnis-factory-bot)[goodwix/doctrine-json-odm

JSON Object-Document Mapping bundle for Symfony and Doctrine

2227.1k](/packages/goodwix-doctrine-json-odm)[andsalves/doctrine-elastic

Elasticsearch Doctrine Adaptation

156.6k](/packages/andsalves-doctrine-elastic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
