vendor/emprel/ambiente-bundle/Event/RouteAmbienteListener.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * Este arquivo é parte do package Ambiente Bundle.
  4.  *
  5.  * (c) Laino Santos <lainosantos@recife.pe.gov.br>
  6.  *
  7.  * Para informações completas sobre copyright e licença, por favor ver o
  8.  * arquivo LICENCE distribuído juntamente com este código.
  9.  */
  10. namespace Emprel\Ambiente\Bundle\Event;
  11. use Emprel\Ambiente\Bundle\Utils\Ambiente;
  12. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  13. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  14. /**
  15.  * Restringe acesso por ambiente.
  16.  *
  17.  * @package Emprel\Ambiente\Bundle\Event
  18.  * @author Laino Santos <lainosantos@recife.pe.gov.br>
  19.  */
  20. class RouteAmbienteListener
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function onKernelRequest(GetResponseEvent $event)
  26.     {
  27.         $request $event->getRequest();
  28.         $ambientes $request->attributes->get('_ambientes_apenas', []);
  29.         $ambientesBlacklist $request->attributes->get('_ambientes_blacklist', []);
  30.         if (is_array($ambientes) && count($ambientes) && !Ambiente::in($ambientes)) {
  31.             throw new AccessDeniedHttpException('Requisição não permitida para o ambiente.');
  32.         }
  33.         if (is_array($ambientesBlacklist) && count($ambientesBlacklist) && Ambiente::in($ambientesBlacklist)) {
  34.             throw new AccessDeniedHttpException('Requisição negada para o ambiente.');
  35.         }
  36.     }
  37. }