-
Notifications
You must be signed in to change notification settings - Fork 2.5k
standard hydrator idea #6894
standard hydrator idea #6894
Conversation
Very interesting approach, though I'm not sure if I like it (I still have to think about it). Not agreeing with the naming: should probably be a |
I like the concept, but not the implementation as it will cause confusion. One should not use the DiC to map a object to it's hydrator. @Ocramius Not sure why you tagged this with |
It effectively introduces the |
@Ocramius Uhm |
Urgh, that sucks :-\ |
Now, I am thinking to create a service factory for this hydrator here . Any thoughts? |
5ce86ea
to
89d5c86
Compare
I created a factory too. Please do comment. :) |
@ojhaujjwal I'd say it fits a module, not the standard |
are you disagreeing with adding the factory in the Mvc component? I really didn't get it. |
@ojhaujjwal Yes, it does not belong in the mvc component. |
But, wait. How do other services like |
I do not see why this is better that just using the hydrator manager to get a hydrator for your entity class. Which is basically what you do when you use the StandardHydrator Class. |
Any more comments? |
This could actually replace the functionality we have in our I, too, am not a fan of the verbiage
and I'll include this in 2.4 (and update zf-hal to make use of it!). |
@weierophinney can you please explain why this component belongs in mvc ? I don't see a reason to include it just so something can be removed from a apigility component ? |
@weierophinney What's with the name DiscoveryHydrator? |
|
4797b43
to
003e508
Compare
@weierophinney rebasing part is done! :D |
8a85c23
to
eaae2f0
Compare
I missed that the factory was in the MVC component - it should be under the
@macnibblet — It's not just Apigility; I've actually seen a number of people wanting to use the hydrator mapping aspect of zf-hal for other purposes, but it's not separated. This would provide that separation. It would also allow us to use the mapping aspect for vanilla JSON responses, for which we don't have a serialization strategy (other than JsonSerializable) in Apigility currently due to the aforementioned coupling in zf-hal — but in a way that could be put into a specialized JSON renderer.
Um, @sandrokeil, I don't know... you're the first to bring that up. Are you suggesting it as a name for the hydrator? |
@weierophinney Yes, it's another suggestion for the hydrator name. |
{ | ||
$class = get_class($object); | ||
if (!$this->hydrators->has($class)) { | ||
throw new Exception\InvalidArgumentException(sprintf('Hydrator service does not exists for class %s', $class)); |
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.
I think this check should be removed, as it can lead to unpredictable behaviour as explained in zfcampus/zf-hal#86
The plugin validation is already done by the plugin manager, calling has
on a pluginmanager with $autoAddInvokableClass
on by default can lead to inconsistent results.
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.
Good point; @ojhaujjwal — please update accordingly. Essentially, we can rely on the fact that the hydrator plugin manager will raise an exception here.
As a name I would personally something like
|
I was suggesting "map", as I was thinking of the feature with regards to the I'm personally wavering between "Discovery" and "Delegating"; I'll choose one during merge. |
+1 for Delegating, since the actual hydration is deletaged to another hydrator |
/** | ||
* Gets hydrator of an object | ||
* | ||
* @param object $object |
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.
Trim spaces
I'm reviewing now, and have noticed that the patch still contains additions to the MVC |
Merged for release in 2.4. Renamed the new hydrator to Usage is now: $hydrators = $services->get('HydratorManager');
$delegating = $hydrators->get('DelegatingHydrator');
$albumHydrator = new Zend\Stdlib\Hydrator\ClassMethods;
$artistHydrator = new Zend\Stdlib\Hydrator\ClassMethods;
$hydrators = new Zend\Stdlib\Hydrator\HydratorPluginManager;
$hydrators->setService('Album', $albumHydrator);
$hydrators->setService('Artist', $artistHydrator);
$array = $delegating->extract(new Artist);
$artist = $delegating->hydrate($data, new Artist); @ojhaujjwal Please also submit documentation to https://github.com/zendframework/zf2-documentation 😄 |
…eature/standard-hydrator standard hydrator idea
I created this hydrator and named it as
StandardHydrator
. This is just an idea. This name can be changed if you guys like the idea.This detects the hydrator for each object. I think that this hydrator can be pretty useful.