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

ContainerAccess   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __get() 0 4 1
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
 * @package EasyWeChat\Foundation
35
 */
36
abstract class ContainerAccess
37
{
38
    /**
39
     * Container prefix.
40
     *
41
     * @var string
42
     */
43
    protected $containerPrefix;
44
45
    /**
46
     * Container.
47
     *
48
     * @var \Pimple\Container
49
     */
50
    protected $container;
51
52
    /**
53
     * MiniProgram constructor.
54
     *
55
     * @param \Pimple\Container $container
56
     */
57
    public function __construct(Container $container)
58
    {
59
        $this->container = $container;
60
    }
61
62
    /**
63
     * Gets a parameter or an object from pimple container.
64
     *
65
     * @param string $key The unique identifier for the parameter or object
66
     *
67
     * @return mixed The value of the parameter or an object
68
     *
69
     * @throws \InvalidArgumentException if the identifier is not defined
70
     */
71
    public function __get($key)
72
    {
73
        return $this->container->offsetGet($this->containerPrefix.$key);
74
    }
75
}
76