vendor/nzo/url-encryptor-bundle/Annotations/AnnotationResolver.php line 36

Open in your IDE?
  1. <?php
  2. namespace Nzo\UrlEncryptorBundle\Annotations;
  3. use Doctrine\Common\Annotations\Reader;
  4. use Nzo\UrlEncryptorBundle\UrlEncryptor\UrlEncryptor;
  5. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  6. class AnnotationResolver
  7. {
  8.     /**
  9.      * @var Reader
  10.      */
  11.     private $reader;
  12.     /**
  13.      * @var UrlEncryptor
  14.      */
  15.     private $decryptor;
  16.     /**
  17.      * AnnotationResolver constructor.
  18.      *
  19.      * @param Reader $reader
  20.      * @param UrlEncryptor $decryptor
  21.      */
  22.     public function __construct(Reader $readerUrlEncryptor $decryptor)
  23.     {
  24.         $this->reader $reader;
  25.         $this->decryptor $decryptor;
  26.     }
  27.     /**
  28.      * @param FilterControllerEvent $event
  29.      */
  30.     public function onKernelController(FilterControllerEvent $event)
  31.     {
  32.         if (!is_array($controller $event->getController())) {
  33.             return;
  34.         }
  35.         $objectController = new \ReflectionObject($controller[0]);
  36.         $method $objectController->getMethod($controller[1]);
  37.         foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
  38.             if ($configuration instanceof ParamEncryptor) {
  39.                 if (isset($configuration->params)) {
  40.                     $request $event->getRequest();
  41.                     foreach ($configuration->params as $key => $param) {
  42.                         if ($request->attributes->has($param)) {
  43.                             $decrypted $this->decryptor->encrypt($request->attributes->get($param));
  44.                             $request->attributes->set($param$decrypted);
  45.                         } elseif ($request->request->has($param)) {
  46.                             $decrypted $this->decryptor->encrypt($request->request->get($param));
  47.                             $request->request->set($param$decrypted);
  48.                         }
  49.                     }
  50.                 }
  51.             } elseif ($configuration instanceof ParamDecryptor) {
  52.                 if (isset($configuration->params)) {
  53.                     $request $event->getRequest();
  54.                     foreach ($configuration->params as $key => $param) {
  55.                         if ($request->attributes->has($param)) {
  56.                             $decrypted $this->decryptor->decrypt($request->attributes->get($param));
  57.                             $request->attributes->set($param$decrypted);
  58.                         } elseif ($request->request->has($param)) {
  59.                             $decrypted $this->decryptor->decrypt($request->request->get($param));
  60.                             $request->request->set($param$decrypted);
  61.                         }
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }