1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Del\Common\Config;
|
4
|
|
|
|
5
|
|
|
use Barnacle\RegistrationInterface;
|
6
|
|
|
use Barnacle\Container;
|
7
|
|
|
|
8
|
|
|
class DbCredentials implements RegistrationInterface
|
9
|
|
|
{
|
10
|
|
|
/** @var array */
|
11
|
|
|
private $credentials = [
|
12
|
|
|
'driver' => 'pdo_mysql',
|
13
|
|
|
'host' => '127.0.0.1',
|
14
|
|
|
'dbname' => '',
|
15
|
|
|
'user' => '',
|
16
|
|
|
'password' => '',
|
17
|
|
|
];
|
18
|
|
|
|
19
|
11 |
|
public function __construct(array $array = [])
|
20
|
|
|
{
|
21
|
11 |
|
$this->credentials = array_merge($this->credentials, $array);
|
22
|
11 |
|
}
|
23
|
|
|
|
24
|
|
|
/**
|
25
|
|
|
* @return string
|
26
|
|
|
*/
|
27
|
1 |
|
public function getPassword(): string
|
28
|
|
|
{
|
29
|
1 |
|
return $this->credentials['password'];
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
/**
|
33
|
|
|
* @param string $password
|
34
|
|
|
*/
|
35
|
11 |
|
public function setPassword(string $password)
|
36
|
|
|
{
|
37
|
11 |
|
$this->credentials['password'] = $password;
|
38
|
11 |
|
}
|
39
|
|
|
|
40
|
|
|
/**
|
41
|
|
|
* @return string
|
42
|
|
|
*/
|
43
|
1 |
|
public function getUser(): string
|
44
|
|
|
{
|
45
|
1 |
|
return $this->credentials['user'];
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* @param string $user
|
50
|
|
|
* @return DbCredentials
|
51
|
|
|
*/
|
52
|
12 |
|
public function setUser(string $user)
|
53
|
|
|
{
|
54
|
12 |
|
$this->credentials['user'] = $user;
|
55
|
12 |
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* @return string
|
59
|
|
|
*/
|
60
|
1 |
|
public function getDatabase(): string
|
61
|
|
|
{
|
62
|
1 |
|
return $this->credentials['dbname'];
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* @param string $database
|
67
|
|
|
*/
|
68
|
11 |
|
public function setDatabase(string $database)
|
69
|
|
|
{
|
70
|
11 |
|
$this->credentials['dbname'] = $database;
|
71
|
11 |
|
}
|
72
|
|
|
|
73
|
|
|
/**
|
74
|
|
|
* @return string
|
75
|
|
|
*/
|
76
|
1 |
|
public function getHost(): string
|
77
|
|
|
{
|
78
|
1 |
|
return $this->credentials['host'];
|
79
|
|
|
}
|
80
|
|
|
|
81
|
|
|
/**
|
82
|
|
|
* @param string $database
|
|
|
|
|
83
|
|
|
*/
|
84
|
10 |
|
public function setHost(string $host)
|
85
|
|
|
{
|
86
|
10 |
|
$this->credentials['host'] = $host;
|
87
|
10 |
|
}
|
88
|
|
|
|
89
|
|
|
/**
|
90
|
|
|
* @return string
|
91
|
|
|
*/
|
92
|
1 |
|
public function getDriver(): string
|
93
|
|
|
{
|
94
|
1 |
|
return $this->credentials['driver'];
|
95
|
|
|
}
|
96
|
|
|
|
97
|
|
|
/**
|
98
|
|
|
* @param string $driver
|
99
|
|
|
*/
|
100
|
11 |
|
public function setDriver(string $driver)
|
101
|
|
|
{
|
102
|
11 |
|
$this->credentials['driver'] = $driver;
|
103
|
11 |
|
}
|
104
|
|
|
|
105
|
|
|
/**
|
106
|
|
|
* @return array
|
107
|
|
|
*/
|
108
|
9 |
|
public function toArray(): array
|
109
|
|
|
{
|
110
|
9 |
|
return $this->credentials;
|
111
|
|
|
}
|
112
|
|
|
|
113
|
|
|
/**
|
114
|
|
|
* @param Container $c
|
115
|
|
|
* @return Container
|
116
|
|
|
*/
|
117
|
1 |
|
public function addToContainer(Container $c): Container
|
118
|
|
|
{
|
119
|
1 |
|
$c['db.credentials'] = $this->toArray();
|
120
|
1 |
|
return $c;
|
121
|
|
|
}
|
122
|
|
|
|
123
|
|
|
/**
|
124
|
|
|
* @return string
|
125
|
|
|
*/
|
126
|
1 |
|
public function getEntityPath(): string
|
127
|
|
|
{
|
128
|
1 |
|
return '';
|
129
|
|
|
}
|
130
|
|
|
|
131
|
|
|
/**
|
132
|
|
|
* @return bool
|
133
|
|
|
*/
|
134
|
1 |
|
public function hasEntityPath(): bool
|
135
|
|
|
{
|
136
|
1 |
|
return false;
|
137
|
|
|
}
|
138
|
|
|
}
|
139
|
|
|
|
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.