Files
breadcrumb-the-shire/core/Service/Scheduler/SchedulerServicesFactory.php

114 lines
3.9 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Service\Scheduler;
use MintyPHP\App\AppContainer;
use MintyPHP\App\Module\ModuleEventDispatcher;
2026-03-05 08:26:51 +01:00
use MintyPHP\Repository\Scheduler\ScheduledJobRepositoryInterface;
use MintyPHP\Repository\Scheduler\ScheduledJobRunRepositoryInterface;
use MintyPHP\Repository\Scheduler\SchedulerRuntimeRepositoryInterface;
2026-03-04 15:56:58 +01:00
use MintyPHP\Repository\Support\DatabaseSessionRepository;
use MintyPHP\Service\Audit\AuditRecorderInterface;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\User\UserLifecycleService;
use MintyPHP\Service\User\UserServicesFactory;
class SchedulerServicesFactory
{
private ?ScheduleCalculator $scheduleCalculator = null;
private ?ScheduledJobRegistry $scheduledJobRegistry = null;
private ?ScheduledJobService $scheduledJobService = null;
private ?SchedulerRunService $schedulerRunService = null;
2026-03-04 15:56:58 +01:00
public function __construct(
private readonly UserServicesFactory $userServicesFactory,
private readonly AuditRecorderInterface $auditRecorder,
2026-03-04 15:56:58 +01:00
private readonly DatabaseSessionRepository $databaseSessionRepository,
private readonly SchedulerRepositoryFactory $schedulerRepositoryFactory,
private readonly AppContainer $appContainer
2026-03-05 11:17:42 +01:00
) {
}
2026-03-04 15:56:58 +01:00
2026-02-23 12:58:19 +01:00
public function createScheduledJobService(): ScheduledJobService
{
return $this->scheduledJobService ??= new ScheduledJobService(
$this->getScheduledJobRepository(),
$this->getScheduledJobRunRepository(),
$this->getScheduledJobRegistry(),
$this->getScheduleCalculator()
);
}
public function createSchedulerRunService(): SchedulerRunService
{
return $this->schedulerRunService ??= new SchedulerRunService(
$this->createScheduledJobService(),
$this->getScheduledJobRepository(),
$this->getScheduledJobRunRepository(),
$this->getSchedulerRuntimeRepository(),
$this->getScheduledJobRegistry(),
2026-03-04 15:56:58 +01:00
$this->getScheduleCalculator(),
$this->getDatabaseSessionRepository(),
$this->getAuditRecorder(),
$this->getEventDispatcher()
2026-02-23 12:58:19 +01:00
);
}
public function createUserLifecycleService(): UserLifecycleService
{
return $this->getUserLifecycleService();
}
2026-03-05 08:26:51 +01:00
private function getScheduledJobRepository(): ScheduledJobRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->schedulerRepositoryFactory->createScheduledJobRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
private function getScheduledJobRunRepository(): ScheduledJobRunRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->schedulerRepositoryFactory->createScheduledJobRunRepository();
2026-02-23 12:58:19 +01:00
}
2026-03-05 08:26:51 +01:00
private function getSchedulerRuntimeRepository(): SchedulerRuntimeRepositoryInterface
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->schedulerRepositoryFactory->createSchedulerRuntimeRepository();
2026-02-23 12:58:19 +01:00
}
private function getScheduleCalculator(): ScheduleCalculator
{
return $this->scheduleCalculator ??= new ScheduleCalculator();
}
private function getUserLifecycleService(): UserLifecycleService
{
2026-03-04 15:56:58 +01:00
return $this->userServicesFactory->createUserLifecycleService();
2026-02-23 12:58:19 +01:00
}
private function getScheduledJobRegistry(): ScheduledJobRegistry
{
2026-03-04 15:56:58 +01:00
return $this->scheduledJobRegistry ??= new ScheduledJobRegistry(
$this->getUserLifecycleService(),
$this->appContainer
2026-03-04 15:56:58 +01:00
);
2026-02-23 12:58:19 +01:00
}
2026-03-04 15:56:58 +01:00
private function getDatabaseSessionRepository(): DatabaseSessionRepository
2026-02-23 12:58:19 +01:00
{
2026-03-04 15:56:58 +01:00
return $this->databaseSessionRepository;
2026-02-23 12:58:19 +01:00
}
2026-03-04 15:56:58 +01:00
private function getAuditRecorder(): AuditRecorderInterface
2026-03-04 15:56:58 +01:00
{
return $this->auditRecorder;
2026-03-04 15:56:58 +01:00
}
private function getEventDispatcher(): ?ModuleEventDispatcher
{
if ($this->appContainer->has(ModuleEventDispatcher::class)) {
$dispatcher = $this->appContainer->get(ModuleEventDispatcher::class);
return $dispatcher instanceof ModuleEventDispatcher ? $dispatcher : null;
}
return null;
}
2026-02-23 12:58:19 +01:00
}