abacaphiliac / zend-transformer
Extract and Hydrate, plus secret sauce.
0.1.1
2017-03-06 03:33 UTC
Requires
- php: >=5.5
- beberlei/assert: ^2.6
- igorw/get-in: ^1.0
- zendframework/zend-filter: ^2.0
- zendframework/zend-hydrator: ^2.0
- zendframework/zend-modulemanager: ^2.0
- zendframework/zend-mvc: ^2.0
- zendframework/zend-servicemanager: ^2.0
- zendframework/zend-validator: ^2.0
Requires (Dev)
- humbug/humbug: 1.0.0-alpha2
- jakub-onderka/php-parallel-lint: ^0.9
- phing/phing: ^2.15
- phpunit/phpunit: ^5.7|^4.8
- squizlabs/php_codesniffer: ^2.8
This package is auto-updated.
Last update: 2024-12-25 12:26:13 UTC
README
abacaphiliac/zend-transformer
An object-to-object ETL package, based on Zend Framework extraction, hydration, and validation abstractions.
Includes a PluginManager for registering transformation specs via application config, and a ZF2 module to wire up all configuration.
Requires >=php55, and supports ZF2 but not ZF3 at this time.
Installation
composer require abacaphiliac/zend-transformer
Usage
Register transformers in your application config:
return [ 'abacaphiliac/zend-transformer' => [ 'transformers' => [ 'SimpleFooBarToFizBuz' => [ 'inputClass' => \AbacaphiliacTest\FooBar::class, 'keyMap' => [ 'foo' => 'fiz', 'bar' => 'buz', ], 'outputClass' => \AbacaphiliacTest\FizBuz::class, ], ], ], ];
Transform some data!
$transformers = $serviceLocator->get('TransformerManager'); $transformer = $transformers->get('SimpleFooBarToFizBuz'); $input = new \AbacaphiliacTest\FooBar('Foo', 'Bar'); $output = $transformer->transform($input, \AbacaphiliacTest\FizBuz::class);
Complex configuration:
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, ], ], ];
Contributing
composer update && vendor/bin/phpunit
This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.