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
Split Instantiator #395
base: 1.x
Are you sure you want to change the base?
Split Instantiator #395
Conversation
This is a very minor BC break if using the `Instantiator` in an undocumented way.
@nikophil, could you give this an early, high-level review? |
if (!$hydrator instanceof Hydrator) { | ||
$hydrator = (new Hydrator())->using($hydrator); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually a nice technique 👍
{ | ||
$instantiator = $this->instantiator ?? self::configuration()->instantiator(); | ||
|
||
if (!$instantiator instanceof Instantiator && !$this->hydrator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: if using a closure or non-Instantiator callable for the instantiator, the hydrator isn't used.
shouldn't we throw an error if we detect an hydrator which is not the default hydrator in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps but then we'd break the possibility of fixing cascade persist with custom instantiators. One problem at a time though. I'll throw an exception for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, that's quite a complex problem 🤯
Closes #388.
This PR splits the Instantator into 2 separate objects:
Instantiator
: now only create the object (using constructor/no constructor/callback/named constructor)Hydrator
: takes the instantiated object and hydrates it with the attributes not used to instantiateThe following is now possible:
Note: if using a closure or non-Instantiator callable for the instantiator, the hydrator isn't used. This is to avoid the unset issue discussed here. I think this is better for DX (not requiring you create a custom instantiator and hydrator) but might cause problems when trying to solve the cascade: persist problem in #312.
Todo: