1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Del\Common\Config; |
5
|
|
|
|
6
|
|
|
use Del\Common\Container\RegistrationInterface; |
7
|
|
|
use Pimple\Container; |
8
|
|
|
|
9
|
|
|
class DbCredentials implements RegistrationInterface |
10
|
|
|
{ |
11
|
|
|
/** @var array */ |
12
|
|
|
private $credentials; |
13
|
|
|
|
14
|
10 |
|
public function __construct(array $array = null) |
15
|
|
|
{ |
16
|
10 |
|
$this->credentials = []; |
17
|
10 |
|
$this->credentials['driver'] = $array['driver'] ?: 'pdo_mysql'; |
18
|
10 |
|
$this->credentials['dbname'] = $array['dbname'] ?: 'delboy1978uk'; |
19
|
10 |
|
$this->credentials['user'] = $array['user'] ?: 'dbuser'; |
20
|
10 |
|
$this->credentials['password'] = $array['password'] ?: '[123456]'; |
21
|
10 |
|
$this->credentials['host'] = $array['host'] ?: '127.0.0.1'; |
22
|
10 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
1 |
|
public function getPassword() |
28
|
|
|
{ |
29
|
1 |
|
return $this->credentials['password']; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $password |
34
|
|
|
* @return DbCredentials |
35
|
|
|
*/ |
36
|
1 |
|
public function setPassword($password) |
37
|
|
|
{ |
38
|
1 |
|
$this->credentials['password'] = $password; |
39
|
1 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
1 |
|
public function getUser() |
46
|
|
|
{ |
47
|
1 |
|
return $this->credentials['user']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $user |
52
|
|
|
* @return DbCredentials |
53
|
|
|
*/ |
54
|
2 |
|
public function setUser($user) |
55
|
|
|
{ |
56
|
2 |
|
$this->credentials['user'] = $user; |
57
|
2 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
1 |
|
public function getDatabase() |
64
|
|
|
{ |
65
|
1 |
|
return $this->credentials['dbname']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $database |
70
|
|
|
* @return DbCredentials |
71
|
|
|
*/ |
72
|
1 |
|
public function setDatabase($database) |
73
|
|
|
{ |
74
|
1 |
|
$this->credentials['dbname'] = $database; |
75
|
1 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getHost() |
82
|
|
|
{ |
83
|
|
|
return $this->credentials['host']; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $database |
|
|
|
|
88
|
|
|
* @return DbCredentials |
89
|
|
|
*/ |
90
|
|
|
public function setHost($host) |
91
|
|
|
{ |
92
|
|
|
$this->credentials['host'] = $host; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
1 |
|
public function getDriver() |
100
|
|
|
{ |
101
|
1 |
|
return $this->credentials['driver']; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $driver |
106
|
|
|
* @return DbCredentials |
107
|
|
|
*/ |
108
|
1 |
|
public function setDriver($driver) |
109
|
|
|
{ |
110
|
1 |
|
$this->credentials['driver'] = $driver; |
111
|
1 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
9 |
|
public function toArray() |
118
|
|
|
{ |
119
|
9 |
|
return $this->credentials; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param Container $c |
124
|
|
|
* @return Container |
125
|
|
|
*/ |
126
|
1 |
|
public function addToContainer(Container $c) |
127
|
|
|
{ |
128
|
1 |
|
$c['db.credentials'] = $this->toArray(); |
129
|
1 |
|
return $c; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return null |
134
|
|
|
*/ |
135
|
1 |
|
public function getEntityPath() |
136
|
|
|
{ |
137
|
1 |
|
return null; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
2 |
|
public function hasEntityPath() |
144
|
|
|
{ |
145
|
2 |
|
return false; |
146
|
|
|
} |
147
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.