[PropertyInfo] Exclude static methods form properties guessing #21331

Merged
merged 1 commit into from Jan 18, 2017

Projects

None yet

5 participants

@dunglas
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
@dunglas dunglas [PropertyInfo] Exclude static methods form properties guessing
190c736
@stof
Member
stof commented Jan 18, 2017

👍

@fabpot
Member
fabpot commented Jan 18, 2017

Thank you @dunglas.

@fabpot fabpot merged commit 190c736 into symfony:2.8 Jan 18, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details
@fabpot fabpot added a commit that referenced this pull request Jan 18, 2017
@fabpot fabpot bug #21331 [PropertyInfo] Exclude static methods form properties gues…
…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
0ca3e96
@dunglas dunglas deleted the dunglas:propertyinfo/exclude_static branch Jan 18, 2017
@fabpot fabpot added a commit that referenced this pull request Jan 18, 2017
@fabpot fabpot bug #21332 [PropertyInfo] Don't try to access a property thru a stati…
…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
bfdac85
@teohhanhui
Contributor

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

@dunglas
Member
dunglas commented Jan 23, 2017 edited

@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
Contributor
This was referenced Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment