vendor/shapecode/cron-bundle/src/EventListener/ServiceJobLoaderListener.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shapecode\Bundle\CronBundle\EventListener;
  4. use Shapecode\Bundle\CronBundle\Event\LoadJobsEvent;
  5. use Shapecode\Bundle\CronBundle\Model\CronJobMetadata;
  6. use Symfony\Component\Console\Command\Command;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. final class ServiceJobLoaderListener implements EventSubscriberInterface
  9. {
  10.     /** @var CronJobMetadata[] */
  11.     private array $jobs = [];
  12.     public function addCommand(
  13.         string $expression,
  14.         Command $command,
  15.         ?string $arguments null,
  16.         int $maxInstances 1
  17.     ): void {
  18.         $this->jobs[] = CronJobMetadata::createByCommand($expression$command$arguments$maxInstances);
  19.     }
  20.     /**
  21.      * @return array<string, string>
  22.      */
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [LoadJobsEvent::NAME => 'onLoadJobs'];
  26.     }
  27.     public function onLoadJobs(LoadJobsEvent $event): void
  28.     {
  29.         foreach ($this->jobs as $job) {
  30.             $event->addJob($job);
  31.         }
  32.     }
  33. }