Completed
Push — master ( e81671...a22352 )
by André
93:06 queued 73:42
created

URLHandlerRegistry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addHandler() 0 4 1
A supported() 0 4 1
A getHandler() 0 8 2
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\URLChecker;
8
9
use InvalidArgumentException;
10
11
class URLHandlerRegistry implements URLHandlerRegistryInterface
12
{
13
    /**
14
     * @var \eZ\Bundle\EzPublishCoreBundle\URLChecker\URLHandlerInterface[]
15
     */
16
    private $handlers = [];
17
18
    /**
19
     * URLHandlerRegistry constructor.
20
     */
21
    public function __construct()
22
    {
23
        $this->handlers = [];
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function addHandler($scheme, URLHandlerInterface $handler)
30
    {
31
        $this->handlers[$scheme] = $handler;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function supported($scheme)
38
    {
39
        return isset($this->handlers[$scheme]);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getHandler($scheme)
46
    {
47
        if (!$this->supported($scheme)) {
48
            throw new InvalidArgumentException("Unsupported URL scheme: $scheme");
49
        }
50
51
        return $this->handlers[$scheme];
52
    }
53
}
54