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