2017 © Pedro Peláez
 

library mapping-bundle

Symfony bundle for mapping library

image

deetrych/mapping-bundle

Symfony bundle for mapping library

  • Saturday, October 7, 2017
  • by matigda
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Mapping bundle

This bundle uses mapping library to create services for convenient mapping., (*1)

Read model use case examples

Let's say you had data stored in Redis as a JSON and You were mapping it to some ViewDTO. Your code probably looks similar to this:, (*2)

$jsonProductData = $this->redisConnection->get($itemKey);

$serializedProductData = json_decode($jsonProductData, true);

return new ProductViewDTO(
    $serializedProductData['price']['value'],
    $serializedProductData['price']['currency'],
    $serializedProductData['details']['material'],
    $serializedProductData['details']['sku'],
    $serializedProductData['description'],
    $serializedProductData['productPhotos']
);

With this config:, (*3)

deetrych_mapping:
    read_models:
        product_view:    # service that will be created will have "deetrych.read_model.mapper.product_view" id
            fields:
                priceValue:
                    path: price.value
                priceCurrency:
                    path: price.currency
                material:
                    path: details.material
                sku:
                    path: details.sku
                description:
                    path: description
                productPhotos:
                    path: productPhotos
            type: json
            model: Vendor\ProductViewDTO

Your code will look like that:, (*4)

return $this->mapper->map($this->redisConnection->get($itemKey));

Write model use case examples

Ok, so let's say You want to save your Domain Model in Redis as json string, but You don't really want to add unnecessary getters in the Model:, (*5)

deetrych_mapping:
    write_models:
        product:  # service that will be created will have "deetrych.write_model.mapper.product" id
            fields:
                price.value:
                    path: price.value
                price.currency:
                    path: price.currency
                details.material:
                    path: details.material
                details.sku:
                    path: details.sku
                description:
                    path: details.description
                productPhotos:
                    path: details.productPhotos
            type: json

( This config assume that your Product has price and details fields, as well as the fact that those fields are objects which also have given fields), (*6)

And your code will look like that:, (*7)

$this->redisConnection->set($identifier, $this->mapper->map($product));

Extending mappers

When extending mappers You need to provide all the mappers You want to use:, (*8)


deetrych_mapping: type_map: write_models: array: Deetrych\Mapping\Mapper\WriteModel\ArrayMapper json: Deetrych\Mapping\Mapper\WriteModel\JsonMapper elastic: Deetrych\Mapping\Decorator\ElasticMapperDecorator mixed: Vendor\YourMapper # <- this class has to extend Deetrych\Mapping\Mapper\WriteModel\AbstractMapper

The Versions

07/10 2017

dev-master

9999999-dev

Symfony bundle for mapping library

  Sources   Download

The Requires

 

The Development Requires

by Avatar mateusz