Test Failed
Push — sudav3 ( bd404a...699e88 )
by 世昌
02:19
created

ApplicationContext::getDataPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace suda\application;
3
4
use suda\orm\DataSource;
5
use suda\framework\Config;
6
use suda\framework\Context;
7
use suda\application\Resource;
8
use suda\framework\loader\Loader;
9
use suda\framework\arrayobject\ArrayDotAccess;
10
11
/**
12
 * 应用程序环境
13
 */
14
class ApplicationContext extends Context
15
{
16
    /**
17
     * 应用路径
18
     *
19
     * @var string
20
     */
21
    protected $path;
22
23
24
    /**
25
     * 数据路径
26
     *
27
     * @var string
28
     */
29
    protected $dataPath;
30
31
    /**
32
     * 配置数组
33
     *
34
     * @var array
35
     */
36
    protected $manifast;
37
38
    /**
39
     * 语言
40
     *
41
     * @var string
42
     */
43
    protected $locate;
44
45
    /**
46
     * 使用的样式
47
     *
48
     * @var string
49
     */
50
    protected $style;
51
52
    /**
53
     * 路由组
54
     *
55
     * @var array
56
     */
57
    protected $routeGroup;
58
59
    /**
60
     * 资源目录
61
     *
62
     * @var Resource
63
     */
64
    protected $resource;
65
66
    /**
67
     * 数据源
68
     *
69
     * @var DataSource
70
     */
71
    protected $dataSource;
72
73
    /**
74
     * 创建应用
75
     *
76
     * @param string $path
77
     * @param array $manifast
78
     * @param \suda\framework\loader\Loader $loader
79
     */
80
    public function __construct(string $path, array $manifast, Loader $loader, string $dataPath = null)
81
    {
82
        parent::__construct(new Config(['app' => $manifast]), $loader);
83
        $this->path = $path;
84
        $this->routeGroup = $manifast['route-group'] ?? ['default'];
85
        $this->resource = new Resource([Resource::getPathByRelativedPath($manifast['resource'] ?? './resource', $path)]);
86
        $this->locate = $manifast['locale'] ?? 'zh-cn';
87
        $this->style = $manifast['style'] ?? 'default';
88
        $this->manifast = $manifast;
89
        $this->dataPath = $dataPath ?? Resource::getPathByRelativedPath($manifast['resource'] ?? './data', $path);
90
    }
91
92
    /**
93
     * Get 使用的样式
94
     *
95
     * @return  string
96
     */
97
    public function getStyle()
98
    {
99
        return $this->style;
100
    }
101
102
    /**
103
     * Set 使用的样式
104
     *
105
     * @param  string  $style  使用的样式
106
     *
107
     * @return  self
108
     */
109
    public function setStyle(string $style)
110
    {
111
        $this->style = $style;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Get 语言
118
     *
119
     * @return  string
120
     */
121
    public function getLocate()
122
    {
123
        return $this->locate;
124
    }
125
126
    /**
127
     * Set 语言
128
     *
129
     * @param  string  $locate  语言
130
     *
131
     * @return  self
132
     */
133
    public function setLocate(string $locate)
134
    {
135
        $this->locate = $locate;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Get 配置数组
142
     *
143
     * @return  mixed
144
     */
145
    public function getManifast(string $name = null, $default = null)
146
    {
147
        if ($name !== null) {
148
            return ArrayDotAccess::get($this->manifast, $name, $default);
149
        }
150
        return $this->manifast;
151
    }
152
153
    /**
154
     * Get 路由组
155
     *
156
     * @return  array
157
     */
158
    public function getRouteGroup()
159
    {
160
        return $this->routeGroup;
161
    }
162
163
    /**
164
     * Get 数据源
165
     *
166
     * @return  Resource
167
     */
168
    public function getResource(): Resource
169
    {
170
        return $this->resource;
171
    }
172
173
    /**
174
     * Set 数据源
175
     *
176
     * @param  Resource  $resource  数据源
177
     *
178
     * @return  self
179
     */
180
    public function setResource(Resource $resource)
181
    {
182
        $this->resource = $resource;
183
184
        return $this;
185
    }
186
187
    /**
188
     * Get 数据源
189
     *
190
     * @return  DataSource
191
     */
192
    public function getDataSource()
193
    {
194
        return $this->dataSource;
195
    }
196
197
    /**
198
     * Set 数据源
199
     *
200
     * @param  DataSource  $dataSource  数据源
201
     *
202
     * @return  self
203
     */
204
    public function setDataSource(DataSource $dataSource)
205
    {
206
        $this->dataSource = $dataSource;
207
208
        return $this;
209
    }
210
211
    /**
212
     * Get 应用路径
213
     *
214
     * @return  string
215
     */
216
    public function getPath()
217
    {
218
        return $this->path;
219
    }
220
221
    /**
222
     * Get 数据路径
223
     *
224
     * @return  string
225
     */ 
226
    public function getDataPath()
227
    {
228
        return $this->dataPath;
229
    }
230
231
    /**
232
     * Set 数据路径
233
     *
234
     * @param  string  $dataPath  数据路径
235
     *
236
     * @return  self
237
     */ 
238
    public function setDataPath(string $dataPath)
239
    {
240
        $this->dataPath = $dataPath;
241
242
        return $this;
243
    }
244
}
245