vendor/contao/core-bundle/src/Cron/CronJob.php line 44

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Cron;
  11. class CronJob
  12. {
  13.     private object $service;
  14.     private ?string $method;
  15.     private string $interval;
  16.     private string $name;
  17.     private \DateTimeInterface $previousRun;
  18.     public function __construct(object $servicestring $intervalstring $method null)
  19.     {
  20.         $this->service $service;
  21.         $this->method $method;
  22.         $this->interval $interval;
  23.         $this->name = \get_class($service);
  24.         if (!\is_callable($service)) {
  25.             if (null === $this->method) {
  26.                 throw new \InvalidArgumentException('Service must be a callable when no method name is defined');
  27.             }
  28.             $this->name .= '::'.$method;
  29.         }
  30.     }
  31.     public function __invoke(string $scope): void
  32.     {
  33.         if (\is_callable($this->service)) {
  34.             ($this->service)($scope);
  35.         } else {
  36.             $this->service->{$this->method}($scope);
  37.         }
  38.     }
  39.     public function getService(): object
  40.     {
  41.         return $this->service;
  42.     }
  43.     public function getMethod(): string
  44.     {
  45.         return $this->method;
  46.     }
  47.     public function getInterval(): string
  48.     {
  49.         return $this->interval;
  50.     }
  51.     public function getName(): string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setPreviousRun(\DateTimeInterface $previousRun): self
  56.     {
  57.         $this->previousRun $previousRun;
  58.         return $this;
  59.     }
  60.     public function getPreviousRun(): \DateTimeInterface
  61.     {
  62.         return $this->previousRun;
  63.     }
  64. }