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