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

41 lines
882 B
PHP

<?php
namespace KupShop\ContentBundle\Util;
use KupShop\ContentBundle\Exception\UnknownSitemapTypeException;
use KupShop\ContentBundle\Sitemap\SitemapInterface;
class SitemapLocator
{
private $handlers;
public function __construct(iterable $handlers)
{
$this->handlers = $handlers;
}
public function getTypes(): array
{
$types = [];
foreach ($this->handlers as $handler) {
if ($handler::isAllowed()) {
$types[] = $handler::getType();
}
}
return $types;
}
public function getSitemap(string $type): SitemapInterface
{
foreach ($this->handlers as $handler) {
if ($handler::getType() === $type && $handler::isAllowed()) {
return $handler;
}
}
throw new UnknownSitemapTypeException($type);
}
}