Symfony2 Use PHP Class Constant in YAML Config?

后端 未结 6 1846
梦如初夏
梦如初夏 2020-12-15 05:45

I know this is probably not possible, but is there a clean way to use a PHP class constant within a YAML config/services/etc. file for Symfony2?

For example, if I ha

6条回答
  •  孤街浪徒
    2020-12-15 06:35

    This is possible, but only when using eval'd code, which is generally frowned upon.

    Given a class constant Permission::ACCESS_NONE e.g. you could do something like this in the yaml file:

    permission: ACCESS_NONE
    

    and the following in the code where you parse the yaml:

    eval("return \The\Complete\Namespace\To\Permission::".$context['permission'].";");

    This is of course butt-ugly code but it does work.

提交回复
热议问题