PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Database/Database.php +206 -50 2.3.17 → 2.1.11 View file →
@@ -1,190 +1,346 @@
1 1 <?php
2 +/**
3 + * Database.php
4 + *
5 + * The Database class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 -declare(strict_types=1);
4 -
5 16 namespace UserAccessManager\Database;
6 17
7 18 use UserAccessManager\Wrapper\Wordpress;
8 -use wpdb;
9 19
20 +/**
21 + * Class Database
22 + *
23 + * @package UserAccessManager\Database
24 + */
10 25 class Database
11 26 {
12 - public const USER_GROUP_TABLE_NAME = 'uam_accessgroups';
13 - public const USER_GROUP_TO_OBJECT_TABLE_NAME = 'uam_accessgroup_to_object';
27 + const USER_GROUP_TABLE_NAME = 'uam_accessgroups';
28 + const USER_GROUP_TO_OBJECT_TABLE_NAME = 'uam_accessgroup_to_object';
14 29
15 - private wpdb $wpDatabase;
30 + /**
31 + * @var Wordpress
32 + */
33 + private $wordpress;
16 34
17 - public function __construct(
18 - private Wordpress $wordpress
19 - ) {
35 + /**
36 + * @var \wpdb
37 + */
38 + private $wpDatabase;
39 +
40 + /**
41 + * Database constructor.
42 + *
43 + * @param Wordpress $wordpress
44 + */
45 + public function __construct(Wordpress $wordpress)
46 + {
47 + $this->wordpress = $wordpress;
20 48 $this->wpDatabase = $wordpress->getDatabase();
21 49 }
22 50
23 - public function getWordpressDatabase(): wpdb
51 + /**
52 + * Returns the wordpress database.
53 + *
54 + * @return \wpdb
55 + */
56 + public function getWordpressDatabase()
24 57 {
25 58 return $this->wpDatabase;
26 59 }
27 60
28 - public function getUserGroupTable(): string
61 + /**
62 + * Returns the user group table name.
63 + *
64 + * @return string
65 + */
66 + public function getUserGroupTable()
29 67 {
30 - return $this->wpDatabase->prefix . self::USER_GROUP_TABLE_NAME;
68 + return $this->wpDatabase->prefix.self::USER_GROUP_TABLE_NAME;
31 69 }
32 70
33 - public function getUserGroupToObjectTable(): string
71 + /**
72 + * Returns the user group table name.
73 + *
74 + * @return string
75 + */
76 + public function getUserGroupToObjectTable()
34 77 {
35 - return $this->wpDatabase->prefix . self::USER_GROUP_TO_OBJECT_TABLE_NAME;
78 + return $this->wpDatabase->prefix.self::USER_GROUP_TO_OBJECT_TABLE_NAME;
36 79 }
37 80
38 81 /**
39 82 * @see dbDelta()
83 + *
84 + * @param string $queries
85 + * @param bool $execute
86 + *
87 + * @return array
40 88 */
41 - public function dbDelta(string $queries = '', bool $execute = true): array
89 + public function dbDelta($queries = '', $execute = true)
42 90 {
43 91 return $this->wordpress->dbDelta($queries, $execute);
44 92 }
45 93
46 94 /**
47 - * @see wpdb
95 + * @see \wpdb::$prefix
96 + *
97 + * @return string
48 98 */
49 - public function getPrefix(): string
99 + public function getPrefix()
50 100 {
51 101 return $this->wpDatabase->prefix;
52 102 }
53 103
54 - public function getLastInsertId(): int|string
104 + /**
105 + * Returns the last insert id.
106 + *
107 + * @return int
108 + */
109 + public function getLastInsertId()
55 110 {
56 111 return $this->wpDatabase->insert_id;
57 112 }
58 113
59 - public function getCurrentBlogId(): int|string
114 + /**
115 + * Returns the current blog id.
116 + *
117 + * @return int
118 + */
119 + public function getCurrentBlogId()
60 120 {
61 121 return $this->wpDatabase->blogid;
62 122 }
63 123
64 - public function getBlogsTable(): string
124 + /**
125 + * Returns the blogs table name.
126 + *
127 + * @return string
128 + */
129 + public function getBlogsTable()
65 130 {
66 131 return $this->wpDatabase->blogs;
67 132 }
68 133
69 - public function getPostsTable(): string
134 + /**
135 + * Returns the posts table name.
136 + *
137 + * @return string
138 + */
139 + public function getPostsTable()
70 140 {
71 141 return $this->wpDatabase->posts;
72 142 }
73 143
74 - public function getTermRelationshipsTable(): string
144 + /**
145 + * Returns the term_relationships table name.
146 + *
147 + * @return string
148 + */
149 + public function getTermRelationshipsTable()
75 150 {
76 151 return $this->wpDatabase->term_relationships;
77 152 }
78 153
79 - public function getTermTaxonomyTable(): string
154 + /**
155 + * Returns the term_taxonomy table name.
156 + *
157 + * @return string
158 + */
159 + public function getTermTaxonomyTable()
80 160 {
81 161 return $this->wpDatabase->term_taxonomy;
82 162 }
83 163
84 - public function getUsersTable(): string
164 + /**
165 + * Returns the users table name.
166 + *
167 + * @return string
168 + */
169 + public function getUsersTable()
85 170 {
86 171 return $this->wpDatabase->users;
87 172 }
88 173
89 - public function getCapabilitiesTable(): string
174 + /**
175 + * Returns the capabilities table name.
176 + *
177 + * @return string
178 + */
179 + public function getCapabilitiesTable()
90 180 {
91 - return $this->wpDatabase->prefix . 'capabilities';
181 + return $this->wpDatabase->prefix.'capabilities';
92 182 }
93 183
94 184 /**
95 - * @see wpdb::get_col
185 + * @see \wpdb::get_col()
186 + *
187 + * @param string $query
188 + * @param int $column
189 + *
190 + * @return array
96 191 */
97 - public function getColumn(?string $query = null, int $column = 0): array
192 + public function getColumn($query = null, $column = 0)
98 193 {
99 194 return $this->wpDatabase->get_col($query, $column);
100 195 }
101 196
102 197 /**
103 - * @see wpdb::get_row
198 + * @see \wpdb::get_row()
199 + *
200 + * @param string $query
201 + * @param string $output
202 + * @param int $row
203 + *
204 + * @return array|null|object
104 205 */
105 - public function getRow(?string $query = null, string $output = OBJECT, int $row = 0): object|array|null
206 + public function getRow($query = null, $output = OBJECT, $row = 0)
106 207 {
107 208 return $this->wpDatabase->get_row($query, $output, $row);
108 209 }
109 210
110 211 /**
111 - * @see wpdb::get_var
212 + * @see \wpdb::get_var()
213 + *
214 + * @param null|string $query
215 + * @param int $column
216 + * @param int $row
217 + *
218 + * @return null|string
112 219 */
113 - public function getVariable(?string $query = null, int $column = 0, int $row = 0): int|string|null
220 + public function getVariable($query = null, $column = 0, $row = 0)
114 221 {
115 222 return $this->wpDatabase->get_var($query, $column, $row);
116 223 }
117 224
118 225 /**
119 - * @see wpdb::get_blog_prefix
226 + * @see \wpdb::get_blog_prefix()
227 + *
228 + * @param int $blogId
229 + *
230 + * @return string
120 231 */
121 - public function getBlogPrefix(int|string|null $blogId = null): string
232 + public function getBlogPrefix($blogId = null)
122 233 {
123 234 return $this->wpDatabase->get_blog_prefix($blogId);
124 235 }
125 236
126 237 /**
127 - * @see wpdb::prepare
238 + * @see \wpdb::prepare()
239 + *
240 + * @param string $query
241 + * @param mixed $arguments
242 + *
243 + * @return string
128 244 */
129 - public function prepare(string $query, mixed $arguments): string
245 + public function prepare($query, $arguments)
130 246 {
131 247 return $this->wpDatabase->prepare($query, $arguments);
132 248 }
133 249
134 250 /**
135 - * @see wpdb::query
251 + * @see \wpdb::query()
252 + *
253 + * @param string $query
254 + *
255 + * @return false|int
136 256 */
137 - public function query(string $query): bool|int
257 + public function query($query)
138 258 {
139 259 return $this->wpDatabase->query($query);
140 260 }
141 261
142 262 /**
143 - * @see wpdb::get_results
263 + * @see \wpdb::get_results()
264 + *
265 + * @param string $query
266 + * @param string $output
267 + *
268 + * @return array|null|object
144 269 */
145 - public function getResults(?string $query = null, string $output = OBJECT): object|array|null
270 + public function getResults($query = null, $output = OBJECT)
146 271 {
147 272 return $this->wpDatabase->get_results($query, $output);
148 273 }
149 274
150 275 /**
151 - * @see wpdb::insert
276 + * @see \wpdb::insert()
277 + *
278 + * @param string $table
279 + * @param array $data
280 + * @param array|string $format
281 + *
282 + * @return false|int
152 283 */
153 - public function insert(string $table, array $data, $format = null): bool|int
284 + public function insert($table, array $data, $format = null)
154 285 {
155 286 return $this->wpDatabase->insert($table, $data, $format);
156 287 }
157 288
158 289 /**
159 - * @see wpdb::update
290 + * @see \wpdb::update()
291 + *
292 + * @param string $table
293 + * @param array $data
294 + * @param array $where
295 + * @param array|string $format
296 + * @param array|string $whereFormat
297 + *
298 + * @return false|int
160 299 */
161 - public function update(string $table, array $data, array $where, $format = null, $whereFormat = null): bool|int
300 + public function update($table, array $data, array $where, $format = null, $whereFormat = null)
162 301 {
163 302 return $this->wpDatabase->update($table, $data, $where, $format, $whereFormat);
164 303 }
165 304
166 305 /**
167 - * @see wpdb::insert
306 + * @see \wpdb::insert()
307 + *
308 + * @param string $table
309 + * @param array $data
310 + * @param array|string $format
311 + *
312 + * @return false|int
168 313 */
169 - public function replace(string $table, array $data, $format = null): bool|int
314 + public function replace($table, array $data, $format = null)
170 315 {
171 316 return $this->wpDatabase->replace($table, $data, $format);
172 317 }
173 318
174 319 /**
175 - * @see wpdb::delete
320 + * @see \wpdb::delete()
321 + *
322 + * @param string $table
323 + * @param array $where
324 + * @param array|string $whereFormat
325 + *
326 + * @return false|int
176 327 */
177 - public function delete(string $table, array $where, $whereFormat = null): bool|int
328 + public function delete($table, array $where, $whereFormat = null)
178 329 {
179 330 return $this->wpDatabase->delete($table, $where, $whereFormat);
180 331 }
181 332
182 - public function getCharset(): string
333 + /**
334 + * Returns the database charset.
335 + *
336 + * @return string
337 + */
338 + public function getCharset()
183 339 {
184 340 $charsetCollate = '';
185 341
186 - $mySlqVersion = (string) $this->getVariable('SELECT VERSION() as mysql_version');
342 + $mySlqVersion = $this->getVariable('SELECT VERSION() as mysql_version');
187 343
188 344 if (version_compare($mySlqVersion, '4.1.0', '>=')) {
189 345 if (!empty($this->wpDatabase->charset)) {
190 346 $charsetCollate = "DEFAULT CHARACTER SET {$this->wpDatabase->charset}";