-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Conversation
This commit introduce strategies for key / properties transformations
@@ -25,6 +29,13 @@ | |||
protected $strategies; | |||
|
|||
/** | |||
* The list of naming strategies that this hydrator has. |
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.
If this is a list, how can it be of type NamingStrategyInterface? Shouldn't it be an array or so?
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 didn't updated the doc-block in the last commit, my bad.
I like the idea in general, pretty useful in many cases. |
* | ||
* @param NamingStrategyInterface $strategy The naming to register. | ||
* | ||
* @return NamingStrategyEnabledInterface |
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.
@return self
, and no empty-line between params and return annotations.
Overall, 👍 One concern I have is that hydrators then become stateful, as they have specific naming strategies composed. What I cannot recall, however, is if the HydratorManager returns a new instance each time, or the same instance; if the former, we're fine. Also, it might be nice to have a way to pass the naming strategy when retrieving a Hydrator from the HydratorManager; plugin managers already allow passing an array of options when you call |
…tegy components
The Hydrator Manager return a new instance on each time be default. But you're not required to use a naming strategy, so the hydrators are still stateless from this point of view. The idea of passing naming strategy sounds interesting, but what about filters and classic strategies ? |
@ronan-gloo Ideally we should also allow passing filters and classic strategies; this would be a nice start, however. Let me know how you want to proceed. |
That's for this specific thing that I'd thought of Data transformers. I'm afraid that the hydrator is getting too much features now :/. As a lot of other components may need that kind of transformation (input filters for instance), that's why I think it would be better to abstract that kind of thing "somewhere else". |
@weierophinney That's right, as long as the interfaces are similar, it will be more flexible (but maybe a bit confusing for the user ?) to specify the "classic" StrategyInterface for naming strategy.I've separated interfaces in order to make the idea clearer. @bakura10 |
@ronan-gloo , I currently have no plans integrating it into ZF2. It's just an idea though... |
$this->underscoreSeparatedKeys = $underscoreSeparatedKeys; | ||
$this->underscoreSeparatedKeys = (bool) $underscoreSeparatedKeys; | ||
|
||
if (true === $this->underscoreSeparatedKeys) { |
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.
Since we know this is a boolean at this point (you cast it to bool in line 82), you can get rid of the true ===
bit.
Add Naming strategy for Hydrators
- we know we have a boolean; remove true === test - combine if statement from body with else parent
- Modified class to use existing filters, via a filter chain, to perform the work. Filter chains are stored as static properties as the implementation will not change between instances.
- Updated copyright year - Removed unneeded annotations - Removed empty lines at start and finish of classes
…r & NamingStrategy components
…evelop Add Naming strategy for Hydrators
- we know we have a boolean; remove true === test - combine if statement from body with else parent
- Modified class to use existing filters, via a filter chain, to perform the work. Filter chains are stored as static properties as the implementation will not change between instances.
- Updated copyright year - Removed unneeded annotations - Removed empty lines at start and finish of classes
This commit is a purpose for key / properties transformations supports through externalized strategies.
It introduce the same behavior implemented for values, but on names level.
hydrate
outputAn Underscore <-> CamelCase strategy is shipped by default, in order to keep ClassMethods underscore feature alive, and keep the BC. (the strategy is set / unset on
setUnderscoreSeparatedKeys
)For others Hydrators, you'll need to set the naming strategy manually:
Let me know if you're interested to merge this feature, i'll push unit tests & doc.