Completed
Push — master ( 8ea878...f68d6a )
by Łukasz
15:34
created

HandlerRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setHandlersMap() 0 4 1
A getConfiguredHandler() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishIOBundle\ApiLoader;
10
11
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
12
13
/**
14
 * Registry of IO handlers, given an alias.
15
 */
16
class HandlerRegistry
17
{
18
    /**
19
     * Map of handler id to handler service id.
20
     *
21
     * @var array
22
     */
23
    private $handlersMap = [];
24
25
    public function setHandlersMap($handlersMap)
26
    {
27
        $this->handlersMap = $handlersMap;
28
    }
29
30
    /**
31
     * @param string $handlerName
32
     *
33
     * @return object an instance of the requested handler
34
     *
35
     * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException If the requested handler doesn't exist
36
     */
37
    public function getConfiguredHandler($handlerName)
38
    {
39
        if (!isset($this->handlersMap[$handlerName])) {
40
            throw new InvalidConfigurationException("Unknown handler $handlerName");
41
        }
42
43
        return $this->handlersMap[$handlerName];
44
    }
45
}
46