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

37 lines
900 B
PHP

<?php
namespace External\MSSQLBundle\Util;
use External\MSSQLBundle\Exception\MoneyException;
use External\MSSQLBundle\Synchronizers\SynchronizerInterface;
use Symfony\Component\DependencyInjection\ServiceLocator;
class SynchronizerLocator
{
private $locator;
private $servicesByTypes;
public function __construct(ServiceLocator $locator, array $servicesByTypes)
{
$this->locator = $locator;
$this->servicesByTypes = $servicesByTypes;
}
/**
* @return SynchronizerInterface
*
* @throws MoneyException
*/
public function getServiceByType(string $type)
{
$id = $this->servicesByTypes[$type] ?? null;
if (!$this->locator->get($id)) {
throw new MoneyException(
sprintf('Unknown synchronizer type \'%s\'!', $type)
);
}
return $this->locator->get($id);
}
}