grifix/normalizer-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Grifix normalizer Symfony integration

4.0.0 2022-11-23 08:17 UTC

This package is auto-updated.

Last update: 2023-07-26 07:06:48 UTC


README

Integration grifix/normalizer with Symfony

Installation

composer require grifix/normalizer-bundle

Usage

  • Read the Grifix Normalizer documentation
  • Inject normalizer as a dependency or get it from the Symfony Container instead of creating it by Normalizer::create()
  • use packages/grifix_normalizer.yaml instead of methods:
    • registerCustomObjectNormalizer
    • registerDefaultObjectNormalizer
  • instead of registerDependency method usage, register dependency by Symfony Container

Default normalizer configuration example:

Open packages/grifix_normalizer.yaml and add the following configuration to the grifix_normalizer.normalizers section:

   grifix_normalizer:
     normalizers:
       #date
       - name: date
         class: Grifix\NormalizerBundle\Tests\Dummies\DateNormalizer
         schemas:
           - - property: value
               type: string
       #entity
       - name: entity
         version_converter: Grifix\NormalizerBundle\Tests\Dummies\EntityVersionConverter
         object_class: Grifix\NormalizerBundle\Tests\Dummies\Entity
         dependencies:
           - service
         schemas:
           #version 1
           - - property: name
               type: string
             - property: dates
               type: array_of_objects
               allowed_normalizers: [date]
             - property: public
               type: boolean
             - property: number
               type: integer
             - property: price
               type: number
             - property: notes
               type: array
             - property: mixed
               type: mixed_object
           #version 2
           - - property: name
               type: string
             - property: dates
               type: array_of_objects
               allowed_normalizers: [date]
             - property: public
               type: boolean
             - property: number
               type: integer
             - property: price
               type: number
             - property: notes
               type: array
             - property: mixed
               type: mixed_object
             - property: date
               type: object
               allowed_normalizers: [date]
               nullable: true
       #vo
       - name: vo
         object_class: Grifix\NormalizerBundle\Tests\Dummies\Vo
         schemas:
           - - property: value
               type: string
  • register Grifix\NormalizerBundle\Tests\Dummies\EntityVersionConverter as a public service
  • register Entity dependencies as public services

Custom normalizer configuration example:

Open packages/grifix_normalizer.yaml and add the following configuration to the grifix_normalizer.normalizers section:

  #date
  - name: date
    class: Grifix\NormalizerBundle\Tests\Dummies\DateNormalizer
    schemas:
      - - property: value
          type: string