src/EventListener/PreExecutionListener.php line 18

Open in your IDE?
  1. <?php 
  2. namespace App\EventListener;
  3. use App\Event\PreExecutionEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Process\Process;
  6. class PreExecutionListener implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         return [
  11.             PreExecutionEvent::NAME => 'onPreExecution',
  12.         ];
  13.     }
  14.     public function onPreExecution(PreExecutionEvent $event)
  15.     {
  16.         $targetDateTime $event->getTargetDateTime();
  17.         
  18.         // Calculate the execution time 5 minutes before the target datetime
  19.         $executionTime = clone $targetDateTime;
  20.         $executionTime->sub(new \DateInterval('PT1M'));
  21.         
  22.         // Replace with your actual command
  23.         $command = ['php''/Users/yacoubadoumbia/Sites/e-learning/src/bin/console''app:test-mail:sending'];
  24.         // Schedule the command execution using Symfony Process
  25.         $process = new Process($command);
  26.         $process->setTimeout(null); // No timeout
  27.         $process->run();
  28.     }
  29. }