You are viewing documentation for an outdated version. It is no longer supported!
Populate
You can populate your DTO using an array.
// property-name => value array
$data = [
'name' => 'Timmy Jones',
'age' => 32
];
// Create instance and invoke populate
$person = new Person();
$person->populate($data); // setName() and setAge() are invoked with the given values
__construct
Via If you are extending the default DTO abstraction, then you can also pass in an array in the constructor.
// property-name => value array
$data = [
'name' => 'Carmen Rock',
'age' => 25
];
// Create instance and invoke populate
$person = new Person($data);
Export to array
Each DTO can be exported to an array.
$properties = $person->toArray();
var_dump($properties); // Will output a "property-name => value" list
// Example:
// [
// 'name' => 'Timmy'
// 'age' => 16
// ]