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

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.     /**
  18.      * @var \DateTimeInterface
  19.      */
  20.     private $previousRun;
  21.     public function __construct(object $servicestring $intervalstring $method null)
  22.     {
  23.         $this->service $service;
  24.         $this->method $method;
  25.         $this->interval $interval;
  26.         $this->name = \get_class($service);
  27.         if (!\is_callable($service)) {
  28.             if (null === $this->method) {
  29.                 throw new \InvalidArgumentException('Service must be a callable when no method name is defined');
  30.             }
  31.             $this->name .= '::'.$method;
  32.         }
  33.     }
  34.     public function __invoke(string $scope): void
  35.     {
  36.         if (\is_callable($this->service)) {
  37.             ($this->service)($scope);
  38.         } else {
  39.             $this->service->{$this->method}($scope);
  40.         }
  41.     }
  42.     public function getService(): object
  43.     {
  44.         return $this->service;
  45.     }
  46.     public function getMethod(): string
  47.     {
  48.         return $this->method;
  49.     }
  50.     public function getInterval(): string
  51.     {
  52.         return $this->interval;
  53.     }
  54.     public function getName(): string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setPreviousRun(\DateTimeInterface $previousRun): self
  59.     {
  60.         $this->previousRun $previousRun;
  61.         return $this;
  62.     }
  63.     public function getPreviousRun(): \DateTimeInterface
  64.     {
  65.         return $this->previousRun;
  66.     }
  67. }