43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace KupShop\FeedGeneratorBundle;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
class ContextPropertiesLocator
|
|
{
|
|
/** @var ContainerInterface */
|
|
private $container;
|
|
|
|
/** @var array */
|
|
private $contexts = [];
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
{
|
|
$this->container = $container;
|
|
}
|
|
|
|
public function addContextProperty($serviceID, string $name)
|
|
{
|
|
if (isset($this->contexts[$name])) {
|
|
throw new \Exception('Duplicated feed generator context property name "'.$name.'" from service "'.$serviceID.'"!');
|
|
}
|
|
$this->contexts[$name] = ['serviceID' => $serviceID];
|
|
}
|
|
|
|
public function sortContexts()
|
|
{
|
|
ksort($this->contexts, SORT_STRING);
|
|
}
|
|
|
|
public function getContexts(): array
|
|
{
|
|
return $this->contexts;
|
|
}
|
|
|
|
public function getServiceByContextName(string $name)
|
|
{
|
|
return isset($this->contexts[$name]) ? $this->container->get($this->contexts[$name]['serviceID']) : null;
|
|
}
|
|
}
|