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

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