1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver\Entity; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Utils\TranslatorInterface; |
6
|
|
|
|
7
|
|
|
use function trim; |
8
|
|
|
use function array_keys; |
9
|
|
|
use function array_merge; |
10
|
|
|
use function array_key_exists; |
11
|
|
|
use function explode; |
12
|
|
|
|
13
|
|
|
class ConfigEntity |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $jush = ''; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $version = '4.8.1-dev'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
public $drivers = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
public $types = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
public $features = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $structuredTypes = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
public $unsigned = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public $operators = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
public $functions = []; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
public $grouping = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
public $editFunctions = []; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
public $options; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* From bootstrap.inc.php |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
public $onActions = 'RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT'; ///< @var string used in foreignKeys() |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
*/ |
84
|
|
|
public $numberRegex = '((?<!o)int(?!er)|numeric|real|float|double|decimal|money)'; // not point, not interval |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* From index.php |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
public $inout = 'IN|OUT|INOUT'; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* From index.php |
94
|
|
|
* @var string |
95
|
|
|
*/ |
96
|
|
|
public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* The current database name |
100
|
|
|
* |
101
|
|
|
* @var string |
102
|
|
|
*/ |
103
|
|
|
public $database = ''; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* The current schema name |
107
|
|
|
* |
108
|
|
|
* @var string |
109
|
|
|
*/ |
110
|
|
|
public $schema = ''; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var TranslatorInterface |
114
|
|
|
*/ |
115
|
|
|
public $trans; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The constructor |
119
|
|
|
* |
120
|
|
|
* @param TranslatorInterface $trans |
121
|
|
|
* @param array $options |
122
|
|
|
*/ |
123
|
|
|
public function __construct(TranslatorInterface $trans, array $options) |
124
|
|
|
{ |
125
|
|
|
$this->trans = $trans; |
126
|
|
|
$this->options = $options; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Set the supported types |
131
|
|
|
* |
132
|
|
|
* @param array $types |
133
|
|
|
* |
134
|
|
|
* @return void |
135
|
|
|
*/ |
136
|
|
|
public function setTypes(array $types) |
137
|
|
|
{ |
138
|
|
|
foreach ($types as $group => $_types) { |
139
|
|
|
$this->structuredTypes[$this->trans->lang($group)] = array_keys($_types); |
140
|
|
|
$this->types = array_merge($this->types, $_types); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get the driver options |
146
|
|
|
* |
147
|
|
|
* @param string $name The option name |
148
|
|
|
* @param mixed $default |
149
|
|
|
* |
150
|
|
|
* @return mixed |
151
|
|
|
*/ |
152
|
|
|
public function options(string $name = '', $default = '') |
153
|
|
|
{ |
154
|
|
|
if (!($name = trim($name))) { |
155
|
|
|
return $this->options; |
156
|
|
|
} |
157
|
|
|
if (array_key_exists($name, $this->options)) { |
158
|
|
|
return $this->options[$name]; |
159
|
|
|
} |
160
|
|
|
if ($name === 'server') { |
161
|
|
|
$server = $this->options['host'] ?? ''; |
162
|
|
|
$port = $this->options['port'] ?? ''; // Optional |
163
|
|
|
// Append the port to the host if it is defined. |
164
|
|
|
if (($port)) { |
165
|
|
|
$server .= ":$port"; |
166
|
|
|
} |
167
|
|
|
return $server; |
168
|
|
|
} |
169
|
|
|
// if ($name === 'ssl') { |
170
|
|
|
// return false; // No SSL options yet |
171
|
|
|
// } |
172
|
|
|
// Option not found |
173
|
|
|
return $default; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return array |
178
|
|
|
*/ |
179
|
|
|
public function onActions() |
180
|
|
|
{ |
181
|
|
|
return explode('|', $this->onActions); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|