-
-
Notifications
You must be signed in to change notification settings - Fork 69
Optional hydration #16
base: 4.2.x
Are you sure you want to change the base?
Conversation
Allows for properties to be skipped when not found in data array.
This requires a different generated class. The checks should not land in runtime. |
That would mean the factory has to rerun to create the right object for the type of data passed in?? |
Right: no decision making at runtime |
@@ -45,7 +45,7 @@ class HydratorGenerator | |||
* | |||
* @return \PHPParser_Node[] | |||
*/ | |||
public function generate(ReflectionClass $originalClass) | |||
public function generate(ReflectionClass $originalClass, $options = array()) |
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 we can schedule this for 2.0
(which is fine) you can add the array
hint here
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.
Also fix the docblock
The approach seems to be much better now :) |
key is not available to the callback used by |
@flip111 yep, but keys are preserved ;-) |
Yes but the filtering per element depends on the key of that element |
@flip111 you are not really using the key except for the |
Lol, so we will have to lookup the php manual every time we need to know
|
@lisachenko Anyway @Ocramius i did all the changes except for this one. Not sure what is the optimal approach here o_O. |
@flip111 segregate all the things in private methods :D |
suggestion: Possibly init*() instead of make*()
@flip111 a rebase as well as test cases for this are required... |
Noted! Though might take some time over here ... |
I got a bit confused because the dev-master got updated. I can not see the changes in comparison to the current dev-master (or don't know how). Perhaps instead of a rebase i can just open up another PR so the diff becomes more clear as well. |
@flip111 the PR still looks fine to me. I can rebase it myself if needed. |
I was waiting for your toolchain to run (i.e. travis), but that didn't happen yet? |
@flip111 Travis does not run PRs which are not mergeable. This is why it does not run. It would run after a rebase |
@Ocramius is this PR still looking fine to you? Is the only blocker that rebase? Did the state of the library changed so much that this PR is unmergeble in it's current state? I would like to push this to finish in the upcomming time. Would be great if you can give your pointers, blessing and that mouse click on the holy merge button. |
@flip111 it was already conflicting with master in May. This has not magically resolved |
I think there is a good use case for not having hydrate and extract work on the same properties. Maybe you want to just hydrate an I wrote a library before where i could choose between $this->barWriter5640e58591b7c415996372->__invoke($object, $data['bar']); You will get if (isset($data['bar'])) {
$this->barWriter5640e58591b7c415996372->__invoke($object, $data['bar']);
} Configuration could be done by a data structure (arrays). For example: ["foo", "bar"] Or if you need more finetuning per property: [
"foo" => [
"extract": true,
"hydrate": "optional"
]
"bar" => ]
"extract": "optional",
"hydrate": false
]
] This implementation could possibly be replaced by custom visitors as in #40 The custom visitor class would have to be added to this library though, otherwise other users of this library do not get this functionality. One huge disadvantage in my opinion is that adding a bunch of visitors in a certain order will cause that they are not compatible with each other anymore ... At least this way you have the guarantee that all the options works together. And also coding is much easier then to mess around with the AST all the time. @Ocramius i'm gonna go ahead and start working on another version of this PR with the above mentioned options (but not by doing it with visitors). I'm leaving this PR as it is for now. Hopefully you will have some time to review this. I do have one more question though ... is it possible to generate more hydrator classes (cached for production) for the same class? In case you want different versions that serve different options... |
New version is ready |
For what it worth, PR #59 should fix this issue by mostly removing code, not adding some. |
Allows for properties to be skipped when not found in data array.
Some considerations:
var_export($accessibleProperty->getName(), true)