2017 © Pedro Peláez
 

library entity-merger

Merge arrays into your object entities

image

orbitale/entity-merger

Merge arrays into your object entities

  • Thursday, July 6, 2017
  • by Pierstoval
  • Repository
  • 1 Watchers
  • 11 Stars
  • 4,184 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 12 % Grown

The README.md

:warning: This package is unmaintained. Please look at better solutions, like serializers., (*1)

Entity Merger

Entity/object merger for PHP apps., (*2)

Installation

Install with Composer, it's the best packages manager you can have:, (*3)

composer require orbitale/entity-merger

Requirements

Basic usage

Note: The EntityMerger only works with mapped objects. The properties must exist, and it cannot use magic methods to retrieve datas., (*4)

use Orbitale\Component\EntityMerger\EntityMerger;

$merger = new EntityMerger();

$object = new Object();
$object->setField(null);

$postedDatas = array('field' => 'value');

$merger->merge($object, $postedDatas);

echo $object->getField(); // Shows "value"

Using the Doctrine ORM ObjectManager

The EntityMerger accepts a Doctrine\ORM\ObjectManager as first argument, like the EntityManager for instance. This allows better and deeper merging when using ORM-mapped entities, by automatically using the Doctrine Metadatas to detect property types. If you are using the EntityMerger in an application that uses Doctrine, it is highly recommended to inject the ObjectManager to use your mapping as type reference for each of your class properties., (*5)

If no ObjectManager is used, the EntityMerger will perform its own checks with its own metadatas manager, but it is obviously less performant than the Doctrine one, because it cannot assume that you are attempting to merge an entity. It instead makes its checks based on PHPDoc, class imports and default parameters, so be sure to perfectly write your PHPDoc in your class if you do not want to use the ObjectManager!, (*6)

Using the Serializer

The EntityMerger accepts a Serializer as second argument. It can both use the native Symfony Serializer and the powerful JMS Serializer., (*7)

Note: If you are using Symfony <2.5 and still want to use the serializer, then you'll have to switch to the JMS' one, or you may have some unexpected behavior because of the lack of the PropertyNormalizer class., (*8)

Using the Serializer allows you to merge two objects in the specified one by serializing the dataObject parameter into an array, and using it as values to merge in your object/entity., (*9)

Note: Of course you can use your own serialization method to inject the dataObject as array in your merge process., (*10)

Advanced usage

Merge two objects in the first one (must use any serializer):, (*11)

use Orbitale\Component\EntityMerger\EntityMerger;

$merger = new EntityMerger(null, $serializer);

$baseObject = new Object;
$baseObject->field = null;

$anotherObject = new Object();
$anotherObject->field = 'value';

$merger->merge($baseObject, $anotherObject);

echo $baseObject->field; // Shows "value"

The Versions

06/07 2017
06/07 2017
15/07 2015

v0.5

0.5.0.0 https://github.com/Orbitale/EntityMerger

Merge arrays into your object entities

  Sources   Download

MIT

The Requires

 

The Development Requires

orm merge doctrine entity symfony

30/03 2015

v0.4

0.4.0.0 https://github.com/Orbitale/EntityMerger

Merge arrays into your object entities

  Sources   Download

MIT

The Requires

 

The Development Requires

orm merge doctrine entity symfony

14/03 2015

v0.3

0.3.0.0 https://github.com/Orbitale/EntityMerger

Merge arrays into your object entities

  Sources   Download

MIT

The Requires

 

The Development Requires

orm merge doctrine entity symfony

25/02 2015

v0.2

0.2.0.0 https://github.com/Pierstoval/EntityMerger

Merge arrays into your object entities

  Sources   Download

MIT

The Requires

 

The Development Requires

orm merge doctrine entity symfony

23/01 2015

v0.1

0.1.0.0 https://github.com/Pierstoval/EntityMerger

Merge arrays into your object entities

  Sources   Download

MIT

The Requires

 

The Development Requires

orm merge doctrine entity symfony