vklymniuk / dto-mapper-bundle
Symfony mapper bundle, easy way to convert data.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 5 055
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- doctrine/annotations: ^1.13
- symfony-ext/dto-mapper: ^0.4
- symfony/config: ^5.2
- symfony/dependency-injection: ^5.2
- symfony/http-kernel: ^5.2
- symfony/proxy-manager-bridge: ^5.2
Requires (Dev)
- phpunit/phpunit: ^7.4
- roave/security-advisories: dev-master
- symfony/framework-bundle: ^5.2
- symfony/yaml: ^5.2
README
Why use VKMapperBundle?
Bundle makes the process of binding all your data mapping rules a lot more easy by providing annotation declarations. You can extract content from objects and fill objects from raw arrays. Instead of slow and dummy reflection classes, the bundle uses fast and performance optimized code generator. All mapping and DI configurations use native symfony cache and lazy loading.
VKMapperBundle uses customized performance strategies:
- Converts
Object
toarray
- Extracts
Object
toarray
- Puts data from
array
intoObject
Installation
The suggested installation method's via composer:
php composer.phar require symfony-ext/dto-mapper-bundle
Setup
Register bundle in bundles.php file.
<?php return [ VKMapperBundle\VKMapperBundle::class => ['all' => true], ];
Tag directory with classes that you want add to mapping.
Tests\DataFixtures\Dto\: resource: '../../DataFixtures/Dto/*' tags: - { name: dto_mapper.annotated } Tests\DataFixtures\Model\: resource: '../../DataFixtures/Model/*' tags: - { name: dto_mapper.annotated }
Fill in the directory you tagged with annotated classes. Class example:
<?php namespace Tests\DataFixtures\Dto; use VKMapperBundle\Annotation\MappingMeta\SourceClass; use VKMapperBundle\Annotation\MappingMeta\DestinationClass; use VKMapperBundle\Annotation\MappingMeta\Strategy; /** * @SourceClass */ class Source { /** * @Strategy\XPathStrategy(xPath="nodeA.inner.optionA") */ public $nodeA; } /** * @DestinationClass */ class Destination { /** * Contains value optionA. */ public $nodeA; }
Usage
Inject MapperInterface into your service.
<?php use DataMapper\MapperInterface; class DataTransformer { public function __construct(MapperInterface $mapper); }
Convert source to dto object:
<?php use DataMapper\MapperInterface; /** @var MapperInterface $mapper */ $mapper->convert($source, $destination);
Extract content from object into array:
<?php use DataMapper\MapperInterface; /** @var MapperInterface $mapper */ $mapper->extract($object);
Documentation
You can learn more about the bundle possibilities and how to use the VKMapperBundle in the docs.