【发布时间】:2021-01-18 05:00:09
【问题描述】:
API Platform for Symfony 允许您使用 Voters 来授予或拒绝访问您的资源,如其docs 中所述。
但是所有示例都使用魔法值,我宁愿为此使用类常量。例如。
/**
* @ApiResource(
* itemOperations={
* "put"={"security"="is_granted(UserVoter::USER_EDIT, object)"},
* }
* )
*/
我已经尝试使用 UserVoter 类的“使用”语句 App\Security\Voter\UserVoter::USER_EDIT 以及转义 App\\Security\\Voter\\UserVoter::USER_EDIT,但是 API 平台不接受任何内容
问题:如何在 API 平台中使用具有安全性的类常量?
【问题讨论】:
-
我从未使用过
ApiPlatform,但see this answer。你试过\\App\\Security\\Voter\\UserVoter::USER_EDIT或is_granted(constant('\\App\\Security\\Voter\\UserVoter::USER_EDIT'), object)吗? (也许对于第二个例子,常量函数需要安装表达式语言组件,我不知道它是否包含在 ApiPlatform 包中) -
嘿。你试过
"security"="is_granted(permission(UserVoter::USER_EDIT), object)"吗?另外,请使用主类注释及其常量显示此实体
标签: symfony api-platform.com symfony4-voter