1. Go to this page and download the library: Download alexpts/php-hydrator 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/ */
alexpts / php-hydrator example snippets
$extractor = new Extractor;
$normalizer = new \PTS\Hydrator\Normalizer;
$model = new Model([
'id' => 1,
'name' => 'Alex'
'email' => '[email protected]'
]);
$rules = [
'id' => [], // prop as dto`s key
'name' => [
'prop' => 'name', // prop is name field in model
],
'email' => [
'get' => 'getEmail', // getter $model->getEmail();
]
];
$rules = $normalizer->normalize($rules);
$extractor->extract($model, $rules)