liuggio / filler-dto
Retrieve and set properties from and to a DTO
Installs: 105 005
Dependents: 2
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.2
Requires (Dev)
- phpunit/phpunit: ~4
- symfony/http-foundation: ~2.7
Suggests
- symfony/http-foundation: Install symfony http-foundation in order to use the Response filler
This package is auto-updated.
Last update: 2024-12-18 23:27:19 UTC
README
It helps you to bridge DTOs and Model Entities.
Fill or retrieve properties from and to DTO objects!
filler-dto
on packagist
Fast
It doesn't use the \Reflection.
Before the Cure
class Cart { private $a; private $b; private $c; 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); } }
After the Cure
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
?
use Liuggio\Filler\HTTPPropertyTrait; class StartShippingDTO { use HTTPPropertyTrait; private $developer; public function __construct(Request $request) { $this->fillPropertiesFromRequest($request); } ... } Class Controller { public function startShippingAction(Request $request) { $startShipping = new StartShippingDTO($request); if ($this->isValid($startShipping)) ... } }
Copy 2 objects
You can also use it for copy properties between 2 objects
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.
More info at: verraes:decoupling-symfony2-forms-from-entities
Install
composer require liuggio/filler-dto dev-master
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 :)
Compatibility
-
= 5.4
- hhvm