8

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.

1 Answer 1

1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.