-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Resolve collections from DocBlock #1214
Resolve collections from DocBlock #1214
Conversation
Any chance to support also this format:
|
@dragosprotung yes, I can add it :) @goetas can you deliver feedback about current implementation and answer above questions? |
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 really like how this feature is progressing.
I did not review possible edge cases in the comment parsing, that would be done when we agree on the architecture of this feature.
In particular im interested in the feedback about implementing this feature as a new driver and implementing DriverInterface
@goetas Proposal of @dragosprotung is implemented.
To keep this compatible with
|
@goetas I would like to ask for review now. |
This looks great so far! I will try it in the next days/weeks and see if I can help with the failing tests |
@goetas will you find time to check the tests? :) |
@goetas can you tell, if you will find time for verifying tests? I understand that you may have not enough time for it. |
I have tested this and looks great, but is seems that needs to be targeting a 4.0 release... the issue is the following code that works as expected now, and is broken if we were going to merge this PR. class User {
/**
* @var Country
*/
private $country;
public function __construct($country)
{
$this->country = $country;
}
}
$user = new User(new Car()); // yes we are passing a "car", not a country, it is not a typo Even if the following code is "wrong", it works. A user will be serialized and in the "country" there will be serialized the car object. If this PR gets merged, the serializer will try to traverse the "car" by using the props defined for "country". This is not an uncommon scenario... immagine just how many docblocks might be not up to date in a project.... and now suddenly applications will start crashing. With typed props this was not an issue is since PHP will do the check for us and tell the user that the code was wrong... but in our case there is no such check. |
This is understandable, you would like to avoid breaking change for current major release. Should I leave the MR to you now and wait for 4.0 release? :) |
@dgafka Sadly I have to say yes. The 4.0 is not yet planned but there are a couple of things I would like to place into it (but have no time to work on it....). The only option I can see to have it in 3.x to make it opt-in, so who is interested can enable it and deal with potential bc breaks? What do you think? (i think it could be possible just by removing the instantiation of it from https://github.com/schmittjoh/serializer/pull/1214/files#diff-31d5d899bd07e7ac0794ccc1b0facdeaR64 and move it to the serializer builder). Thanks a lot again for your great work! |
@goetas I have added You can enable it by using method
|
@goetas will we make it to 3.x after recent change? :) |
hi! sorry if it took that long, but I think that this is ready! I was trying to use https://github.com/phpstan/phpdoc-parser to parse the docblocks, but I did not make it, will try again! Thanks a lot for your work! |
If I understand you were trying to replace the part which resolves the docblock types for an external library. Thank you for merging it :) I am looking forward for next MR, in order to optimize deserializing process. I feel like version 3, had big impact on that as the times increased. |
yeah. the advantage of the other lib is that is fully tested and support very exotic syntaxes to express types (see PHPStan)...
Looking forward to it.
did not know that... IMO should be faster than 1.x... but I might be wrong. |
thanks again for this contribution |
@dgafka how to enable DocBlockDriver? |
@simPod you can see example usage in here: |
I see. I'll have to do it differently if I use the sf bundle. Thanks. |
There are few things worth discussion:
What should happen, when incorrect DocBlock type is given?
Current implementation will throw exception, as above has no sense
What should happen, when union type is given?
Current implementation will throw exception, as we will not know, which class should be used for deserialization.
What should happen, when class does not exists?
Current implementation will throw exception as, this class will not be deserializable.
1)
and2)
3)
what exception type it should be?Current implementation will throw \InvalidArgumentException