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
|
|
|
public function __construct(array $array = null) |
15
|
|
|
{ |
16
|
|
|
$this->credentials = []; |
17
|
|
|
$this->credentials['driver'] = $array['driver'] ?: 'pdo_mysql'; |
18
|
|
|
$this->credentials['dbname'] = $array['dbname'] ?: 'delboy1978uk'; |
19
|
|
|
$this->credentials['user'] = $array['user'] ?: 'dbuser'; |
20
|
|
|
$this->credentials['password'] = $array['password'] ?: '[123456]'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function getPassword() |
27
|
|
|
{ |
28
|
|
|
return $this->credentials['password']; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $password |
33
|
|
|
* @return DbCredentials |
34
|
|
|
*/ |
35
|
|
|
public function setPassword($password) |
36
|
|
|
{ |
37
|
|
|
$this->credentials['password'] = $password; |
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getUser() |
45
|
|
|
{ |
46
|
|
|
return $this->credentials['user']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $user |
51
|
|
|
* @return DbCredentials |
52
|
|
|
*/ |
53
|
|
|
public function setUser($user) |
54
|
|
|
{ |
55
|
|
|
$this->credentials['user'] = $user; |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getDatabase() |
63
|
|
|
{ |
64
|
|
|
return $this->credentials['database']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $database |
69
|
|
|
* @return DbCredentials |
70
|
|
|
*/ |
71
|
|
|
public function setDatabase($database) |
72
|
|
|
{ |
73
|
|
|
$this->credentials['database'] = $database; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getDriver() |
81
|
|
|
{ |
82
|
|
|
return $this->credentials['driver']; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $driver |
87
|
|
|
* @return DbCredentials |
88
|
|
|
*/ |
89
|
|
|
public function setDriver($driver) |
90
|
|
|
{ |
91
|
|
|
$this->credentials['driver'] = $driver; |
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function toArray() |
99
|
|
|
{ |
100
|
|
|
return $this->credentials; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param Container $c |
105
|
|
|
* @return Container |
106
|
|
|
*/ |
107
|
|
|
public function addToContainer(Container $c) |
108
|
|
|
{ |
109
|
|
|
$c['db.credentials'] = $this->toArray(); |
110
|
|
|
return $c; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
} |