0

Symfony 的 API 平台允许您使用 Voters 来授予或拒绝访问您的资源,如他们的文档中所述。

但是,所有示例都使用魔术值,我宁愿为此使用类常量。前任。

/**
 * @ApiResource(
 *     itemOperations={
 *          "put"={"security"="is_granted(UserVoter::USER_EDIT, object)"},
 *     }
 * )
 */

我已经尝试使用UserVoter该类的“use”语句App\Security\Voter\UserVoter::USER_EDIT以及 escaped App\\Security\\Voter\\UserVoter::USER_EDIT,但是 API 平台没有接受任何内容

问题:如何在 API 平台中使用具有安全性的类常量?

4

1 回答 1

2

只是为了向任何想知道的人确认: is_granted(constant('\\App\\Security\\Voter\\UserVoter::USER_EDIT'), object)工作是一种享受

于 2021-06-29T13:29:48.260 回答