RoutingAnnotationLoader::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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