src/Twig/DecryptageExtension.php line 62

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Twig;
  7. use App\Services\Encryptage\AesEncrytageStrategy;
  8. use Twig\Extension\AbstractExtension;
  9. use Twig\TwigFilter;
  10. use Twig\TwigFunction;
  11. class DecryptageExtension extends AbstractExtension
  12. {
  13.     /**
  14.      * @var \App\Services\Encryptage\AesEncrytageStrategy
  15.      */
  16.     private $aes;
  17.     public function __construct(AesEncrytageStrategy $aes)
  18.     {
  19.         $this->aes $aes;
  20.     }
  21.     /**
  22.      * @return \Twig\TwigFilter[]
  23.      */
  24.     public function getFilters(): array
  25.     {
  26.         return [
  27.             new TwigFilter('decrypt', [$this'decrypt']),
  28.             new TwigFilter('encrypt', [$this'encrypt']),
  29.         ];
  30.     }
  31.     /**
  32.      * @return \Twig\TwigFunction[]
  33.      */
  34.     public function getFunctions(): array
  35.     {
  36.         return [
  37.             new TwigFunction('decrypt', [$this'decrypt']),
  38.             new TwigFunction('encrypt', [$this'encrypt']),
  39.         ];
  40.     }
  41.     /**
  42.      * @param $value
  43.      */
  44.     public function decrypt($value): string
  45.     {
  46.         return ( $value ) ?$this->aes->decryptage($value):'';
  47.     }
  48.     
  49.     /**
  50.      * @param $value
  51.      */
  52.     public function encrypt($value): string
  53.     {
  54.         return ( $value ) ?$this->aes->encryptage($value):'';
  55.     }
  56. }