1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slince/spike package. |
5
|
|
|
* |
6
|
|
|
* (c) Slince <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Spike\Client; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Slince\Config\Config; |
17
|
|
|
use Spike\Common\Tunnel\TunnelFactory; |
18
|
|
|
use Spike\Common\Tunnel\TunnelInterface; |
19
|
|
|
|
20
|
|
|
class Configuration extends Config |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var TunnelInterface[]|Collection |
24
|
|
|
*/ |
25
|
|
|
protected $tunnels; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return TunnelInterface[]|Collection |
29
|
|
|
*/ |
30
|
|
|
public function getTunnels() |
31
|
|
|
{ |
32
|
|
|
if ($this->tunnels) { |
33
|
|
|
return $this->tunnels; |
34
|
|
|
} |
35
|
|
|
$data = $this->get('tunnels', []); |
36
|
|
|
$tunnels = []; |
37
|
|
|
foreach ($data as $info) { |
38
|
|
|
$tunnel = TunnelFactory::fromArray($info); |
39
|
|
|
$tunnels[] = $tunnel; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $this->tunnels = new ArrayCollection($tunnels); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Gets the current timezone. |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function getTimezone() |
51
|
|
|
{ |
52
|
|
|
return $this->get('timezone', 'Asia/shanghai'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Gets the log file. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getLogFile() |
61
|
|
|
{ |
62
|
|
|
return isset($this['log']['file']) ? $this['log']['file'] : getcwd().'/access.log'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Gets the log level. |
67
|
|
|
* |
68
|
|
|
* @return int |
69
|
|
|
*/ |
70
|
|
|
public function getLogLevel() |
71
|
|
|
{ |
72
|
|
|
return isset($this['log']['level']) ? $this['log']['level'] : 'info'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getServerAddress() |
76
|
|
|
{ |
77
|
|
|
$address = $this->get('server-address', '127.0.0.1:8090'); |
78
|
|
|
|
79
|
|
|
return $address; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getDefaultConfigFile() |
83
|
|
|
{ |
84
|
|
|
return getcwd().'/'.'spike.json'; |
85
|
|
|
} |
86
|
|
|
} |