1. Go to this page and download the library: Download cerbero/transformer 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/ */
cerbero / transformer example snippets
use Cerbero\Transformer\AbstractTransformer;
class MyTransformer extends AbstractTransformer
{
protected function getStructure()
{
// the array structure you want to obtain
}
}
protected function getStructure()
{
return [
'key' => 'some.nested.key',
'favorites' => [
'color' => 'color',
'number' => 'number int',
],
'is_admin' => 'adminPermission bool',
'status' => 'status enum:denied=0,accepted=1,pending=2',
'important.date' => 'date date:Y-m-d',
'cents' => 'cents substr:1|float',
// The `unneeded` key is not defined, so it will be ignored
'json' => 'json arr',
];
}
$transformer = new MyTransformer($data);
$transformed = $transformer->transform();
// or by using the static factory method:
$transformed = MyTransformer::from($data)->transform();
$transformer = new MyTransformer($data);
$transformed = $transformer->transformInto(new DataTransferObject);
// or by using the static factory method:
$transformed = MyTransformer::from($data)->transformInto(new DataTransferObject);
protected function prefix($prefix)
{
return $prefix . $this->value;
}
use Cerbero\Transformer\Transformations\AbstractTransformation;
class PrefixTransformation extends AbstractTransformation
{
public function apply(array $parameters)
{
return $parameters[0] . $this->value;
}
}
protected function getCustomTransformationNamespace(): string
{
return 'My\Namespace';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.