-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
[2.0] [Feature-request] Provide InitializedObjectConstructor as default #775
Comments
Since |
@goetas the problem of using forms is that you have to write form classes instead of describing the serialized presentation of entities. It's like suggestion to manually map DB data to entities but not using the Doctrine2 hydration metadata |
I know than it is not an optimal solution... at the moment the serializer is not really powerful to update objects (as example, can not easily append items to a collection or deal with different data-formats where normalization is needed). On the other hand, symfony form is really good at it, but does not offer serialization, that is why I like to combine the two of them. The provided object constructors are domain independent...
class InstantiatedObjectsObjectConstructor implements ObjectConstructorInterface
{
private $registry = array();
private $fallbackConstructor;
public function __construct(ObjectConstructorInterface $fallbackConstructor)
{
$this->fallbackConstructor = $fallbackConstructor;
}
public function add($id, $object)
{
$this->registry[$id] = $object;
}
public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context)
{
$id = $data['id']; // or something better
if (isset($this->registry[$id])) {
return $this->registry[$id];
} else {
return $this->fallbackConstructor->construct(...);
}
}
} This is not a great solution, but is more flexible and can work for a more deep object graph. |
This is the problem since there can be a domain logic and defaults in the constructor, so this forbids any domain logic here. Passing the instance via context seems legit too me, do not see anything weird here (excluding excplicit named method would be nice). Doctrine has sort of "Hints" for this which looks much more weird than named context features. Just an idea - can we define a constructor type not at global level, but on the metadata one? I.e I see nothing bad in instantiating Value-Objects with current unserializing constructor, but higher-class business logic object can be passed as is. offtop question: do we involve any kind of naming strategy here beforehand? |
actually there should be a bug (not verified) about it, see #734
this sounds a good idea... probably something as /**
* @Constructor("unserialize|doctrine|any_other_name")
*/
protected $user; |
Can we reopen and leave this as RFC idea before 2.0 (or later release)? |
Crating a new RFC for 1.x branch sounds good (and keeping this closed). The suggested approach ( |
I'm using Thanks |
as said in #775 (comment)
|
It is really hard to understand that you cannot to deserialize into existing object without additional configuration or using doctrine
Also this is weird that such useful thing lives within fixtures.
If it is applicable for 1.x branch (since it is somehow backward compatible), it would be nice
The text was updated successfully, but these errors were encountered: