|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Spiral Framework. |
|
4
|
|
|
* |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* @author Anton Titov (Wolfy-J) |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Spiral\Database\Configs; |
|
9
|
|
|
|
|
10
|
|
|
use Spiral\Core\InjectableConfig; |
|
11
|
|
|
use Spiral\Core\Traits\Config\AliasTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Databases config. |
|
15
|
|
|
*/ |
|
16
|
|
|
class DatabasesConfig extends InjectableConfig |
|
17
|
|
|
{ |
|
18
|
|
|
use AliasTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Configuration section. |
|
22
|
|
|
*/ |
|
23
|
|
|
const CONFIG = 'databases'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $config = [ |
|
29
|
|
|
'default' => 'default', |
|
30
|
|
|
'aliases' => [], |
|
31
|
|
|
'databases' => [], |
|
32
|
|
|
'connections' => [] |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function defaultDatabase() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->config['default']; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $database |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function hasDatabase($database) |
|
48
|
|
|
{ |
|
49
|
|
|
return isset($this->config['databases'][$database]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $connection |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function hasConnection($connection) |
|
57
|
|
|
{ |
|
58
|
|
|
return isset($this->config['connections'][$connection]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function databaseNames() |
|
65
|
|
|
{ |
|
66
|
|
|
return array_keys($this->config['databases']); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
public function connectionNames() |
|
73
|
|
|
{ |
|
74
|
|
|
return array_keys($this->config['connections']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $database |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function databaseConnection($database) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->config['databases'][$database]['connection']; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $database |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function databasePrefix($database) |
|
91
|
|
|
{ |
|
92
|
|
|
if (isset($this->config['databases'][$database]['tablePrefix'])) { |
|
93
|
|
|
return $this->config['databases'][$database]['tablePrefix']; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return ''; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $connection |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
|
|
public function connectionDriver($connection) |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->config['connections'][$connection]['driver']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $connection |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
public function connectionConfig($connection) |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->config['connections'][$connection]; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |