Git Product home page Git Product logo

automapper-bundle-1's Introduction

AutoMapper Bundle

The component ships a Bundle to allow a quick integration with Symfony. To use it, you just have to add the main bundle class to your config/bundles.php file.

return [
    // ...
    AutoMapper\Bundle\AutoMapperBundle::class => ['all' => true],
];

Then configure the bundle to your needs, for example:

automapper:
  autoregister: true
  mappings:
    - source: AutoMapper\Bundle\Tests\Fixtures\User
      target: AutoMapper\Bundle\Tests\Fixtures\UserDTO
      pass: DummyApp\UserConfigurationPass

Possible properties:

  • normalizer (default: false): A boolean which indicate if we inject the AutoMapperNormalizer;
  • cache_dir (default: %kernel.cache_dir%/automapper): This settings allows you to customize the output directory for generated mappers;
  • mappings: This option allows you to customize Mapper metadata, you have to specify source & target data types and related configuration using pass field. This configuration should implements AutoMapper\Bundle\Configuration\ConfigurationPassInterface.
  • allow_readonly_target_to_populate (default: false): Will throw an exception if you use a readonly class as target to populate if set to false.

Normalizer Bridge

A Normalizer Bridge is available, aiming to be 100% feature compatible with the ObjectNormalizer of the symfony/serializer component. The goal of this bridge is not to replace the ObjectNormalizer but rather providing a very fast alternative.

As shown in the benchmark above, using this bridge leads up to more than 8x speed increase in normalization.

Future consideration

Things that could be done later:

  • symfony/form bridge for mapping request data to object
  • symfony/validator integration:

PHP 7.4 may give a problem to the symfony/validator component where typed properties can be problem, given a class like this:

class Foo {
    /** @Assert\NotNull() */
    public int $foo;
}

An user may send a null value (in a form by example or JSON), and PHP will raise an error before the validation, since the validation occurs on the mapped object.

This component can help resolving this case with the actual behavior:

  • Create a dummy class with the same properties as Foo but without type checking
  • Mapping user data to this dummy class (using the automapper component)
  • Validating this dummy class with the metadata from the Foo class
  • Mapping the dummy object to the foo class (using the automapper component)

Feel free to challenge as much as possible.

automapper-bundle-1's People

Contributors

korbeil avatar nikophil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.