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

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 $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.      * @inheritDoc
  22.      */
  23.     public static function getSubscribedEvents() : array
  24.     {
  25.         return [
  26.             LoadJobsEvent::NAME => 'onLoadJobs',
  27.         ];
  28.     }
  29.     public function onLoadJobs(LoadJobsEvent $event) : void
  30.     {
  31.         foreach ($this->jobs as $job) {
  32.             $event->addJob($job);
  33.         }
  34.     }
  35. }