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

URLHandlerRegistry::supported()   A

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
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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