Files
kupshop/bundles/External/VarioBundle/Util/SynchronizerLocator.php
2025-08-02 16:30:27 +02:00

34 lines
810 B
PHP

<?php
namespace External\VarioBundle\Util;
use External\VarioBundle\Exception\SynchronizerException;
use External\VarioBundle\Synchronizers\SynchronizerInterface;
use Symfony\Component\DependencyInjection\ServiceLocator;
class SynchronizerLocator
{
private $locator;
public function __construct(ServiceLocator $locator)
{
$this->locator = $locator;
}
public function getTypes(): array
{
return array_keys($this->locator->getProvidedServices());
}
public function getServiceByType(string $type): SynchronizerInterface
{
if (!$this->locator->has($type)) {
throw new SynchronizerException(
sprintf('Unknown synchronizer type \'%s\'!', $type)
);
}
return $this->locator->get($type);
}
}