src/Form/EventListener/Admin/Webhook/GenerateHMACFieldsSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Admin\Webhook;
  4. use App\Entity\Admin\Webhook;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Form\FormEvent;
  7. use Symfony\Component\Form\FormEvents;
  8. class GenerateHMACFieldsSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents(): array
  11.     {
  12.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  13.     }
  14.     public function preSetData(FormEvent $event): void
  15.     {
  16.         /** @var Webhook $webhook */
  17.         $webhook $event->getData();
  18.         // Generate Random HMAC Key for each entry
  19.         if (null === $webhook->getId()) {
  20.             $webhook->setHmacKey(sha1(time() . random_int(0getrandmax())));
  21.         }
  22.     }
  23. }