Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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
merged 1 commit into from
Jan 18, 2017

Conversation

dunglas
Copy link
Member

@dunglas 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

@stof
Copy link
Member

stof commented Jan 18, 2017

👍

@fabpot
Copy link
Member

fabpot commented Jan 18, 2017

Thank you @dunglas.

@fabpot fabpot merged commit 190c736 into symfony:2.8 Jan 18, 2017
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
@dunglas dunglas deleted the propertyinfo/exclude_static branch January 18, 2017 15:19
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
@teohhanhui
Copy link
Contributor

Again like in api-platform/core#914, I'm curious about the rationale behind this... Since there's no explanation given.

@dunglas
Copy link
Member Author

dunglas commented Jan 23, 2017

@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 Book. It's definitely a bug, static methods should be excluded.

@teohhanhui
Copy link
Contributor

teohhanhui commented Jan 23, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants