43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\UrlGenerator;
|
|
|
|
use App\Core\Entity\Site\Node;
|
|
use App\Repository\Blog\PostRepositoryQuery;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
/**
|
|
* class FooUrlGenerator.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class FooUrlGenerator
|
|
{
|
|
protected UrlGeneratorInterface $urlGenerator;
|
|
protected PostRepositoryQuery $postRepositoryQuery;
|
|
|
|
public function __construct(UrlGeneratorInterface $urlGenerator, PostRepositoryQuery $postRepositoryQuery)
|
|
{
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->postRepositoryQuery = $postRepositoryQuery;
|
|
}
|
|
|
|
public function generateIndex(Node $node, array $options): array
|
|
{
|
|
$posts = $this->postRepositoryQuery->create()->find();
|
|
$urls = [];
|
|
|
|
foreach ($posts as $post) {
|
|
$urls[] = $this->urlGenerator->generate(
|
|
$node->getRouteName(),
|
|
[
|
|
'post' => $post->getId(),
|
|
],
|
|
UrlGeneratorInterface::ABSOLUTE_URL
|
|
);
|
|
}
|
|
|
|
return $urls;
|
|
}
|
|
}
|