-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
dunglas
commented
Jan 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 |
👍 |
Thank you @dunglas. |
fabpot
added a commit
that referenced
this pull request
Jan 18, 2017
…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/a Commits ------- 190c736 [PropertyInfo] Exclude static methods form properties guessing
fabpot
added a commit
that referenced
this pull request
Jan 18, 2017
…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/a See also #21331. Commits ------- 3b4858f [PropertyInfo] Don't try to access a property thru a static method
Again like in api-platform/core#914, I'm curious about the rationale behind this... Since there's no explanation given. |
@teohhanhui if you have an entity like the following: <?php
// src/AppBundle/Entity/Book.php
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @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[]
*/
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 |
Static properties / methods could be used for a variety of reasons (I
believe there are valid use cases where properties are represented as
such). I don't see why PropertyInfo should make the decision for the user
to 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>
.
|
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.