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

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