Passed
Push — master ( 8a8c4e...760901 )
by Christian
20:05 queued 09:47
created

SitemapPageLoader::generateSitemap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Page\Sitemap;
4
5
use Shopware\Core\Content\Sitemap\SalesChannel\AbstractSitemapRoute;
6
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
7
use Shopware\Core\System\SalesChannel\SalesChannelContext;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class SitemapPageLoader
12
{
13
    /**
14
     * @var EventDispatcherInterface
15
     */
16
    private $eventDispatcher;
17
18
    /**
19
     * @var AbstractSitemapRoute
20
     */
21
    private $sitemapRoute;
22
23
    public function __construct(
24
        EventDispatcherInterface $eventDispatcher,
25
        AbstractSitemapRoute $sitemapRoute
26
    ) {
27
        $this->eventDispatcher = $eventDispatcher;
28
        $this->sitemapRoute = $sitemapRoute;
29
    }
30
31
    /**
32
     * @throws InconsistentCriteriaIdsException
33
     */
34
    public function load(Request $request, SalesChannelContext $context): SitemapPage
35
    {
36
        $page = new SitemapPage();
37
        $page->setSitemaps($this->sitemapRoute->load($request, $context)->getSitemaps()->getElements());
38
39
        $this->eventDispatcher->dispatch(
40
            new SitemapPageLoadedEvent($page, $context, $request)
41
        );
42
43
        return $page;
44
    }
45
}
46