Call custom __construct on POST
See original GitHub issueI have a simple resource mapped and I can perform the default CRUD operations on it, but I want to create my entity calling a custom constructor like public function __construct(Email $email)
.
Is this even possible with a custom action / event / option in serializer?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Constructs - AWS Cloud Development Kit (AWS CDK) v2
A construct represents a "cloud component" and encapsulates everything AWS CloudFormation needs to create the component. Note. Constructs are part of the ...
Read more >How to run code after constructor in a Lombok builder
If I create my own constructor, that means I'll have to manually create an "all-arg" constructor and maintain it every time there're new...
Read more >How to create an AWS CDK Construct - Towards the Cloud
Constructs encapsulate everything that AWS CloudFormation needs to create the resources and properties. It can contain one or more AWS resources ...
Read more >How to Create Custom Post Types in WordPress - WPBeginner
Beginner's guide to custom post types in WordPress. Learn how to create custom post types in WordPress.
Read more >register_post_type() | Function
$capability_type is used as a base to construct capabilities by default. ... In general, you should always prefix your post types, or specify...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m using a DDD/Hexagonal architecture approach and I would like to decouple my Domain from the Framework, so not having a
__construct
and just call all thesetters
that I need to initialise my entity doesn’t fit in my project.Is it technicaly possible to add this option to the framework in a PR? Maybe someone can take over and code it if enough people find it useful.
Here what I answered him already in Slack, so it can be use as reference and probably to close the issue:
A solution can be to have a custom denormalizer for that class. That way he can create the instance of the class whatever he want. Another solution (if the user can set/choose this kind of constructor parameter) is to have a parameter in the json in the POST body with the same name as the constructor parameter, because the default Serializer ObjectNormalizer use reflection to create the instance and if the constructor has parameters, it tries to denormalize them from the input.