简体   繁体   English

Symfony sensio/framework-extra-bundle 已被放弃,我找不到 IsGranted 替代方案

[英]Symfony sensio/framework-extra-bundle is abandoned and i cannot find an IsGranted alternative

(on a Symfony 5.4 PHP 7.4 project) (在 Symfony 5.4 PHP 7.4 项目上)
So far I am using IsGranted to restrict access in controllers per role.到目前为止,我使用IsGranted来限制每个角色在控制器中的访问。 ie IE

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
class PostController extends Controller
{
    /**
     * @IsGranted("ROLE_ADMIN")
     */
    public function myAdminPage()
    { // ... }
}

Since the abandoned warning on composer update ie: Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.由于composer update ie: Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.上的abandoned警告被废弃,你应该避免使用它。 Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead. I'm trying to find an alternative.我正在尝试寻找替代方案。

for the case of the Route annotation things are straight forward by replacing:对于Route注释的情况,通过替换是直接的:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
with
use Symfony\Component\Routing\Annotation\Route;

But I cannot find an alternative for IsGranted .但我找不到IsGranted的替代方案。 (for Symfony 5 or Symfony 6) (对于 Symfony 5 或 Symfony 6)

Any suggestions/advices?有什么建议/建议吗?
Thanks.谢谢。

In Symfony 5.4, you should use the Security component instead.在 Symfony 5.4 中,您应该改用Security组件。

use Symfony\Component\Security\Core\Security;

class PostController extends Controller
{
    /**
     * @Security("is_granted('ROLE_ADMIN')")
     */
    public function myAdminPage()
    { 
        // ... 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM