Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[PropertyInfo] Exclude static methods form properties guessing#21331
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dunglas commentedJan 18, 2017
| Q | A |
|---|---|
| Branch? | 2.8 |
| Bug fix? | yes |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | n/a |
| License | MIT |
| Doc PR | n/a |
stof commentedJan 18, 2017
👍 |
fabpot commentedJan 18, 2017
Thank you@dunglas. |
…sing (dunglas)This PR was merged into the 2.8 branch.Discussion----------[PropertyInfo] Exclude static methods form properties guessing| Q | A| ------------- | ---| Branch? | 2.8| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR | n/aCommits-------190c736 [PropertyInfo] Exclude static methods form properties guessing
…c method (dunglas)This PR was merged into the 2.8 branch.Discussion----------[PropertyInfo] Don't try to access a property thru a static method| Q | A| ------------- | ---| Branch? | 2.8| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR | n/aSee also#21331.Commits-------3b4858f [PropertyInfo] Don't try to access a property thru a static method
teohhanhui commentedJan 23, 2017
Again like inapi-platform/core#914, I'm curious about the rationale behind this... Since there's no explanation given. |
dunglas commentedJan 23, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@teohhanhui if you have an entity like the following: <?php// src/AppBundle/Entity/Book.phpuseApiPlatform\Core\Annotation\ApiResource;useSymfony\Component\Validator\ConstraintsasAssert;/** * @ApiResource(attributes={"validation_groups"={Book::class, "getValidationGroups"}}) */class Book{/** * Return dynamic validation groups. * * @param self $book Contains the instance of Book to validate. * * @return string[] */publicstaticfunctiongetValidationGroups(self$book) {return ['a']; }/** * @Assert\NotBlank(groups={"a"}) */private$name;/** * @Assert\NotNull(groups={"b"}) */private$author;// ...} The extractor will include "validationGroups" in the list of properties of the entity |
teohhanhui commentedJan 23, 2017 via email
Static properties / methods could be used for a variety of reasons (Ibelieve there are valid use cases where properties are represented assuch). I don't see why PropertyInfo should make the decision for the userto exclude them. …On Mon, 23 Jan 2017, 17:50 Kévin Dunglas, ***@***.***> wrote:@teohhanhui <https://github.com/teohhanhui> if you have an entity like the following: <?php// src/AppBundle/Entity/Book.phpuse ApiPlatform\Core\Annotation\ApiResource;use Symfony\Component\Validator\Constraints as Assert;/** * @ApiResource(attributes={"validation_groups"={Book::class, "validationGroups"}}) */class Book{ /** * Return dynamic validation groups. * *@param self $book Contains the instance of Book to validate. * *@return string[] */ public static function getValidationGroups(self $book) { return ['a']; } /** *@Assert\NotBlank(groups={"a"}) */ private $name; /** *@Assert\NotNull(groups={"b"}) */ private $author; // ...} The extractor will include "validationGroups" in the list of properties of the entity Book. It's definitely a bug, static methods should be excluded. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#21331 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAhf6yMCQsM49ouZKVmBQSYbbwuVi3bRks5rVHfegaJpZM4Lmzua> . |