ObblmExtraLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
ccs 0
cts 14
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A supports() 0 3 1
A load() 0 16 3
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