Files
kupshop/bundles/KupShop/ContentBundle/Util/PageLocator.php
2025-08-02 16:30:27 +02:00

42 lines
934 B
PHP

<?php
namespace KupShop\ContentBundle\Util;
use KupShop\ContentBundle\Exception\UnknownPageTypeException;
use KupShop\ContentBundle\Page\PageInterface;
use Symfony\Component\DependencyInjection\ServiceLocator;
class PageLocator
{
private $locator;
private $pages;
public function __construct(ServiceLocator $locator, array $pages)
{
$this->locator = $locator;
$this->pages = $pages;
}
public function getTypes()
{
return array_keys($this->pages);
}
/**
* @return PageInterface
*
* @throws UnknownPageTypeException
*/
public function getPageService(string $type)
{
if (isset($this->pages[$type])) {
$class = $this->pages[$type]['class'];
if ($this->locator->has($class)) {
return $this->locator->get($class);
}
}
throw new UnknownPageTypeException($type);
}
}