使用注释获取实体常量的选择列表

时间:2014-10-28 22:31:47

标签: php symfony annotations

是否可以使用注释来获取特定类型的类/实体常量的ChoiceListarray

我的意思是这样的:

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;

    ...
}

然后:

$builder->add('thing', 'choice', array(
  'choice_list' => getChoiceListFromConsts('User','Things')
));

我希望getChoiceListFromConsts('User','Things')返回类似的内容:

array( 
     'Label 1' => 1,
     'Label 2' => 2,
     'Label 3' => 3
);

Symfony2中是否有内置功能,或者是否有提供此类服务的捆绑包?

0 个答案:

没有答案