2017 © Pedro Peláez
 

library filler-dto

Retrieve and set properties from and to a DTO

image

liuggio/filler-dto

Retrieve and set properties from and to a DTO

  • Wednesday, April 20, 2016
  • by liuggio
  • Repository
  • 2 Watchers
  • 5 Stars
  • 37,956 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 11 % Grown

The README.md

Filler

It helps you to bridge DTOs and Model Entities., (*1)

Fill or retrieve properties from and to DTO objects!, (*2)

filler-dto on packagist, (*3)

Latest Stable Version Latest Unstable Version Total Downloads, (*4)

Fast

It doesn't use the \Reflection., (*5)

Before the Cure

``` php class Cart { private $a; private $b; private $c;, (*6)

private function __construct($a, $b, $c)
{
    $this->a = $a;
    $this->b = $b;
    $this->c = $c;
}

public static function startShipping(StartShippingData $data)
{
    return new self($data->a, $data->b, null);
}

public static function addProduct(AddProductData $data)
{
    return new self(null, $data->b, $data->cs);
}

}, (*7)


## After the Cure ``` php class Cart { use PropertyTrait; private $a; private $b; private $c; private function __construct($dto) { $this->fillProperties($dto); } public static function startShipping(StartShippingData $data) { return new self($data); } public static function addProduct(AddProductData $data) { return new self($data); } } class StartShippingData { public $a; public $b; } class AddProductData { public $b; public $c; }

From Request

Do you want to map an object from the Request?, (*8)

``` php use Liuggio\Filler\HTTPPropertyTrait;, (*9)

class StartShippingDTO { use HTTPPropertyTrait;, (*10)

private $developer;

public function __construct(Request $request)
{
    $this->fillPropertiesFromRequest($request);
}

... }, (*11)

Class Controller { public function startShippingAction(Request $request) { $startShipping = new StartShippingDTO($request);, (*12)

    if ($this->isValid($startShipping)) ...
}

}, (*13)


### Copy 2 objects You can also use it for copy properties between 2 objects ``` php use HTTPPropertyTrait; $to = new DTOFromRequest(); $this->fillPropertiesFromRequest($request, $to); // the $to object has all the var from the Request

Differences?

We needed it for an edge case, but then we have decided to release it because if you are used to develop with the Command pattern, this lib could help you to develop faster app., (*14)

More info at: verraes:decoupling-symfony2-forms-from-entities, (*15)

Install

composer require liuggio/filler-dto dev-master, (*16)

API

trait PropertyTrait
   fillProperties($dto)
   getAllProperties($filter = null)

trait HTTPPropertyTrait
    fillPropertiesFromRequest(Request $request, $name = '')
    copyPropertiesFromRequest(Request $request, $to)

Example

Please have a look to the tests and tests/Fixtures folders :), (*17)

Compatibility

  • >= 5.4
  • hhvm

The Versions

20/04 2016

dev-master

9999999-dev

Retrieve and set properties from and to a DTO

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

20/04 2016

dev-rename

dev-rename

Retrieve and set properties from and to a DTO

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

20/04 2016

0.1.0

0.1.0.0

Retrieve and set properties from and to a DTO

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

28/08 2014

dev-test

dev-test

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires