Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ContainerObjectContructor #979

Closed
wants to merge 1 commit into from

Conversation

MaksSlesarenko
Copy link

Add new ContainerObjectContructor that allows to create new objects from di container services. For ex in symfony this will allow autowiring in deserialized entity

Q A
Bug fix? no
New feature? yes
Doc updated no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets no
License MIT

Add new ContainerObjectContructor that allows to create new objects from di container services. For ex in symfony this will allow autowiring in deserialized entity
@goetas
Copy link
Collaborator

goetas commented Jul 24, 2018

Hi.
Thanks for the PR.

I'm not sure about this feature.... autowiring of an entity? Can you explain a bit better the use case?

Is your PR related to #79 ?

@Majkl578
Copy link
Contributor

I am against this addition, it breaks assumptions of serialization/deserialization concept: both of these processes are meant to bypass the constructor.

@MaksSlesarenko
Copy link
Author

@goetas
I do not think it is related #79

You see when using ParamConverter I can convert request params to DTO object and it also gets validated, so in controller I will receive

public function putPostAction(Post $post, ConstraintViolationListInterface $validationErrors)

  • deserialized object and validation errors. That is good part.

Bad part is that current implementation of JMS/Serialiser does this

$object = new $className

This code breaks dependency inversion principle and it constructs object from class by itself, leaving me without any options to bypass a service or model manager to validate DTO object against database.

https://symfony.com/doc/master/bundles/FOSRestBundle/request_body_converter_listener.html

@MaksSlesarenko
Copy link
Author

Maybe this should be placed in serializer-bundle, to fix dependency inversion principle that is used by symfony ?

@goetas
Copy link
Collaborator

goetas commented Jul 24, 2018

@MaksSlesarenko

Bad part is that current implementation of JMS/Serialiser does this
$object = new $className

not true. jms serializer deos not call the constructor, it uses reflection to create a new object.

@goetas
Copy link
Collaborator

goetas commented Jul 24, 2018

@MaksSlesarenko
What you are doing is more a FOS rest bundle feature to allow validation and deserialization of an object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants