Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine annotation constant concatenation

i'm trying to use class constant in a doctrine annotation, as explained here : http://doctrine-common.readthedocs.io/en/latest/reference/annotations.html#constants

for example, this works like a charm :

@MappableProperty(description=Company::ACTIVITY_NATURE_BIC)

But I don't want to parse a raw constant, I would like to concatenate it with a string.

what I would like to achieve is something like this :

@MappableProperty(description="Activity nature, for example Company::ACTIVITY_NATURE_BIC")

as expected, this doesn't work. Is constant concatenation impossible in doctrine annotation ?

EDIT : after some research, this is impossible to parse both string and constants at the same time right now. might be implemented in the future.

like image 316
VaN Avatar asked Dec 14 '17 15:12

VaN


1 Answers

One can't use constants concatenation in annotations, but one can concatenate strings and constants into another class constant and then use it in the annotation.

For instance:

class Company {
    public const ACTIVITY_NATURE_BIC = "[...]";
    public const ACTIVITY_NATURE_DESCRIPTION = "Activity nature, for example ".self::ACTIVITY_NATURE_BIC;

    /** @MappableProperty(description=Company::ACTIVITY_NATURE_DESCRIPTION) */
    private $activityNature;
}
like image 178
fbastien Avatar answered Oct 22 '22 13:10

fbastien