46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\SynchronizationBundle\Util;
|
|
|
|
use KupShop\SynchronizationBundle\Synchronization\Job;
|
|
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
|
|
use Symfony\Component\DependencyInjection\ServiceLocator;
|
|
|
|
class SynchronizationJobProvider
|
|
{
|
|
/** @var Job[] */
|
|
private ?array $jobs = null;
|
|
|
|
public function __construct(
|
|
#[TaggedLocator(tag: 'kupshop.synchronization.register')] protected ServiceLocator $registerLocator,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return Job[]
|
|
*/
|
|
public function getJobs(): array
|
|
{
|
|
if ($this->jobs === null) {
|
|
$this->jobs = [];
|
|
|
|
foreach ($this->registerLocator->getProvidedServices() as $serviceId => $classId) {
|
|
foreach ($this->registerLocator->get($serviceId)->getJobs() as $job) {
|
|
$this->jobs[$job->id] = $job;
|
|
}
|
|
}
|
|
|
|
uasort($this->jobs, fn ($a, $b) => $b->priority <=> $a->priority);
|
|
}
|
|
|
|
return $this->jobs;
|
|
}
|
|
|
|
public function getJob(string $id): ?Job
|
|
{
|
|
return $this->getJobs()[$id] ?? null;
|
|
}
|
|
}
|