Api-platform: Make ApiPlatform\Core\Hydra\Serializer\ErrorNormalizer not final

Created on 6 Jun 2017  路  2Comments  路  Source: api-platform/api-platform

I wanted to overwrite ApiPlatform\Core\Hydra\Serializer\ErrorNormalizer to make normalize() to keep the hydra:description even in production mode. The code here is nice, so theoretically I only have to extend ApiPlatform\Core\Hydra\Serializer\ErrorNormalizer and overwrite getErrorMessage() that is provided by ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait. But unfortunately ApiPlatform\Core\Hydra\Serializer\ErrorNormalizer is final so I have to copy the whole service to achieve my goal.

api_platform.hydra.normalizer.error:
    public: false
    class: AppBundle\Serializer\ErrorNormalizer
    arguments: [ '@api_platform.router', '%kernel.debug%']
    tags: [ { name: serializer.normalizer, priority: 32 } ]

So, is there a better way to achieve my goal or should the final keyword get removed to make my boilerplate code obsolete again?

question

Most helpful comment

Use the decorator pattern instead of inheritance: https://symfony.com/doc/current/service_container/service_decoration.html

All 2 comments

Use the decorator pattern instead of inheritance: https://symfony.com/doc/current/service_container/service_decoration.html

@blaues0cke Like @meyerbaptiste said, I think this will be good for you.

Was this page helpful?
0 / 5 - 0 ratings