PHP code example of neuron-php / dto
1. Go to this page and download the library: Download neuron-php/dto library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
neuron-php / dto example snippets
$DtoFactory = new DtoFactory( 'examples/test.yaml' );
$Dto = $DtoFactory->create();
$Dto->username = 'Fred';
$Dto->address->street = '13 Mockingbird lane.'
$Dto->validate()
print_r( $Dto->getErrors() );
print_r( $Dto->getParameter( 'username' )->getErrors() );
$MapperFactory = new \Neuron\Dto\MapperFactory( 'examples/test-json-map.yaml' );
$Mapper = $MapperFactory->create();
$Payload = [
'user' => [
'name' => 'test',
'password' => 'testtest',
'age' => 40,
'birthday' => '1978-01-01',
'address' => [
'street' => '13 Mocking',
'city' => 'Mockingbird Heights',
'state' => 'CA',
'zip' => '90210'
],
'inventory' => [
[
'name' => 'shoes',
'count' => 1,
'attributes' => [
[
'name' => 'leather',
],
[
'name' => 'boot',
],
[
'name' =>'smelly'
]
]
],
[
'name' => 'jackets',
'count' => 2
],
[
'name' => 'pants',
'count' => 3
]
]
]
];
$Mapper->map( $Dto, $Payload );
echo $Dto->username; // outputs 'test'
echo $Dto->inventory[ 1 ]->amount; // outputs 3
echo $Dto->inventory[ 0 ]->attributes[ 1 ]->name; // outputs 'boot'