RoutingAnnotationLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Routing;
4
5
use DH\DoctrineAuditBundle\Controller\ViewerController;
6
use RuntimeException;
7
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
8
use Symfony\Component\Config\Loader\Loader;
9
use Symfony\Component\Routing\RouteCollection;
10
11
class RoutingAnnotationLoader extends Loader
12
{
13
    /**
14
     * @var AnnotatedRouteControllerLoader
15
     */
16
    private $annotatedRouteControllerLoader;
17
18
    /**
19
     * @var bool
20
     */
21
    private $isLoaded = false;
22
23
    /**
24
     * @var array
25
     */
26
    private $configuration;
27
28
    public function __construct(AnnotatedRouteControllerLoader $annotatedRouteController, array $configuration)
29
    {
30
        $this->annotatedRouteControllerLoader = $annotatedRouteController;
31
        $this->configuration = $configuration;
32
    }
33
34
    public function load($resource, ?string $type = null): RouteCollection
35
    {
36
        if (true === $this->isLoaded) {
37
            throw new RuntimeException('Do not add the "audit" loader twice');
38
        }
39
40
        $routeCollection = new RouteCollection();
41
        if (true === $this->configuration['enabled_viewer']) {
42
            $routeCollection = $this->annotatedRouteControllerLoader->load(ViewerController::class);
43
        }
44
45
        $this->isLoaded = true;
46
47
        return $routeCollection;
48
    }
49
50
    public function supports($resource, ?string $type = null): bool
51
    {
52
        return 'audit' === $type;
53
    }
54
}
55