Skip to content
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

Using @Until and @Since on class level #1048

Closed
tjveldhuizen opened this issue Feb 25, 2019 · 4 comments
Closed

Using @Until and @Since on class level #1048

tjveldhuizen opened this issue Feb 25, 2019 · 4 comments

Comments

@tjveldhuizen
Copy link
Contributor

tjveldhuizen commented Feb 25, 2019

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes/no

The @VirtualProperty annotation can be used on classes and methods. The @Until and @Since annotations can be used on methods and properties. As such, it is not possible to use the @SInCE annotation in the options argument of the @VirtualProperty, on class level.

In most cases I prefer not to create a method in the class, just to be used in the API. However, such virtual property is limited to specific versions. Therefore, my questions are: Am I right about not being abled to use those annotations in this way? If yes, would it be possible to make @Until and @Since available on class level, within the options-parameter of @VirtualProperty? I guess it might be relatively easy, since @Groups is available and seems to be working in the same way.

Example:

/**
 * Class Team
 *
 * @package Nevobo\BeachBundle\Entity
 *
 * @ORM\Entity(repositoryClass="Nevobo\BeachBundle\Entity\Repository\TeamRepository")
 * @Serializer\ExclusionPolicy("all")
 * @Serializer\VirtualProperty(
 *      name="players",
 *      exp="object.getTeam().getPlayers()",
 *      options={
 *          @Serializer\Until(0),
 *          @Serializer\Groups({
 *              "beach_team_results",
 *          })
 *      }
 * )
 * @ORM\Table(name="beach_participant")
 */
class Participant {
...
}
@goetas
Copy link
Collaborator

goetas commented Feb 25, 2019

Hmm, it should work out of the box. Can it be that you have a field named players in your class that overrides the virtual property?

@tjveldhuizen tjveldhuizen changed the title Usince \@Until and \@Since on class level Using @Until and @Since on class level Feb 25, 2019
@tjveldhuizen
Copy link
Contributor Author

No, there is no players property, nor a players() method (or even getPlayers()). The error message is as following.

AnnotationException in AnnotationException.php line 54: [Semantical Error] Annotation @Serializer\Until is not allowed to be declared on class Nevobo\BeachBundle\Entity\Participant. You may only use this annotation on these code elements: PROPERTY, METHOD.

(I've made a small correction in the class naming of my simplified example, by the way, maing clear the VirtualProperty doesn't refer to the 'current' class)

@goetas
Copy link
Collaborator

goetas commented Feb 25, 2019

Well, then if is so, a PR is welcome.

@goetas
Copy link
Collaborator

goetas commented Feb 26, 2019

Fixed via #1049

@goetas goetas closed this as completed Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants