PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Database / ExternalDatabaseConfiguration.php
wp-staging / Framework / Database Last commit date
Exporter 2 weeks ago QueryBuilder 2 weeks ago CustomTable.php 2 weeks ago DbInfo.php 2 weeks ago ExcludedTables.php 2 weeks ago ExternalDatabaseConfiguration.php 2 weeks ago OptionPreservationHandler.php 2 weeks ago SearchReplace.php 3 days ago SelectedTables.php 2 weeks ago TableDto.php 2 weeks ago TableService.php 1 week ago TablesRenamer.php 1 week ago WpDbInfo.php 2 weeks ago WpOptionsInfo.php 2 weeks ago iDbInfo.php 3 years ago
ExternalDatabaseConfiguration.php
85 lines
1 <?php
2
3 namespace WPStaging\Framework\Database;
4
5 use WPStaging\Framework\Adapter\Database\DatabaseException;
6
7
8
9
10 final class ExternalDatabaseConfiguration
11 {
12
13
14
15
16 public function isEnabled($options): bool
17 {
18 $options = $this->normalizeOptions($options);
19
20 if (array_key_exists('useCustomDatabase', $options)) {
21 return filter_var($options['useCustomDatabase'], FILTER_VALIDATE_BOOLEAN);
22 }
23
24 return $this->hasConnectionTarget($options);
25 }
26
27
28
29
30
31 public function hasConnectionTarget($options): bool
32 {
33 $options = $this->normalizeOptions($options);
34
35 return $this->getValue($options, 'databaseServer') !== ''
36 && $this->getValue($options, 'databaseUser') !== ''
37 && $this->getValue($options, 'databaseDatabase') !== '';
38 }
39
40
41
42
43
44
45 public function validateConnectionTarget($options)
46 {
47 $options = $this->normalizeOptions($options);
48
49 if (!$this->hasConnectionTarget($options)) {
50 throw new DatabaseException(__('External database credentials are incomplete. Enter the database host, database name, and database user.', 'wp-staging'));
51 }
52
53 if (strpos($this->getValue($options, 'databaseServer'), '://') !== false) {
54 throw new DatabaseException(__('The external database server must be a hostname, IP address, socket, or host:port value without a URL scheme such as http:// or https://.', 'wp-staging'));
55 }
56 }
57
58
59
60
61
62 private function normalizeOptions($options): array
63 {
64 if (is_array($options)) {
65 return $options;
66 }
67
68 if (is_object($options)) {
69 return get_object_vars($options);
70 }
71
72 return [];
73 }
74
75
76
77
78
79
80 private function getValue(array $options, string $key): string
81 {
82 return isset($options[$key]) ? trim((string)$options[$key]) : '';
83 }
84 }
85