Is it possible to use annotations to get a ChoiceList
or array
of specific type of class/entity constants?
I mean something like this:
class User{
/**
* @Item(Things,'Label 1')
*/
const SOME_THING1=1;
/**
* @Item(Things,'Label 2')
*/
const SOME_THING2=2;
/**
* @Item(Things,'Label 3')
*/
const SOME_THING3=3;
/**
* @Item(OtherThings,'Label 1')
*/
const SOME_OTHER_THING1=1;
/**
* @Item(OtherThings,'Label 2')
*/
const SOME_OTHER_THING2=2;
...
}
and then:
$builder->add('thing', 'choice', array(
'choice_list' => getChoiceListFromConsts('User','Things')
));
And I expect getChoiceListFromConsts('User','Things')
to return something like:
array(
'Label 1' => 1,
'Label 2' => 2,
'Label 3' => 3
);
Is there a build-in feature for this in Symfony2 or is there any bundle that provide such a service?