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\Server; |
13
|
|
|
|
14
|
|
|
use Slince\Config\Config; |
15
|
|
|
use Spike\Common\Authentication\AuthenticationInterface; |
16
|
|
|
use Spike\Common\Authentication; |
17
|
|
|
|
18
|
|
|
class Configuration extends Config |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Gets the current timezone. |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function getTimezone() |
26
|
|
|
{ |
27
|
|
|
return $this->get('timezone', 'Asia/shanghai'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Gets the log file. |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getLogFile() |
36
|
|
|
{ |
37
|
|
|
return isset($this['log']['file']) ? $this['log']['file'] : getcwd().'/access.log'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Gets the log level. |
42
|
|
|
* |
43
|
|
|
* @return int |
44
|
|
|
*/ |
45
|
|
|
public function getLogLevel() |
46
|
|
|
{ |
47
|
|
|
return isset($this['log']['level']) ? $this['log']['level'] : 'info'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Gets the server address to bind. |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getAddress() |
56
|
|
|
{ |
57
|
|
|
$address = $this->get('address', '0.0.0.0:8090'); |
58
|
|
|
|
59
|
|
|
return $address; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Gets the config file. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getDefaultConfigFile() |
68
|
|
|
{ |
69
|
|
|
return getcwd().'/'.'spiked.json'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Gets the authentication. |
74
|
|
|
* |
75
|
|
|
* @return AuthenticationInterface|null |
76
|
|
|
*/ |
77
|
|
|
public function getAuthentication() |
78
|
|
|
{ |
79
|
|
|
$auth = $this->get('auth', []); |
80
|
|
|
$type = isset($auth['type']) ? $auth['type'] : 'simple_password'; |
81
|
|
|
unset($auth['type']); |
82
|
|
|
if ($auth) { |
83
|
|
|
switch ($type) { |
84
|
|
|
default: |
|
|
|
|
85
|
|
|
$authentication = new Authentication\PasswordAuthentication($auth); |
86
|
|
|
break; |
87
|
|
|
} |
88
|
|
|
} else { |
89
|
|
|
$authentication = null; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $authentication; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.