Closed thomasvargiu closed 6 years ago
@thomasvargiu
Possible problems with the current implementation
…To do this we should add the method in the Fieldset interface…
I see another problem: the goal should be to remove / extract all methods that can bind an object to a form. This will reduce the complexity of the Fieldset
and Form
classes. Your suggestion will increase the complexity of the classes / interfaces. So it's the wrong direction!
I completely agree with you @froschdesign, working on it I saw too much complexity alredy existing. I'm going to close this PR.
This PR is made to allow to create the object binded to a form only when form data are available.
Imagine the situation where you need to create a new User with a value-object like this:
To create the user we need to pass properties in constructor, so we can't create (and bind) it before to have some validated data from the form.
Of course the best way should be to use a data mapper, but this would be a convenient way to resolve this problem.
Proposal:
Add a callable to create the object only when object is empty and validated data are available.
Usage:
Possible problems with the current implementation
Like for
Form::bind()
, in thesetEmptyObjectInstantiator()
we need to set the value even on thebaseFieldset
. To do this we should add the method in the Fieldset interface, but it would be a BC. Right now I check whether the method exists withmethod_exists()
.Todo:
This is just the first idea on how to implement this feature, proposals and suggestions are welcome.