2017 © Pedro Peláez
 

library doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

image

pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  • Friday, March 16, 2018
  • by pmill
  • Repository
  • 3 Watchers
  • 13 Stars
  • 7,607 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 9 Forks
  • 1 Open issues
  • 7 Versions
  • 32 % Grown

The README.md

Doctrine Array to Entity Hydrator

Introduction

Build Status Test Coverage Downloads, (*1)

A hydrator for doctrine 2 that converts an array to the entity of your choice., (*2)

Installing via Composer

The recommended way to install is through Composer., (*3)

composer require pmill/doctrine-array-hydrator

Example

Given this doctrine entity:, (*4)

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use pmill\Doctrine\Hydrator\Test\Fixture\Company;
use pmill\Doctrine\Hydrator\Test\Fixture\Permission;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User
{
   /**
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue
    * 
    * @var int
    */
    protected $id;

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

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

    /**
     * @ManyToOne(targetEntity="Company")
     * 
     * @var Company
     */
    protected $company;

    /**
     * @OneToMany(targetEntity="Permission", mappedBy="product")
     * 
     * @var Permission[]
     */
    protected $permissions;
}

We can populate this object with an array, for example:, (*5)

$data = [
    'name'        => 'Fred Jones',
    'email'       => 'fred@example.com',
    'company'     => 2,
    'permissions' => [1, 2, 3, 4]
];

$hydrator = new \pmill\Doctrine\Hydrator\ArrayHydrator($entityManager);
$entity   = $hydrator->hydrate('App\Entity\User', $data);

We can populate user with JSON API resource data Documentation, (*6)

$data = [
    'attributes'    => [
        'name'  => 'Fred Jones',
        'email' => 'fred@example.com',
    ],
    'relationships' => [
        'company'     => [
            'data' => ['id' => 1, 'type' => 'company'],
        ],
        'permissions' => [
            'data' => [
                ['id' => 1, 'type' => 'permission'],
                ['id' => 2, 'type' => 'permission'],
                ['id' => 3, 'type' => 'permission'],
                ['id' => 4, 'type' => 'permission'],
                ['name' => 'New permission']
            ]
        ]
    ]
];

$hydrator = new \pmill\Doctrine\Hydrator\JsonApiHydrator($entityManager);
$entity   = $hydrator->hydrate('App\Entity\User', $data);

Doctrine Array to Entity Hydrator Copyright (c) 2015 pmill (dev.pmill@gmail.com) All rights reserved., (*7)

The Versions

16/03 2018

dev-master

9999999-dev https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

16/03 2018

v0.1.5

0.1.5.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

23/11 2017

v0.1.4

0.1.4.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

10/11 2017

v0.1.3

0.1.3.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

17/02 2016

v0.1.2

0.1.2.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

28/11 2015

0.1.1

0.1.1.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator

18/11 2015

v0.1.0

0.1.0.0 https://github.com/pmill/doctrine-array-hydrator

An array to entity hydrator for Doctrine 2 entities

  Sources   Download

MIT

The Requires

 

The Development Requires

php array doctrine hydrator