Skip to content

Avariya/dto-mapper-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Symfony dto-mapper-bundle

Build Status

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 to array
  • Extracts Object to array
  • Puts data from array into Object

Installation

The suggested installation method's via composer:

php composer.phar require vklymniuk/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.

About

Symfony dto-mapper-bundle

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages