ResolverChain::addResolver()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Service;
12
13
use Jb\Bundle\FileUploaderBundle\Exception\JbFileUploaderException;
14
use Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface;
15
16
/**
17
 * ResolverChain
18
 *
19
 * @author jobou
20
 */
21 View Code Duplication
class ResolverChain
22
{
23
    /**
24
     * @var array
25
     */
26
    private $resolvers;
27
28
    /**
29
     * Constructor
30
     */
31
    public function __construct()
32
    {
33
        $this->resolvers = array();
34
    }
35
36
    /**
37
     * Add a resolver
38
     *
39
     * @param \Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface $resolver
40
     */
41
    public function addResolver(ResolverInterface $resolver, $alias)
42
    {
43
        $this->resolvers[$alias] = $resolver;
44
    }
45
46
    /**
47
     *
48
     * @param string $alias
49
     *
50
     * @return \Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface
51
     *
52
     * @throws \Jb\Bundle\FileUploaderBundle\Exception\JbFileUploaderException
53
     */
54
    public function getResolver($alias)
55
    {
56
        if (array_key_exists($alias, $this->resolvers)) {
57
            return $this->resolvers[$alias];
58
        }
59
60
        throw new JbFileUploaderException('Unknown resolver ' . $alias);
61
    }
62
}
63