php – 如何使用Symfony表达式语言在@Security注释中使用类常量?
发布时间:2020-05-25 09:18:17 所属栏目:PHP 来源:互联网
导读:我正在使用Symfony 3,我已经创建了一个自定义的Voter类. 我想使用SensioFrameworkExtraBundle @Security标记访问它. 它有点工作. 如果我执行以下操作,它将完美运行: /** * @RestGet(organisation/{id}) * @Security(is_granted(OrgAdmin, id)) * @param in
我正在使用Symfony 3,我已经创建了一个自定义的Voter类. 我想使用SensioFrameworkExtraBundle @Security标记访问它. 它有点工作. 如果我执行以下操作,它将完美运行: /** * @RestGet("organisation/{id}") * @Security("is_granted('OrgAdmin',id)") * @param int $id * @param Request $request * * @return View */ public function getOrganisationAction($id,Request $request) { 但是我不喜欢在应用程序中使用魔术字符串的想法,我宁愿使用类常量来进行检查. 像这样的东西: /** * @RestGet("organisation/{id}") * @Security("is_granted(AppBundleOrgRoles::ROLE_ADMIN,Request $request) { 但是当我尝试时,我收到以下错误消息: Unexpected character "" around position 20 for expression `is_granted(AppBundleOrgRoles::ROLE_ADMIN,id)`. 未转义时,如下: Unexpected character "" around position 20 for expression `is_granted(AppBundleOrgRoles::ROLE_ADMIN,id)`. 所以我很难过. 可以吗? 有关更好的方法的任何建议吗? 您可以使用Expression Language Component中提供的constant() 函数:
@Security("is_granted(constant('FullNamespaceToOrgRoles::ROLE_ADMIN'),id)") (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |