| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Service\Cron;
- use App\Service\Cron\UI\CronUIInterface;
- use App\Service\Cron\UI\SilentUI;
- use App\Service\Utils\StringsUtils;
- use JetBrains\PhpStorm\Pure;
- use Psr\Log\LoggerInterface;
- use Symfony\Contracts\Service\Attribute\Required;
- /**
- * Base class for the Cron-jobs defined in \App\Service\Cron\Job
- *
- * This class shouldn't implement directly the CronjobInterface because it shall not be injected itself into the
- * CronjobIterator, but all its subclasses should.
- */
- abstract class BaseCronJob
- {
- protected CronUIInterface $ui;
- protected LoggerInterface $logger;
- #[Pure]
- public function __construct()
- {
- $this->ui = new SilentUI();
- }
- #[Required]
- /** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
- public function setLoggerInterface(LoggerInterface $cronLogger): void { $this->logger = $cronLogger; }
- final public function name(): string {
- return StringsUtils::camelToSnake(
- preg_replace('/(?:\w+\\\)*(\w+)$/', '$1', static::class),
- '-'
- );
- }
- public function setUI(CronUIInterface $ui): void {
- $this->ui = $ui;
- }
- }
|