|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 12.06.2017 15:29 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace DBAL; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class Schema { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var \db_mysql $db |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $db; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* List of all table names |
|
18
|
|
|
* |
|
19
|
|
|
* @var string[] $tablesAll |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $tablesAll = null; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string[] $tablesSn |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $tablesSn = null; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
public function __construct(\db_mysql $db) { |
|
29
|
|
|
$this->db = $db; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function clear() { |
|
33
|
|
|
$this->tablesAll = null; |
|
|
|
|
|
|
34
|
|
|
$this->tablesSn = null; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function loadTableNamesFromDb() { |
|
38
|
|
|
$this->clear(); |
|
39
|
|
|
$this->tablesAll = array(); |
|
40
|
|
|
$this->tablesSn = array(); |
|
41
|
|
|
|
|
42
|
|
|
$query = $this->db->mysql_get_table_list(); |
|
43
|
|
|
|
|
44
|
|
|
$prefix_length = strlen($this->db->db_prefix); |
|
45
|
|
|
|
|
46
|
|
|
while($row = $this->db->db_fetch($query)) { |
|
47
|
|
|
foreach($row as $table_name) { |
|
48
|
|
|
$this->tablesAll[$table_name] = $table_name; |
|
49
|
|
|
|
|
50
|
|
|
if(strpos($table_name, $this->db->db_prefix) === 0) { |
|
51
|
|
|
$table_name_sn = substr($table_name, $prefix_length); |
|
52
|
|
|
$this->tablesSn[$table_name_sn] = $table_name_sn; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get names of all tables in this DB |
|
60
|
|
|
* |
|
61
|
|
|
* @return \string[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getAllTables() { |
|
64
|
|
|
if(!isset($this->tablesAll)) { |
|
65
|
|
|
$this->loadTableNamesFromDb(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->tablesAll; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get un-prefixed table names potentially used by game |
|
73
|
|
|
* |
|
74
|
|
|
* @return string[] |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getSnTables() { |
|
77
|
|
|
if(!isset($this->tablesSn)) { |
|
78
|
|
|
$this->loadTableNamesFromDb(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->tablesSn; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Checks if SN table exists |
|
86
|
|
|
* |
|
87
|
|
|
* @param $tableName |
|
88
|
|
|
* |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
|
|
public function isSnTableExists($tableName) { |
|
92
|
|
|
return isset($this->getSnTables()[$tableName]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..