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

HandlerRegistry::getConfiguredHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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