Completed
Pull Request — master (#632)
by mingyoung
02:45
created

ContainerAccess::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
/**
13
 * ContainerAccess.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @copyright 2017
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\Foundation;
28
29
use Pimple\Container;
30
31
/**
32
 * Class ContainerAccess.
33
 */
34
abstract class ContainerAccess
35
{
36
    /**
37
     * Container prefix.
38
     *
39
     * @var string
40
     */
41
    protected $containerPrefix;
42
43
    /**
44
     * Container.
45
     *
46
     * @var \Pimple\Container
47
     */
48
    protected $container;
49
50
    /**
51
     * ContainerAccess constructor.
52
     *
53
     * @param \Pimple\Container $container
54
     */
55
    public function __construct(Container $container)
56
    {
57
        $this->container = $container;
58
    }
59
60
    /**
61
     * Gets a parameter or an object from pimple container.
62
     *
63
     * @param string $key The unique identifier for the parameter or object
64
     *
65
     * @return mixed The value of the parameter or an object
66
     *
67
     * @throws \InvalidArgumentException if the identifier is not defined
68
     */
69
    public function __get($key)
70
    {
71
        return $this->container->offsetGet($this->containerPrefix.$key);
72
    }
73
}
74