PHP code example of abacaphiliac / zend-transformer
1. Go to this page and download the library: Download abacaphiliac/zend-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/ */
abacaphiliac / zend-transformer example snippets
return [
'abacaphiliac/zend-transformer' => [
'transformers' => [
'SimpleFooBarToFizBuz' => [
'inputClass' => \AbacaphiliacTest\FooBar::class,
'keyMap' => [
'foo' => 'fiz',
'bar' => 'buz',
],
'outputClass' => \AbacaphiliacTest\FizBuz::class,
],
],
],
];
$transformers = $serviceLocator->get('TransformerManager');
$transformer = $transformers->get('SimpleFooBarToFizBuz');
$input = new \AbacaphiliacTest\FooBar('Foo', 'Bar');
$output = $transformer->transform($input, \AbacaphiliacTest\FizBuz::class);
return [
'abacaphiliac/zend-transformer' => [
'transformers' => [
'ComplexFooBarToFizBuz' => [
'input_validator' => 'MyInputValidatorFromValidatorManager',
'extractor' => 'MyExractorFromHydratorManager',
'transformer' => 'MyTransformerFromServiceManager',
'hydrator' => 'MyHydratorFromHydratorManager',
'output_validator' => 'MyOutputValidatorFromValidatorManager',
],
],
],
'service_manager' => [
'invokables' => [
'MyTransformerFromServiceManager' => function (array $data) {
// Don't do this in production, as the config cannot be cached.
return [];
},
],
],
'validators' => [
'invokables' => [
'MyInputValidatorFromValidatorManager' => \Zend\Validator\ValidatorChain::class,
'MyOutputValidatorFromValidatorManager' => \Zend\Validator\ValidatorChain::class,
],
],
'hydrators' => [
'invokables' => [
'MyExractorFromHydratorManager' => \Zend\Hydrator\ClassMethods::class,
'MyHydratorFromHydratorManager' => \Zend\Hydrator\ClassMethods::class,
],
],
];