Completed
Push — master ( da2f6e...d3b8cb )
by Kamil
20:06
created

SitemapBuilder::addProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Sylius\Bundle\CoreBundle\Sitemap\Builder;
13
14
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactoryInterface;
15
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface;
16
use Symfony\Component\DependencyInjection\ContainerAware;
17
18
/**
19
 * @author Arkadiusz Krakowiak <[email protected]>
20
 */
21
class SitemapBuilder implements SitemapBuilderInterface
22
{
23
    /**
24
     * @var SitemapFactoryInterface
25
     */
26
    private $sitemapFactory;
27
28
    /**
29
     * @var array
30
     */
31
    private $providers = [];
32
33
    /**
34
     * @param SitemapFactoryInterface $sitemapFactory
35
     */
36
    public function __construct(SitemapFactoryInterface $sitemapFactory)
37
    {
38
        $this->sitemapFactory = $sitemapFactory;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function addProvider(UrlProviderInterface $provider)
45
    {
46
        $this->providers[] = $provider;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function build()
53
    {
54
        $sitemap = $this->sitemapFactory->createNew();
55
        $urls = [];
56
57
        foreach ($this->providers as $provider) {
58
            $urls = array_merge($urls, $provider->generate());
59
        }
60
        $sitemap->setUrls($urls);
61
62
        return $sitemap;
63
    }
64
}
65