Passed
Push — dev ( 6b4bd1...b901d7 )
by 世昌
02:22
created

PHPContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 109
rs 10
c 2
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A loader() 0 3 1
A __construct() 0 4 1
A setConfig() 0 5 1
A getLoader() 0 3 1
A conf() 0 3 1
A config() 0 3 1
A setLoader() 0 5 1
A getConfig() 0 3 1
1
<?php
2
namespace suda\framework\context;
3
4
use suda\framework\Config;
5
use suda\framework\Debugger;
6
use suda\framework\loader\Loader;
7
8
/**
9
 * PHP环境
10
 */
11
class PHPContext
12
{
13
    /**
14
     * PHP自动加载
15
     *
16
     * @var Loader
17
     */
18
    protected $loader;
19
20
    /**
21
     * 全局配置
22
     *
23
     * @var Config
24
     */
25
    protected $config;
26
27
28
    /**
29
     * 创建PHP环境
30
     *
31
     * @param Config $config
32
     * @param Loader $loader
33
     */
34
    public function __construct(Config $config, Loader $loader)
35
    {
36
        $this->loader = $loader;
37
        $this->config = $config;
38
    }
39
40
    /**
41
     * 获取加载器
42
     *
43
     * @return Loader
44
     */
45
    public function loader():Loader
46
    {
47
        return $this->loader;
48
    }
49
50
51
    /**
52
     * 获取配置
53
     *
54
     * @return Config
55
     */
56
    public function config():Config
57
    {
58
        return $this->config;
59
    }
60
61
62
    /**
63
     * 获取配置信息
64
     *
65
     * @param string $name
66
     * @param mixed $default
67
     * @return mixed
68
     */
69
    public function conf(string $name, $default = null)
70
    {
71
        return $this->config->get($name, $default);
72
    }
73
74
    /**
75
     * Get PHP自动加载
76
     *
77
     * @return  Loader
78
     */
79
    public function getLoader()
80
    {
81
        return $this->loader;
82
    }
83
84
    /**
85
     * Set PHP自动加载
86
     *
87
     * @param Loader $loader  PHP自动加载
88
     *
89
     * @return  self
90
     */
91
    public function setLoader(Loader $loader)
92
    {
93
        $this->loader = $loader;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Get 全局配置
100
     *
101
     * @return  Config
102
     */
103
    public function getConfig()
104
    {
105
        return $this->config;
106
    }
107
108
    /**
109
     * Set 全局配置
110
     *
111
     * @param Config $config  全局配置
112
     *
113
     * @return  self
114
     */
115
    public function setConfig(Config $config)
116
    {
117
        $this->config = $config;
118
119
        return $this;
120
    }
121
}
122