question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call custom __construct on POST

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
regniblodcommented, May 14, 2017

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 the setters 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.

2reactions
magarzoncommented, May 22, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found