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?
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.
Most helpful comment
Use the decorator pattern instead of inheritance: https://symfony.com/doc/current/service_container/service_decoration.html