AliasSitemapProvider::all()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 9
Bugs 2 Features 0
Metric Value
cc 2
eloc 9
c 9
b 2
f 0
nc 2
nop 1
dl 0
loc 18
ccs 0
cts 13
cp 0
crap 6
rs 9.9666
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Bundle\UrlBundle\Url;
7
8
use Doctrine\DBAL\Connection;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
11
use Zicht\Bundle\UrlBundle\Entity\UrlAlias;
12
use Zicht\Bundle\UrlBundle\Event\SitemapFilterEvent;
13
use Zicht\Bundle\UrlBundle\Events;
14
15
/**
16
 * This Provider used to be optimistic, however now has been made a bit smarter while maintaining backwards compatibility.
17
 */
18
class AliasSitemapProvider implements ListableProvider
19
{
20
    /** @var Connection  */
21
    private $connection;
22
    /** @var EventDispatcherInterface  */
23
    private $eventDispatcher;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param Connection $connection
29
     */
30
    public function __construct(Connection $connection, EventDispatcherInterface $eventDispatcher)
31
    {
32
        $this->connection = $connection;
33
        $this->eventDispatcher = $eventDispatcher;
34
    }
35
36
    /**
37
     * @{inheritDoc}
38
     */
39
    public function all(AuthorizationCheckerInterface $authorizationChecker)
40
    {
41
        $query = $this->connection->prepare('SELECT * FROM url_alias WHERE mode=?');
42
        $query->execute([UrlAlias::REWRITE]);
43
        $urls = new \ArrayObject($query->fetchAll(\PDO::FETCH_ASSOC));
44
45
        /**
46
         * Hook to allow the mapping to be modified at run-time.
47
         */
48
        if ($this->eventDispatcher->hasListeners(Events::EVENT_SITEMAP_FILTER)) {
49
            $this->eventDispatcher->dispatch(Events::EVENT_SITEMAP_FILTER, new SitemapFilterEvent($urls));
50
        }
51
52
        return array_map(
53
            function ($url) {
54
                return ['value' => $url['public_url']];
55
            },
56
            $urls->getArrayCopy()
57
        );
58
    }
59
}
60