1 | <?php |
||
14 | class Database { |
||
15 | |||
16 | /** |
||
17 | * The global wpdb object. |
||
18 | * |
||
19 | * @var \wpdb |
||
20 | */ |
||
21 | protected $wpdb; |
||
22 | |||
23 | /** |
||
24 | * A list of all table names. |
||
25 | * |
||
26 | * @var string[] |
||
27 | */ |
||
28 | protected $table_names; |
||
29 | |||
30 | /** |
||
31 | * The filesystem. |
||
32 | * |
||
33 | * @var \WP_Filesystem_Base |
||
34 | */ |
||
35 | protected $filesystem; |
||
36 | |||
37 | /** |
||
38 | * The list of all tables that the user can read. |
||
39 | * |
||
40 | * @var Table[] |
||
41 | */ |
||
42 | protected $tables; |
||
43 | |||
44 | /** |
||
45 | * Create a new Database object based on the given wpdb object. |
||
46 | * |
||
47 | * @param \wpdb $wpdb The global wpdb object. |
||
48 | */ |
||
49 | public function __construct( $wpdb ) { |
||
52 | |||
53 | /** |
||
54 | * Set the filesystem. |
||
55 | * |
||
56 | * @param \WP_Filesystem_Base $filesystem The filesystem object. |
||
57 | */ |
||
58 | public function set_filesystem( \WP_Filesystem_Base $filesystem ) { |
||
61 | |||
62 | /** |
||
63 | * Get the filesystem. |
||
64 | * |
||
65 | * @return \WP_Filesystem_Base |
||
66 | */ |
||
67 | public function get_filesystem() { |
||
70 | |||
71 | /** |
||
72 | * Get the global wpdb object. |
||
73 | * |
||
74 | * @return \wpdb |
||
75 | */ |
||
76 | public function get_wpdb() { |
||
79 | |||
80 | /** |
||
81 | * Get a list of tables and views that the current user can read. |
||
82 | * |
||
83 | * @return string[] The table names. |
||
84 | */ |
||
85 | public function get_table_names() { |
||
96 | |||
97 | /** |
||
98 | * Get a table from the database. |
||
99 | * |
||
100 | * @param string $name The name of the desired table. |
||
101 | * @return \WordPress\Tabulate\DB\Table|false The table, or false if it's not available. |
||
102 | */ |
||
103 | public function get_table( $name ) { |
||
112 | |||
113 | /** |
||
114 | * Forget all table information, forcing it to be re-read from the database |
||
115 | * when next required. Used after schema changes. |
||
116 | */ |
||
117 | public function reset() { |
||
121 | |||
122 | /** |
||
123 | * Get all tables in this database. |
||
124 | * |
||
125 | * @param boolean $exclude_views Whether to exclude database views from the returned list. |
||
126 | * @return Table[] An array of all Tables. |
||
127 | */ |
||
128 | public function get_tables( $exclude_views = true ) { |
||
143 | |||
144 | /** |
||
145 | * Get all views in this database. |
||
146 | * |
||
147 | * @return Table|array An array of all Tables that are views. |
||
148 | */ |
||
149 | public function get_views() { |
||
158 | |||
159 | /** |
||
160 | * Create a new table. |
||
161 | * |
||
162 | * @param string $name The name of the new table. |
||
163 | * @param string $comment The table comment. |
||
164 | * @throws Exception If the current user cannot 'promote_users'. |
||
165 | */ |
||
166 | public function create_table( $name, $comment = '' ) { |
||
177 | |||
178 | /** |
||
179 | * A wrapper around wpdb::prepare() and wpdb::query() |
||
180 | * that also checks wpdb::$last_error and throws up on occasion of badness. |
||
181 | * |
||
182 | * @param string $sql The SQL statement to execute. |
||
183 | * @param string[] $params Parameters to pass to wpdb::prepare(). |
||
184 | * @param string $error_message What to tell the user if this query fails. |
||
185 | * @throws Exception The exception message is taken from wpdb::$last_error and if WP_DEBUG is set will also include the erroneous SQL. |
||
186 | */ |
||
187 | public function query( $sql, $params = null, $error_message = null ) { |
||
200 | |||
201 | /** |
||
202 | * Get the name of the directory to which MySQL will write temporary export files. |
||
203 | * This is either the value of the 'secure_file_priv' server variable, |
||
204 | * or WordPress's normal temporary directory as returned by get_temp_dir(). |
||
205 | * Always has a trailing slash. |
||
206 | * |
||
207 | * @return string Full path of the directory. |
||
208 | * @throws Exception If the directory is not writable. |
||
209 | */ |
||
210 | public function get_tmp_dir() { |
||
220 | } |
||
221 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.