mickprev/duplicator

Library for duplicate an object (or an array of objects) using PHP annotations.

v1.0.0 2019-10-28 10:38 UTC

This package is auto-updated.

Last update: 2021-12-28 16:16:37 UTC


README

Library for duplicate an object (or an array of objects) using PHP annotations.

Getting started

composer require mickprev/duplicator
use MickPrev\Duplicator\Annotation\Groups;

class Product
{
    // ...
    /**
      * @Groups({"my_group"})
      */
     private $title;
    // ...
}

$duplicator = new ChainDuplicator(
    [
        new IterableDuplicator(),
        new ObjectDuplicator(),
        new DefaultDuplicator(),
    ]
);

$newProduct = $duplicator->duplicate($originalProduct, ['groups' => ['my_group']]);

What the duplicator does not do yet

  • Duplicate object with arguments in the constructor that have no default value.
  • 'Iterable' duplicator returns a value with the same type that the value to duplicate instead of always return an array.

Extras