Completed
Push — master ( 1ae43c...a59297 )
by Carlos
03:01
created

PrefixedContainer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 37
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 8 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
 * Trait PrefixedContainer.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\Support\Traits;
28
29
use EasyWeChat\Support\Str;
30
use Pimple\Container;
31
32
/**
33
 * Trait PrefixedContainer.
34
 */
35
trait PrefixedContainer
36
{
37
    /**
38
     * Container.
39
     *
40
     * @var \Pimple\Container
41
     */
42
    protected $container;
43
44
    /**
45
     * ContainerAccess constructor.
46
     *
47
     * @param \Pimple\Container $container
48
     */
49
    public function __construct(Container $container)
50
    {
51
        $this->container = $container;
52
    }
53
54
    /**
55
     * Gets a parameter or an object from pimple container.
56
     *
57
     * @param string $key The unique identifier for the parameter or object
58
     *
59
     * @return mixed The value of the parameter or an object
60
     *
61
     * @throws \InvalidArgumentException if the identifier is not defined
62
     */
63
    public function __get($key)
64
    {
65
        $className = (new \ReflectionClass($this))->getShortName();
66
67
        $name = Str::snake($className).'.'.$key;
68
69
        return $this->container->offsetGet($name);
70
    }
71
}
72