src/Listener/Admin/RequireListener.php line 53

Open in your IDE?
  1. <?php
  2. /** @noinspection PhpUnused */
  3. namespace App\Listener\Admin;
  4. use Agediss\RabbitMQ\Entity\AMQPMessageBody;
  5. use App\Entity\Client;
  6. use App\Entity\Motif;
  7. use App\Entity\Plateforme;
  8. use App\Entity\Pole;
  9. use App\Entity\Societe;
  10. use App\Entity\SousTraitant;
  11. use App\Entity\Transporteur;
  12. use Doctrine\Common\Annotations\AnnotationReader;
  13. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
  14. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  15. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  16. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  17. use http\Exception\RuntimeException;
  18. use Psr\Log\LoggerInterface;
  19. use ReflectionClass;
  20. use Swagger\Logger;
  21. use Symfony\Component\DependencyInjection\ContainerInterface;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
  24. use Symfony\Component\HttpKernel\Profiler\Profiler;
  25. class RequireListener implements EventSubscriberInterface
  26. {
  27.     /**
  28.      * @var ContainerInterface
  29.      */
  30.     private $container;
  31.     /**
  32.      * @var LoggerInterface
  33.      */
  34.     private $logger;
  35.     public function __construct(ContainerInterface $containerLoggerInterface $logger)
  36.     {
  37.         $this->container $container;
  38.         $this->logger $logger;
  39.     }
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             BeforeEntityPersistedEvent::class => ['CheckRequireFields'],
  44.         ];
  45.     }
  46.     public function CheckRequireFields(BeforeEntityPersistedEvent $event): void
  47.     {
  48.         $entity $event->getEntityInstance();
  49.         $reflextionClass = new ReflectionClass($entity);
  50.         $reader = new AnnotationReader();
  51.         foreach ($reflextionClass->getProperties() as $property) {
  52.             $annotation $reader->getPropertyAnnotation($property'ORM');
  53.             $this->logger->info(json_encode($annotation));
  54.         }
  55.     }
  56. }