Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Symfony 5 PHP8 Attributes for Security

I have a page that I am trying to convert from annotations to PHP8 attributes.

namespace App\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[IsGranted('ROLE_ADMIN')]
#[Route('/page')]
class PageController extends AbstractController
{
    #[Route('/', name: 'page')]
    public function index(): Response
    {
        return $this->render('page/index.html.twig', [
            'controller_name' => 'PageController',
        ]);
    }
}

The IsGranted attribute doesn't seem to work, as the page is accessible instead of a 403 error. On the other hand when converted to annotations, like below it works as expected. Is there a config setting I am missing?

/**
 * @IsGranted("ROLE_ADMIN")
 */
#[Route('/page')]
class PageController extends AbstractController
{
    #[Route('/', name: 'page')]
    public function index(): Response
    {
        return $this->render('page/index.html.twig', [
            'controller_name' => 'PageController',
        ]);
    }
}

Other attributes eg #[Route], #[Entity] etc works, but the Security attributes do not seem to work.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Support for PHP8 attributes in the SensioFrameworkExtraBundle package are available only from version 6.1.0. You likely just need to update it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda