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 +242 -54 2.3.19 → 2.1.11 View file →
@@ -1,167 +1,355 @@
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 - public function dbDelta(string $queries = '', bool $execute = true): array
81 + /**
82 + * @see dbDelta()
83 + *
84 + * @param string $queries
85 + * @param bool $execute
86 + *
87 + * @return array
88 + */
89 + public function dbDelta($queries = '', $execute = true)
39 90 {
40 91 return $this->wordpress->dbDelta($queries, $execute);
41 92 }
42 93
43 - public function getPrefix(): string
94 + /**
95 + * @see \wpdb::$prefix
96 + *
97 + * @return string
98 + */
99 + public function getPrefix()
44 100 {
45 101 return $this->wpDatabase->prefix;
46 102 }
47 103
48 - public function getLastInsertId(): int|string
104 + /**
105 + * Returns the last insert id.
106 + *
107 + * @return int
108 + */
109 + public function getLastInsertId()
49 110 {
50 111 return $this->wpDatabase->insert_id;
51 112 }
52 113
53 - public function getCurrentBlogId(): int|string
114 + /**
115 + * Returns the current blog id.
116 + *
117 + * @return int
118 + */
119 + public function getCurrentBlogId()
54 120 {
55 121 return $this->wpDatabase->blogid;
56 122 }
57 123
58 - public function getBlogsTable(): string
124 + /**
125 + * Returns the blogs table name.
126 + *
127 + * @return string
128 + */
129 + public function getBlogsTable()
59 130 {
60 131 return $this->wpDatabase->blogs;
61 132 }
62 133
63 - public function getPostsTable(): string
134 + /**
135 + * Returns the posts table name.
136 + *
137 + * @return string
138 + */
139 + public function getPostsTable()
64 140 {
65 141 return $this->wpDatabase->posts;
66 142 }
67 143
68 - public function getTermRelationshipsTable(): string
144 + /**
145 + * Returns the term_relationships table name.
146 + *
147 + * @return string
148 + */
149 + public function getTermRelationshipsTable()
69 150 {
70 151 return $this->wpDatabase->term_relationships;
71 152 }
72 153
73 - public function getTermTaxonomyTable(): string
154 + /**
155 + * Returns the term_taxonomy table name.
156 + *
157 + * @return string
158 + */
159 + public function getTermTaxonomyTable()
74 160 {
75 161 return $this->wpDatabase->term_taxonomy;
76 162 }
77 163
78 - public function getUsersTable(): string
164 + /**
165 + * Returns the users table name.
166 + *
167 + * @return string
168 + */
169 + public function getUsersTable()
79 170 {
80 171 return $this->wpDatabase->users;
81 172 }
82 173
83 - public function getCapabilitiesTable(): string
174 + /**
175 + * Returns the capabilities table name.
176 + *
177 + * @return string
178 + */
179 + public function getCapabilitiesTable()
84 180 {
85 - return $this->wpDatabase->prefix . 'capabilities';
181 + return $this->wpDatabase->prefix.'capabilities';
86 182 }
87 183
88 - public function getColumn(?string $query = null, int $column = 0): array
184 + /**
185 + * @see \wpdb::get_col()
186 + *
187 + * @param string $query
188 + * @param int $column
189 + *
190 + * @return array
191 + */
192 + public function getColumn($query = null, $column = 0)
89 193 {
90 194 return $this->wpDatabase->get_col($query, $column);
91 195 }
92 196
93 - public function getRow(?string $query = null, string $output = OBJECT, int $row = 0): object|array|null
197 + /**
198 + * @see \wpdb::get_row()
199 + *
200 + * @param string $query
201 + * @param string $output
202 + * @param int $row
203 + *
204 + * @return array|null|object
205 + */
206 + public function getRow($query = null, $output = OBJECT, $row = 0)
94 207 {
95 208 return $this->wpDatabase->get_row($query, $output, $row);
96 209 }
97 210
98 - public function getVariable(?string $query = null, int $column = 0, int $row = 0): int|string|null
211 + /**
212 + * @see \wpdb::get_var()
213 + *
214 + * @param null|string $query
215 + * @param int $column
216 + * @param int $row
217 + *
218 + * @return null|string
219 + */
220 + public function getVariable($query = null, $column = 0, $row = 0)
99 221 {
100 222 return $this->wpDatabase->get_var($query, $column, $row);
101 223 }
102 224
103 - public function getBlogPrefix(int|string|null $blogId = null): string
225 + /**
226 + * @see \wpdb::get_blog_prefix()
227 + *
228 + * @param int $blogId
229 + *
230 + * @return string
231 + */
232 + public function getBlogPrefix($blogId = null)
104 233 {
105 234 return $this->wpDatabase->get_blog_prefix($blogId);
106 235 }
107 236
108 - public function prepare(string $query, mixed $arguments): string
237 + /**
238 + * @see \wpdb::prepare()
239 + *
240 + * @param string $query
241 + * @param mixed $arguments
242 + *
243 + * @return string
244 + */
245 + public function prepare($query, $arguments)
109 246 {
110 247 return $this->wpDatabase->prepare($query, $arguments);
111 248 }
112 249
113 - public function query(string $query): bool|int
250 + /**
251 + * @see \wpdb::query()
252 + *
253 + * @param string $query
254 + *
255 + * @return false|int
256 + */
257 + public function query($query)
114 258 {
115 259 return $this->wpDatabase->query($query);
116 260 }
117 261
118 - public function getResults(?string $query = null, string $output = OBJECT): object|array|null
262 + /**
263 + * @see \wpdb::get_results()
264 + *
265 + * @param string $query
266 + * @param string $output
267 + *
268 + * @return array|null|object
269 + */
270 + public function getResults($query = null, $output = OBJECT)
119 271 {
120 272 return $this->wpDatabase->get_results($query, $output);
121 273 }
122 274
123 - public function insert(string $table, array $data, array|string|null $format = null): bool|int
275 + /**
276 + * @see \wpdb::insert()
277 + *
278 + * @param string $table
279 + * @param array $data
280 + * @param array|string $format
281 + *
282 + * @return false|int
283 + */
284 + public function insert($table, array $data, $format = null)
124 285 {
125 286 return $this->wpDatabase->insert($table, $data, $format);
126 287 }
127 288
128 - public function update(
129 - string $table,
130 - array $data,
131 - array $where,
132 - array|string|null $format = null,
133 - array|string|null $whereFormat = null
134 - ): bool|int {
289 + /**
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
299 + */
300 + public function update($table, array $data, array $where, $format = null, $whereFormat = null)
301 + {
135 302 return $this->wpDatabase->update($table, $data, $where, $format, $whereFormat);
136 303 }
137 304
138 - public function replace(string $table, array $data, array|string|null $format = null): bool|int
305 + /**
306 + * @see \wpdb::insert()
307 + *
308 + * @param string $table
309 + * @param array $data
310 + * @param array|string $format
311 + *
312 + * @return false|int
313 + */
314 + public function replace($table, array $data, $format = null)
139 315 {
140 316 return $this->wpDatabase->replace($table, $data, $format);
141 317 }
142 318
143 - public function delete(string $table, array $where, array|string|null $whereFormat = null): bool|int
319 + /**
320 + * @see \wpdb::delete()
321 + *
322 + * @param string $table
323 + * @param array $where
324 + * @param array|string $whereFormat
325 + *
326 + * @return false|int
327 + */
328 + public function delete($table, array $where, $whereFormat = null)
144 329 {
145 330 return $this->wpDatabase->delete($table, $where, $whereFormat);
146 331 }
147 332
148 - public function getCharset(): string
333 + /**
334 + * Returns the database charset.
335 + *
336 + * @return string
337 + */
338 + public function getCharset()
149 339 {
150 - $mySqlVersion = (string) $this->getVariable('SELECT VERSION() as mysql_version');
340 + $charsetCollate = '';
151 341
152 - if (version_compare($mySqlVersion, '4.1.0', '<')) {
153 - return '';
154 - }
342 + $mySlqVersion = $this->getVariable('SELECT VERSION() as mysql_version');
155 343
156 - $charsetCollate = '';
344 + if (version_compare($mySlqVersion, '4.1.0', '>=')) {
345 + if (!empty($this->wpDatabase->charset)) {
346 + $charsetCollate = "DEFAULT CHARACTER SET {$this->wpDatabase->charset}";
347 + }
157 348
158 - if (!empty($this->wpDatabase->charset)) {
159 - $charsetCollate = "DEFAULT CHARACTER SET {$this->wpDatabase->charset}";
160 - }
161 -
162 - if (!empty($this->wpDatabase->collate)) {
163 - $charsetCollate .= " COLLATE {$this->wpDatabase->collate}";
349 + if (!empty($this->wpDatabase->collate)) {
350 + $charsetCollate .= " COLLATE {$this->wpDatabase->collate}";
351 + }
164 352 }
165 353
166 354 return $charsetCollate;
167 355 }