Container   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 14 3
A has() 0 4 1
A merge() 0 6 2
A add() 0 6 3
1
<?php
2
3
/*
4
 * This file is part of the jade/jade package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jade;
13
14
use Pimple\Container as PimpleContainer;
15
use Jade\Exception\ContainerException;
16
use Jade\Exception\ContainerValueNotFoundException;
17
18
class Container extends PimpleContainer implements ContainerInterface
19
{
20
    /**
21
     * 从容器中获取实例对象或者其它资源
22
     *
23
     * @param string $id
24
     * @return mixed
25
     */
26
    public function get($id)
27
    {
28
        if (!$this->offsetExists($id)) {
29
            throw new ContainerValueNotFoundException(sprintf('Identifier "%s" is not defined.', $id));
30
        }
31
        try {
32
            return $this->offsetGet($id);
33
        } catch (\InvalidArgumentException $exception) {
34
            throw new ContainerException(sprintf('Container error while retrieving "%s"', $id),
35
                null,
36
                $exception
37
            );
38
        }
39
    }
40
41
    /**
42
     * 检查容器是否存储该资源,如果存在返回true,否则返回false
43
     *
44
     * @param string $id Identifier of the entry to look for.
45
     *
46
     * @return boolean
47
     */
48
    public function has($id)
49
    {
50
        return $this->offsetExists($id);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function merge(array $values)
57
    {
58
        foreach ($values as $key => $value) {
59
            $this[$key] = $value;
60
        }
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function add(array $values)
67
    {
68
        foreach ($values as $key => $value) {
69
            $this->offsetExists($key) || $this[$key] = $value;
70
        }
71
    }
72
}