41 lines
882 B
PHP
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);
|
|
}
|
|
}
|