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

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