In my previous post we saw, in the context of a REST application created with Symfony and PHP8, how to obtain a DTO as a parameter of an action, deserializing the json content of the request body with the Symfony serializer component and exploiting the information available in the URI using a PHP8 attribute.
The DTO thus obtained, however, contains only primitive data, so if in the request there are references to objects of our domain, these will remain as such and will not be converted into the objects themselves.
To achieve this we could use a de/serialization library, such…
Version 8 of PHP was released just over 2 months ago, and among the most important changes there is the introduction of attributes, which will allow you to create with native syntax what has been achieved up to now with PHPDoc and Doctrine annotations.
The Symfony framework makes extensive use of them, for example to specify routing directly in controllers and validation rules in entities. Version 5.2 already supports PHP8 attributes in both cases.
Symfony Value Resolvers are a mechanism that allows, for example, to obtain as arguments of an action: