ObblmExtraLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Obblm\Core\Routing;
4
5
use Symfony\Component\Config\Loader\Loader;
6
use Symfony\Component\Routing\RouteCollection;
7
8
class ObblmExtraLoader extends Loader
9
{
10
    public const ROUTE_TYPE_NAME = 'obblm';
11
12
    private $isLoaded = false;
13
    private $routeAutoloader = false;
14
15
    public function __construct(RouteAutoloader $routeAutoloader)
16
    {
17
        $this->routeAutoloader = $routeAutoloader;
18
    }
19
20
    public function load($resource, string $type = null)
21
    {
22
        if (true === $this->isLoaded) {
23
            throw new \RuntimeException('Do not add the "extra" loader twice');
24
        }
25
26
        $routes = new RouteCollection();
27
28
        foreach ($this->routeAutoloader->getObblmRoutes() as $route) {
29
            $importedRoutes = $this->import($route['resource'], $route['type']);
30
            $routes->addCollection($importedRoutes);
31
        }
32
33
        $this->isLoaded = true;
34
35
        return $routes;
36
    }
37
38
    public function supports($resource, string $type = null)
39
    {
40
        return 'obblm' === $type;
41
    }
42
}
43