@@ -12,19 +12,19 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @var array |
14 | 14 | */ |
15 | - protected static $snakeCache = []; |
|
15 | + protected static $snakeCache=[]; |
|
16 | 16 | /** |
17 | 17 | * The cache of camel-cased words. |
18 | 18 | * |
19 | 19 | * @var array |
20 | 20 | */ |
21 | - protected static $camelCache = []; |
|
21 | + protected static $camelCache=[]; |
|
22 | 22 | /** |
23 | 23 | * The cache of studly-cased words. |
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected static $studlyCache = []; |
|
27 | + protected static $studlyCache=[]; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * 判断一个字符串是否以给定字符串开始 |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | return static::$camelCache[$value]; |
72 | 72 | } |
73 | 73 | |
74 | - return static::$camelCache[$value] = lcfirst(static::studly($value)); |
|
74 | + return static::$camelCache[$value]=lcfirst(static::studly($value)); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | * @return string |
82 | 82 | */ |
83 | 83 | public static function studly($value) { |
84 | - $key = $value; |
|
84 | + $key=$value; |
|
85 | 85 | |
86 | 86 | if (isset(static::$studlyCache[$key])) { |
87 | 87 | return static::$studlyCache[$key]; |
88 | 88 | } |
89 | 89 | |
90 | - $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
90 | + $value=ucwords(str_replace(['-', '_'], ' ', $value)); |
|
91 | 91 | |
92 | - return static::$studlyCache[$key] = str_replace(' ', '', $value); |
|
92 | + return static::$studlyCache[$key]=str_replace(' ', '', $value); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | */ |
102 | 102 | public static function finish($value, $cap) { |
103 | - $quoted = preg_quote($cap, '/'); |
|
103 | + $quoted=preg_quote($cap, '/'); |
|
104 | 104 | |
105 | - return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; |
|
105 | + return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | return true; |
118 | 118 | } |
119 | 119 | |
120 | - $pattern = preg_quote($pattern, '#'); |
|
120 | + $pattern=preg_quote($pattern, '#'); |
|
121 | 121 | |
122 | 122 | // Asterisks are translated into zero-or-more regular expression wildcards |
123 | 123 | // to make it convenient to check if the strings starts with the given |
124 | 124 | // pattern such as "library/*", making any string check convenient. |
125 | - $pattern = str_replace('\*', '.*', $pattern); |
|
125 | + $pattern=str_replace('\*', '.*', $pattern); |
|
126 | 126 | |
127 | - return (bool)preg_match('#^' . $pattern . '\z#u', $value); |
|
127 | + return (bool) preg_match('#^'.$pattern.'\z#u', $value); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -144,20 +144,20 @@ discard block |
||
144 | 144 | * @param string $delimiter |
145 | 145 | * @return string |
146 | 146 | */ |
147 | - public static function snake($value, $delimiter = '_') { |
|
148 | - $key = $value; |
|
147 | + public static function snake($value, $delimiter='_') { |
|
148 | + $key=$value; |
|
149 | 149 | |
150 | 150 | if (isset(static::$snakeCache[$key][$delimiter])) { |
151 | 151 | return static::$snakeCache[$key][$delimiter]; |
152 | 152 | } |
153 | 153 | |
154 | 154 | if (!ctype_lower($value)) { |
155 | - $value = preg_replace('/\s+/u', '', $value); |
|
155 | + $value=preg_replace('/\s+/u', '', $value); |
|
156 | 156 | |
157 | - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
|
157 | + $value=static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
158 | 158 | } |
159 | 159 | |
160 | - return static::$snakeCache[$key][$delimiter] = $value; |
|
160 | + return static::$snakeCache[$key][$delimiter]=$value; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | * @param string $end |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public static function limit($value, $limit = 100, $end = '...') { |
|
181 | + public static function limit($value, $limit=100, $end='...') { |
|
182 | 182 | if (mb_strwidth($value, 'UTF-8') <= $limit) { |
183 | 183 | return $value; |
184 | 184 | } |
185 | 185 | |
186 | - return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; |
|
186 | + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -194,14 +194,14 @@ discard block |
||
194 | 194 | * @param string $end |
195 | 195 | * @return string |
196 | 196 | */ |
197 | - public static function words($value, $words = 100, $end = '...') { |
|
198 | - preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); |
|
197 | + public static function words($value, $words=100, $end='...') { |
|
198 | + preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
|
199 | 199 | |
200 | 200 | if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
201 | 201 | return $value; |
202 | 202 | } |
203 | 203 | |
204 | - return rtrim($matches[0]) . $end; |
|
204 | + return rtrim($matches[0]).$end; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param string|null $default |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - public static function parseCallback($callback, $default = null) { |
|
224 | + public static function parseCallback($callback, $default=null) { |
|
225 | 225 | return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
226 | 226 | } |
227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @return bool |
234 | 234 | */ |
235 | 235 | public static function contains($haystack, $needles) { |
236 | - foreach ((array)$needles as $needle) { |
|
236 | + foreach ((array) $needles as $needle) { |
|
237 | 237 | if ($needle != '' && mb_strpos($haystack, $needle) !== false) { |
238 | 238 | return true; |
239 | 239 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @param int $count |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public static function plural($value, $count = 2) { |
|
251 | + public static function plural($value, $count=2) { |
|
252 | 252 | return Pluralizer::plural($value, $count); |
253 | 253 | } |
254 | 254 | |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | * @param int $length |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public static function quickRandom($length = 16) { |
|
265 | + public static function quickRandom($length=16) { |
|
266 | 266 | if (PHP_MAJOR_VERSION > 5) { |
267 | 267 | return static::random($length); |
268 | 268 | } |
269 | 269 | |
270 | - $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
270 | + $pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
271 | 271 | |
272 | 272 | return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); |
273 | 273 | } |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | * @param int $length |
279 | 279 | * @return string |
280 | 280 | */ |
281 | - public static function random($length = 16) { |
|
282 | - $string = ''; |
|
281 | + public static function random($length=16) { |
|
282 | + $string=''; |
|
283 | 283 | |
284 | - while (($len = strlen($string)) < $length) { |
|
285 | - $size = $length - $len; |
|
284 | + while (($len=strlen($string)) < $length) { |
|
285 | + $size=$length - $len; |
|
286 | 286 | |
287 | - $bytes = random_bytes($size); |
|
287 | + $bytes=random_bytes($size); |
|
288 | 288 | |
289 | - $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
289 | + $string.=substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | return $string; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public static function replaceArray($search, array $replace, $subject) { |
304 | 304 | foreach ($replace as $value) { |
305 | - $subject = static::replaceFirst($search, $value, $subject); |
|
305 | + $subject=static::replaceFirst($search, $value, $subject); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | return $subject; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @return string |
318 | 318 | */ |
319 | 319 | public static function replaceFirst($search, $replace, $subject) { |
320 | - $position = strpos($subject, $search); |
|
320 | + $position=strpos($subject, $search); |
|
321 | 321 | |
322 | 322 | if ($position !== false) { |
323 | 323 | return substr_replace($subject, $replace, $position, strlen($search)); |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @return string |
336 | 336 | */ |
337 | 337 | public static function replaceLast($search, $replace, $subject) { |
338 | - $position = strrpos($subject, $search); |
|
338 | + $position=strrpos($subject, $search); |
|
339 | 339 | |
340 | 340 | if ($position !== false) { |
341 | 341 | return substr_replace($subject, $replace, $position, strlen($search)); |
@@ -371,19 +371,19 @@ discard block |
||
371 | 371 | * @param string $separator |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - public static function slug($title, $separator = '-') { |
|
375 | - $title = static::ascii($title); |
|
374 | + public static function slug($title, $separator='-') { |
|
375 | + $title=static::ascii($title); |
|
376 | 376 | |
377 | 377 | // Convert all dashes/underscores into separator |
378 | - $flip = $separator == '-' ? '_' : '-'; |
|
378 | + $flip=$separator == '-' ? '_' : '-'; |
|
379 | 379 | |
380 | - $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); |
|
380 | + $title=preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
|
381 | 381 | |
382 | 382 | // Remove all characters that are not the separator, letters, numbers, or whitespace. |
383 | - $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
383 | + $title=preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
384 | 384 | |
385 | 385 | // Replace all separator characters and whitespace by a single separator |
386 | - $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); |
|
386 | + $title=preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); |
|
387 | 387 | |
388 | 388 | return trim($title, $separator); |
389 | 389 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public static function ascii($value) { |
398 | 398 | foreach (static::charsArray() as $key => $val) { |
399 | - $value = str_replace($val, $key, $value); |
|
399 | + $value=str_replace($val, $key, $value); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | return preg_replace('/[^\x20-\x7E]/u', '', $value); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | return $charsArray; |
419 | 419 | } |
420 | 420 | |
421 | - return $charsArray = [ |
|
421 | + return $charsArray=[ |
|
422 | 422 | '0' => ['°', '₀', '۰'], |
423 | 423 | '1' => ['¹', '₁', '۱'], |
424 | 424 | '2' => ['²', '₂', '۲'], |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @return string |
543 | 543 | */ |
544 | 544 | public static function ucfirst($string) { |
545 | - return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); |
|
545 | + return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @param int|null $length |
564 | 564 | * @return string |
565 | 565 | */ |
566 | - public static function substr($string, $start, $length = null) { |
|
566 | + public static function substr($string, $start, $length=null) { |
|
567 | 567 | return mb_substr($string, $start, $length, 'UTF-8'); |
568 | 568 | } |
569 | 569 | } |
570 | 570 | \ No newline at end of file |
@@ -76,7 +76,6 @@ discard block |
||
76 | 76 | private $_with = Array(); |
77 | 77 | |
78 | 78 | /** |
79 | - * @param array $data Data to preload on object creation |
|
80 | 79 | */ |
81 | 80 | public function __construct() { |
82 | 81 | $this->db = app('db')->connect($this->dbConn); |
@@ -207,7 +206,7 @@ discard block |
||
207 | 206 | /** |
208 | 207 | * Save or Update object |
209 | 208 | * |
210 | - * @return mixed insert id or false in case of failure |
|
209 | + * @return boolean insert id or false in case of failure |
|
211 | 210 | */ |
212 | 211 | public function save($data = null) { |
213 | 212 | if ($this->isNew) |
@@ -216,7 +215,7 @@ discard block |
||
216 | 215 | } |
217 | 216 | |
218 | 217 | /** |
219 | - * @return mixed insert id or false in case of failure |
|
218 | + * @return boolean insert id or false in case of failure |
|
220 | 219 | */ |
221 | 220 | public function insert() { |
222 | 221 | if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) |
@@ -362,7 +361,7 @@ discard block |
||
362 | 361 | /** |
363 | 362 | * Delete method. Works only if object primaryKey is defined |
364 | 363 | * |
365 | - * @return boolean Indicates success. 0 or 1. |
|
364 | + * @return null|boolean Indicates success. 0 or 1. |
|
366 | 365 | */ |
367 | 366 | public function delete() { |
368 | 367 | if (empty ($this->data[$this->primaryKey])) |
@@ -522,7 +521,7 @@ discard block |
||
522 | 521 | * @param string $joinType SQL join type: LEFT, RIGHT, INNER, OUTER |
523 | 522 | * @param string $primaryKey SQL join On Second primaryKey |
524 | 523 | * |
525 | - * @return dbObject |
|
524 | + * @return Model |
|
526 | 525 | */ |
527 | 526 | private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
528 | 527 | $joinObj = new $objectName; |
@@ -571,7 +570,7 @@ discard block |
||
571 | 570 | /** |
572 | 571 | * Helper function to create dbObject with Json return type |
573 | 572 | * |
574 | - * @return dbObject |
|
573 | + * @return Model |
|
575 | 574 | */ |
576 | 575 | private function JsonBuilder() { |
577 | 576 | $this->returnType = 'Json'; |
@@ -585,7 +584,7 @@ discard block |
||
585 | 584 | /** |
586 | 585 | * Helper function to create dbObject with Array return type |
587 | 586 | * |
588 | - * @return dbObject |
|
587 | + * @return Model |
|
589 | 588 | */ |
590 | 589 | private function ArrayBuilder() { |
591 | 590 | $this->returnType = 'Array'; |
@@ -596,7 +595,7 @@ discard block |
||
596 | 595 | * Helper function to create dbObject with Object return type. |
597 | 596 | * Added for consistency. Works same way as new $objname () |
598 | 597 | * |
599 | - * @return dbObject |
|
598 | + * @return Model |
|
600 | 599 | */ |
601 | 600 | private function ObjectBuilder() { |
602 | 601 | $this->returnType = 'Object'; |
@@ -651,7 +650,7 @@ discard block |
||
651 | 650 | * @access public |
652 | 651 | * @param string $objectName Object Name |
653 | 652 | * |
654 | - * @return dbObject |
|
653 | + * @return null|Model |
|
655 | 654 | */ |
656 | 655 | private function with($objectName) { |
657 | 656 | if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @var int |
11 | 11 | */ |
12 | - public static $pageLimit = 20; |
|
12 | + public static $pageLimit=20; |
|
13 | 13 | /** |
14 | 14 | * Variable that holds total pages count of last paginate() query |
15 | 15 | * |
16 | 16 | * @var int |
17 | 17 | */ |
18 | - public static $totalPages = 0; |
|
18 | + public static $totalPages=0; |
|
19 | 19 | /** |
20 | 20 | * Models path |
21 | 21 | * |
@@ -33,33 +33,33 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @var boolean |
35 | 35 | */ |
36 | - public $isNew = true; |
|
36 | + public $isNew=true; |
|
37 | 37 | /** |
38 | 38 | * Return type: 'Array' to return results as array, 'Object' as object |
39 | 39 | * 'Json' as json string |
40 | 40 | * |
41 | 41 | * @var string |
42 | 42 | */ |
43 | - public $returnType = 'Object'; |
|
43 | + public $returnType='Object'; |
|
44 | 44 | /** |
45 | 45 | * An array that holds insert/update/select errors |
46 | 46 | * |
47 | 47 | * @var array |
48 | 48 | */ |
49 | - public $errors = null; |
|
49 | + public $errors=null; |
|
50 | 50 | /** |
51 | 51 | * Primary key for an object. 'id' is a default value. |
52 | 52 | * |
53 | 53 | * @var stating |
54 | 54 | */ |
55 | - protected $primaryKey = 'id'; |
|
55 | + protected $primaryKey='id'; |
|
56 | 56 | /** |
57 | 57 | * Table name for an object. Class name will be used by default |
58 | 58 | * |
59 | 59 | * @var stating |
60 | 60 | */ |
61 | 61 | protected $dbTable; |
62 | - protected $dbConn = null; |
|
62 | + protected $dbConn=null; |
|
63 | 63 | protected $prefix; |
64 | 64 | /** |
65 | 65 | * Working instance of MysqliDb created earlier |
@@ -73,24 +73,24 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @var string |
75 | 75 | */ |
76 | - private $_with = Array(); |
|
76 | + private $_with=Array(); |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param array $data Data to preload on object creation |
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | - $this->db = app('db')->connect($this->dbConn); |
|
82 | + $this->db=app('db')->connect($this->dbConn); |
|
83 | 83 | if ($this->prefix) { |
84 | - $this->db = $this->db->setPrefix($this->prefix); |
|
84 | + $this->db=$this->db->setPrefix($this->prefix); |
|
85 | 85 | } |
86 | 86 | if (!$this->dbTable) { |
87 | - $classFull = get_class($this); |
|
88 | - $classArray = explode("\\", $classFull); |
|
89 | - $classSelf = array_pop($classArray); |
|
90 | - $classSelf = Str::snake($classSelf); |
|
91 | - $this->dbTable = $classSelf; |
|
87 | + $classFull=get_class($this); |
|
88 | + $classArray=explode("\\", $classFull); |
|
89 | + $classSelf=array_pop($classArray); |
|
90 | + $classSelf=Str::snake($classSelf); |
|
91 | + $this->dbTable=$classSelf; |
|
92 | 92 | } |
93 | - $this->db = $this->db->table($this->dbTable); |
|
93 | + $this->db=$this->db->table($this->dbTable); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | * @return dbObject |
101 | 101 | */ |
102 | 102 | public static function table($tableName) { |
103 | - $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName); |
|
103 | + $tableName=preg_replace("/[^-a-z0-9_]+/i", '', $tableName); |
|
104 | 104 | if (!class_exists($tableName)) |
105 | 105 | eval ("class $tableName extends dbObject {}"); |
106 | - return new $tableName (); |
|
106 | + return new $tableName(); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -117,23 +117,23 @@ discard block |
||
117 | 117 | * @return mixed |
118 | 118 | */ |
119 | 119 | public static function __callStatic($method, $arg) { |
120 | - $obj = new static; |
|
121 | - $result = call_user_func_array(array($obj, $method), $arg); |
|
120 | + $obj=new static; |
|
121 | + $result=call_user_func_array(array($obj, $method), $arg); |
|
122 | 122 | if (method_exists($obj, $method)) |
123 | 123 | return $result; |
124 | 124 | return $obj; |
125 | 125 | } |
126 | 126 | |
127 | - public static function autoload($path = null) { |
|
127 | + public static function autoload($path=null) { |
|
128 | 128 | if ($path) |
129 | - static::$modelPath = $path . "/"; |
|
129 | + static::$modelPath=$path."/"; |
|
130 | 130 | else |
131 | - static::$modelPath = __DIR__ . "/models/"; |
|
131 | + static::$modelPath=__DIR__."/models/"; |
|
132 | 132 | spl_autoload_register("dbObject::dbObjectAutoload"); |
133 | 133 | } |
134 | 134 | |
135 | 135 | private static function dbObjectAutoload($classname) { |
136 | - $filename = static::$modelPath . $classname . ".php"; |
|
136 | + $filename=static::$modelPath.$classname.".php"; |
|
137 | 137 | if (file_exists($filename)) |
138 | 138 | include($filename); |
139 | 139 | } |
@@ -153,20 +153,20 @@ discard block |
||
153 | 153 | return $this->data[$name]; |
154 | 154 | |
155 | 155 | if (property_exists($this, 'relations') && isset ($this->relations[$name])) { |
156 | - $relationType = strtolower($this->relations[$name][0]); |
|
157 | - $modelName = $this->relations[$name][1]; |
|
156 | + $relationType=strtolower($this->relations[$name][0]); |
|
157 | + $modelName=$this->relations[$name][1]; |
|
158 | 158 | switch ($relationType) { |
159 | 159 | case 'hasone': |
160 | - $key = isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name; |
|
161 | - $obj = new $modelName; |
|
162 | - $obj->returnType = $this->returnType; |
|
163 | - return $this->data[$name] = $obj->byId($this->data[$key]); |
|
160 | + $key=isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name; |
|
161 | + $obj=new $modelName; |
|
162 | + $obj->returnType=$this->returnType; |
|
163 | + return $this->data[$name]=$obj->byId($this->data[$key]); |
|
164 | 164 | break; |
165 | 165 | case 'hasmany': |
166 | - $key = $this->relations[$name][2]; |
|
167 | - $obj = new $modelName; |
|
168 | - $obj->returnType = $this->returnType; |
|
169 | - return $this->data[$name] = $obj->where($key, $this->data[$this->primaryKey])->get(); |
|
166 | + $key=$this->relations[$name][2]; |
|
167 | + $obj=new $modelName; |
|
168 | + $obj->returnType=$this->returnType; |
|
169 | + return $this->data[$name]=$obj->where($key, $this->data[$this->primaryKey])->get(); |
|
170 | 170 | break; |
171 | 171 | default: |
172 | 172 | break; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) |
190 | 190 | return; |
191 | 191 | |
192 | - $this->data[$name] = $value; |
|
192 | + $this->data[$name]=$value; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | public function __isset($name) { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return mixed insert id or false in case of failure |
211 | 211 | */ |
212 | - public function save($data = null) { |
|
212 | + public function save($data=null) { |
|
213 | 213 | if ($this->isNew) |
214 | 214 | return $this->insert(); |
215 | 215 | return $this->update($data); |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function insert() { |
222 | 222 | if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) |
223 | - $this->createdAt = date("Y-m-d H:i:s"); |
|
224 | - $sqlData = $this->prepareData(); |
|
223 | + $this->createdAt=date("Y-m-d H:i:s"); |
|
224 | + $sqlData=$this->prepareData(); |
|
225 | 225 | if (!$this->validate($sqlData)) |
226 | 226 | return false; |
227 | 227 | |
228 | - $id = $this->db->insert($this->dbTable, $sqlData); |
|
228 | + $id=$this->db->insert($this->dbTable, $sqlData); |
|
229 | 229 | if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) |
230 | - $this->data[$this->primaryKey] = $id; |
|
231 | - $this->isNew = false; |
|
230 | + $this->data[$this->primaryKey]=$id; |
|
231 | + $this->isNew=false; |
|
232 | 232 | |
233 | 233 | return $id; |
234 | 234 | } |
235 | 235 | |
236 | 236 | private function prepareData() { |
237 | - $this->errors = Array(); |
|
238 | - $sqlData = Array(); |
|
237 | + $this->errors=Array(); |
|
238 | + $sqlData=Array(); |
|
239 | 239 | if (count($this->data) == 0) |
240 | 240 | return Array(); |
241 | 241 | |
@@ -247,27 +247,27 @@ discard block |
||
247 | 247 | |
248 | 248 | foreach ($this->data as $key => &$value) { |
249 | 249 | if ($value instanceof dbObject && $value->isNew == true) { |
250 | - $id = $value->save(); |
|
250 | + $id=$value->save(); |
|
251 | 251 | if ($id) |
252 | - $value = $id; |
|
252 | + $value=$id; |
|
253 | 253 | else |
254 | - $this->errors = array_merge($this->errors, $value->errors); |
|
254 | + $this->errors=array_merge($this->errors, $value->errors); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | if (!in_array($key, array_keys($this->dbFields))) |
258 | 258 | continue; |
259 | 259 | |
260 | 260 | if (!is_array($value)) { |
261 | - $sqlData[$key] = $value; |
|
261 | + $sqlData[$key]=$value; |
|
262 | 262 | continue; |
263 | 263 | } |
264 | 264 | |
265 | 265 | if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) |
266 | - $sqlData[$key] = json_encode($value); |
|
266 | + $sqlData[$key]=json_encode($value); |
|
267 | 267 | else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) |
268 | - $sqlData[$key] = implode("|", $value); |
|
268 | + $sqlData[$key]=implode("|", $value); |
|
269 | 269 | else |
270 | - $sqlData[$key] = $value; |
|
270 | + $sqlData[$key]=$value; |
|
271 | 271 | } |
272 | 272 | return $sqlData; |
273 | 273 | } |
@@ -280,23 +280,23 @@ discard block |
||
280 | 280 | return true; |
281 | 281 | |
282 | 282 | foreach ($this->dbFields as $key => $desc) { |
283 | - $type = null; |
|
284 | - $required = false; |
|
283 | + $type=null; |
|
284 | + $required=false; |
|
285 | 285 | if (isset ($data[$key])) |
286 | - $value = $data[$key]; |
|
286 | + $value=$data[$key]; |
|
287 | 287 | else |
288 | - $value = null; |
|
288 | + $value=null; |
|
289 | 289 | |
290 | 290 | if (is_array($value)) |
291 | 291 | continue; |
292 | 292 | |
293 | 293 | if (isset ($desc[0])) |
294 | - $type = $desc[0]; |
|
294 | + $type=$desc[0]; |
|
295 | 295 | if (isset ($desc[1]) && ($desc[1] == 'required')) |
296 | - $required = true; |
|
296 | + $required=true; |
|
297 | 297 | |
298 | 298 | if ($required && strlen($value) == 0) { |
299 | - $this->errors[] = Array($this->dbTable . "." . $key => "is required"); |
|
299 | + $this->errors[]=Array($this->dbTable.".".$key => "is required"); |
|
300 | 300 | continue; |
301 | 301 | } |
302 | 302 | if ($value == null) |
@@ -304,29 +304,29 @@ discard block |
||
304 | 304 | |
305 | 305 | switch ($type) { |
306 | 306 | case "text"; |
307 | - $regexp = null; |
|
307 | + $regexp=null; |
|
308 | 308 | break; |
309 | 309 | case "int": |
310 | - $regexp = "/^[0-9]*$/"; |
|
310 | + $regexp="/^[0-9]*$/"; |
|
311 | 311 | break; |
312 | 312 | case "double": |
313 | - $regexp = "/^[0-9\.]*$/"; |
|
313 | + $regexp="/^[0-9\.]*$/"; |
|
314 | 314 | break; |
315 | 315 | case "bool": |
316 | - $regexp = '/^[yes|no|0|1|true|false]$/i'; |
|
316 | + $regexp='/^[yes|no|0|1|true|false]$/i'; |
|
317 | 317 | break; |
318 | 318 | case "datetime": |
319 | - $regexp = "/^[0-9a-zA-Z -:]*$/"; |
|
319 | + $regexp="/^[0-9a-zA-Z -:]*$/"; |
|
320 | 320 | break; |
321 | 321 | default: |
322 | - $regexp = $type; |
|
322 | + $regexp=$type; |
|
323 | 323 | break; |
324 | 324 | } |
325 | 325 | if (!$regexp) |
326 | 326 | continue; |
327 | 327 | |
328 | 328 | if (!preg_match($regexp, $value)) { |
329 | - $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed"); |
|
329 | + $this->errors[]=Array($this->dbTable.".".$key => "$type validation failed"); |
|
330 | 330 | continue; |
331 | 331 | } |
332 | 332 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | /** |
337 | 337 | * @param array $data Optional update data to apply to the object |
338 | 338 | */ |
339 | - public function update($data = null) { |
|
339 | + public function update($data=null) { |
|
340 | 340 | if (empty ($this->dbFields)) |
341 | 341 | return false; |
342 | 342 | |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | |
346 | 346 | if ($data) { |
347 | 347 | foreach ($data as $k => $v) |
348 | - $this->$k = $v; |
|
348 | + $this->$k=$v; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) |
352 | - $this->updatedAt = date("Y-m-d H:i:s"); |
|
352 | + $this->updatedAt=date("Y-m-d H:i:s"); |
|
353 | 353 | |
354 | - $sqlData = $this->prepareData(); |
|
354 | + $sqlData=$this->prepareData(); |
|
355 | 355 | if (!$this->validate($sqlData)) |
356 | 356 | return false; |
357 | 357 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | if (method_exists($this, $method)) |
385 | 385 | return call_user_func_array(array($this, $method), $arg); |
386 | 386 | $this->db->table($this->dbTable); |
387 | - return call_user_func_array(array($this->db, $method), $arg);; |
|
387 | + return call_user_func_array(array($this->db, $method), $arg); ; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | * @return array Converted data |
412 | 412 | */ |
413 | 413 | public function toArray() { |
414 | - $data = $this->data; |
|
414 | + $data=$this->data; |
|
415 | 415 | $this->processAllWith($data); |
416 | 416 | foreach ($data as &$d) { |
417 | 417 | if ($d instanceof dbObject) |
418 | - $d = $d->data; |
|
418 | + $d=$d->data; |
|
419 | 419 | } |
420 | 420 | return $data; |
421 | 421 | } |
@@ -425,40 +425,40 @@ discard block |
||
425 | 425 | * |
426 | 426 | * @param array $data |
427 | 427 | */ |
428 | - private function processAllWith(&$data, $shouldReset = true) { |
|
428 | + private function processAllWith(&$data, $shouldReset=true) { |
|
429 | 429 | if (count($this->_with) == 0) |
430 | 430 | return; |
431 | 431 | |
432 | 432 | foreach ($this->_with as $name => $opts) { |
433 | - $relationType = strtolower($opts[0]); |
|
434 | - $modelName = $opts[1]; |
|
433 | + $relationType=strtolower($opts[0]); |
|
434 | + $modelName=$opts[1]; |
|
435 | 435 | if ($relationType == 'hasone') { |
436 | - $obj = new $modelName; |
|
437 | - $table = $obj->dbTable; |
|
438 | - $primaryKey = $obj->primaryKey; |
|
436 | + $obj=new $modelName; |
|
437 | + $table=$obj->dbTable; |
|
438 | + $primaryKey=$obj->primaryKey; |
|
439 | 439 | |
440 | 440 | if (!isset ($data[$table])) { |
441 | - $data[$name] = $this->$name; |
|
441 | + $data[$name]=$this->$name; |
|
442 | 442 | continue; |
443 | 443 | } |
444 | 444 | if ($data[$table][$primaryKey] === null) { |
445 | - $data[$name] = null; |
|
445 | + $data[$name]=null; |
|
446 | 446 | } else { |
447 | 447 | if ($this->returnType == 'Object') { |
448 | - $item = new $modelName ($data[$table]); |
|
449 | - $item->returnType = $this->returnType; |
|
450 | - $item->isNew = false; |
|
451 | - $data[$name] = $item; |
|
448 | + $item=new $modelName($data[$table]); |
|
449 | + $item->returnType=$this->returnType; |
|
450 | + $item->isNew=false; |
|
451 | + $data[$name]=$item; |
|
452 | 452 | } else { |
453 | - $data[$name] = $data[$table]; |
|
453 | + $data[$name]=$data[$table]; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | unset ($data[$table]); |
457 | 457 | } else |
458 | - $data[$name] = $this->$name; |
|
458 | + $data[$name]=$this->$name; |
|
459 | 459 | } |
460 | 460 | if ($shouldReset) |
461 | - $this->_with = Array(); |
|
461 | + $this->_with=Array(); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -471,24 +471,24 @@ discard block |
||
471 | 471 | * |
472 | 472 | * @return array Array of dbObjects |
473 | 473 | */ |
474 | - protected function get($limit = null, $fields = null) { |
|
475 | - $objects = Array(); |
|
474 | + protected function get($limit=null, $fields=null) { |
|
475 | + $objects=Array(); |
|
476 | 476 | $this->processHasOneWith(); |
477 | - $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
477 | + $results=$this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
478 | 478 | if ($this->db->count == 0) |
479 | 479 | return null; |
480 | 480 | |
481 | 481 | foreach ($results as &$r) { |
482 | 482 | $this->processArrays($r); |
483 | - $this->data = $r; |
|
483 | + $this->data=$r; |
|
484 | 484 | $this->processAllWith($r, false); |
485 | 485 | if ($this->returnType == 'Object') { |
486 | - $item = new static ($r); |
|
487 | - $item->isNew = false; |
|
488 | - $objects[] = $item; |
|
486 | + $item=new static ($r); |
|
487 | + $item->isNew=false; |
|
488 | + $objects[]=$item; |
|
489 | 489 | } |
490 | 490 | } |
491 | - $this->_with = Array(); |
|
491 | + $this->_with=Array(); |
|
492 | 492 | if ($this->returnType == 'Object') |
493 | 493 | return $objects; |
494 | 494 | |
@@ -502,11 +502,11 @@ discard block |
||
502 | 502 | if (count($this->_with) == 0) |
503 | 503 | return; |
504 | 504 | foreach ($this->_with as $name => $opts) { |
505 | - $relationType = strtolower($opts[0]); |
|
506 | - $modelName = $opts[1]; |
|
507 | - $key = null; |
|
505 | + $relationType=strtolower($opts[0]); |
|
506 | + $modelName=$opts[1]; |
|
507 | + $key=null; |
|
508 | 508 | if (isset ($opts[2])) |
509 | - $key = $opts[2]; |
|
509 | + $key=$opts[2]; |
|
510 | 510 | if ($relationType == 'hasone') { |
511 | 511 | $this->db->setQueryOption("MYSQLI_NESTJOIN"); |
512 | 512 | $this->join($modelName, $key); |
@@ -525,18 +525,18 @@ discard block |
||
525 | 525 | * |
526 | 526 | * @return dbObject |
527 | 527 | */ |
528 | - private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
|
529 | - $joinObj = new $objectName; |
|
528 | + private function join($objectName, $key=null, $joinType='LEFT', $primaryKey=null) { |
|
529 | + $joinObj=new $objectName; |
|
530 | 530 | if (!$key) |
531 | - $key = $objectName . "id"; |
|
531 | + $key=$objectName."id"; |
|
532 | 532 | |
533 | 533 | if (!$primaryKey) |
534 | - $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
534 | + $primaryKey=$this->db->getPrefix().$joinObj->dbTable.".".$joinObj->primaryKey; |
|
535 | 535 | |
536 | 536 | if (!strchr($key, '.')) |
537 | - $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
537 | + $joinStr=$this->db->getPrefix().$this->dbTable.".{$key} = ".$primaryKey; |
|
538 | 538 | else |
539 | - $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
539 | + $joinStr=$this->db->getPrefix()."{$key} = ".$primaryKey; |
|
540 | 540 | |
541 | 541 | $this->db->join($joinObj->dbTable, $joinStr, $joinType); |
542 | 542 | return $this; |
@@ -548,12 +548,12 @@ discard block |
||
548 | 548 | private function processArrays(&$data) { |
549 | 549 | if (isset ($this->jsonFields) && is_array($this->jsonFields)) { |
550 | 550 | foreach ($this->jsonFields as $key) |
551 | - $data[$key] = json_decode($data[$key]); |
|
551 | + $data[$key]=json_decode($data[$key]); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | if (isset ($this->arrayFields) && is_array($this->arrayFields)) { |
555 | 555 | foreach ($this->arrayFields as $key) |
556 | - $data[$key] = explode("|", $data[$key]); |
|
556 | + $data[$key]=explode("|", $data[$key]); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return int |
564 | 564 | */ |
565 | 565 | protected function count() { |
566 | - $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
566 | + $res=$this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
567 | 567 | if (!$res) |
568 | 568 | return 0; |
569 | 569 | return $res; |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * @return dbObject |
576 | 576 | */ |
577 | 577 | private function JsonBuilder() { |
578 | - $this->returnType = 'Json'; |
|
578 | + $this->returnType='Json'; |
|
579 | 579 | return $this; |
580 | 580 | } |
581 | 581 | |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | * @return dbObject |
590 | 590 | */ |
591 | 591 | private function ArrayBuilder() { |
592 | - $this->returnType = 'Array'; |
|
592 | + $this->returnType='Array'; |
|
593 | 593 | return $this; |
594 | 594 | } |
595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @return dbObject |
601 | 601 | */ |
602 | 602 | private function ObjectBuilder() { |
603 | - $this->returnType = 'Object'; |
|
603 | + $this->returnType='Object'; |
|
604 | 604 | return $this; |
605 | 605 | } |
606 | 606 | |
@@ -613,8 +613,8 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @return dbObject|array |
615 | 615 | */ |
616 | - private function byId($id, $fields = null) { |
|
617 | - $this->db->where($this->db->getPrefix() . $this->dbTable . '.' . $this->primaryKey, $id); |
|
616 | + private function byId($id, $fields=null) { |
|
617 | + $this->db->where($this->db->getPrefix().$this->dbTable.'.'.$this->primaryKey, $id); |
|
618 | 618 | return $this->getOne($fields); |
619 | 619 | } |
620 | 620 | |
@@ -626,22 +626,22 @@ discard block |
||
626 | 626 | * |
627 | 627 | * @return dbObject |
628 | 628 | */ |
629 | - protected function getOne($fields = null) { |
|
629 | + protected function getOne($fields=null) { |
|
630 | 630 | $this->processHasOneWith(); |
631 | - $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
631 | + $results=$this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
632 | 632 | if ($this->db->count == 0) |
633 | 633 | return null; |
634 | 634 | |
635 | 635 | $this->processArrays($results); |
636 | - $this->data = $results; |
|
636 | + $this->data=$results; |
|
637 | 637 | $this->processAllWith($results); |
638 | 638 | if ($this->returnType == 'Json') |
639 | 639 | return json_encode($results); |
640 | 640 | if ($this->returnType == 'Array') |
641 | 641 | return $results; |
642 | 642 | |
643 | - $item = new static ($results); |
|
644 | - $item->isNew = false; |
|
643 | + $item=new static ($results); |
|
644 | + $item->isNew=false; |
|
645 | 645 | |
646 | 646 | return $item; |
647 | 647 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
659 | 659 | die ("No relation with name $objectName found"); |
660 | 660 | |
661 | - $this->_with[$objectName] = $this->relations[$objectName]; |
|
661 | + $this->_with[$objectName]=$this->relations[$objectName]; |
|
662 | 662 | |
663 | 663 | return $this; |
664 | 664 | } |
@@ -679,23 +679,23 @@ discard block |
||
679 | 679 | * @param array|string $fields Array or coma separated list of fields to fetch |
680 | 680 | * @return array |
681 | 681 | */ |
682 | - private function paginate($page, $fields = null) { |
|
683 | - $this->db->pageLimit = self::$pageLimit; |
|
684 | - $res = $this->db->paginate($this->dbTable, $page, $fields); |
|
685 | - self::$totalPages = $this->db->totalPages; |
|
682 | + private function paginate($page, $fields=null) { |
|
683 | + $this->db->pageLimit=self::$pageLimit; |
|
684 | + $res=$this->db->paginate($this->dbTable, $page, $fields); |
|
685 | + self::$totalPages=$this->db->totalPages; |
|
686 | 686 | if ($this->db->count == 0) return null; |
687 | 687 | |
688 | 688 | foreach ($res as &$r) { |
689 | 689 | $this->processArrays($r); |
690 | - $this->data = $r; |
|
690 | + $this->data=$r; |
|
691 | 691 | $this->processAllWith($r, false); |
692 | 692 | if ($this->returnType == 'Object') { |
693 | - $item = new static ($r); |
|
694 | - $item->isNew = false; |
|
695 | - $objects[] = $item; |
|
693 | + $item=new static ($r); |
|
694 | + $item->isNew=false; |
|
695 | + $objects[]=$item; |
|
696 | 696 | } |
697 | 697 | } |
698 | - $this->_with = Array(); |
|
698 | + $this->_with=Array(); |
|
699 | 699 | if ($this->returnType == 'Object') |
700 | 700 | return $objects; |
701 | 701 |
@@ -101,8 +101,9 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public static function table($tableName) { |
103 | 103 | $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName); |
104 | - if (!class_exists($tableName)) |
|
105 | - eval ("class $tableName extends dbObject {}"); |
|
104 | + if (!class_exists($tableName)) { |
|
105 | + eval ("class $tableName extends dbObject {}"); |
|
106 | + } |
|
106 | 107 | return new $tableName (); |
107 | 108 | } |
108 | 109 | |
@@ -119,23 +120,26 @@ discard block |
||
119 | 120 | public static function __callStatic($method, $arg) { |
120 | 121 | $obj = new static; |
121 | 122 | $result = call_user_func_array(array($obj, $method), $arg); |
122 | - if (method_exists($obj, $method)) |
|
123 | - return $result; |
|
123 | + if (method_exists($obj, $method)) { |
|
124 | + return $result; |
|
125 | + } |
|
124 | 126 | return $obj; |
125 | 127 | } |
126 | 128 | |
127 | 129 | public static function autoload($path = null) { |
128 | - if ($path) |
|
129 | - static::$modelPath = $path . "/"; |
|
130 | - else |
|
131 | - static::$modelPath = __DIR__ . "/models/"; |
|
130 | + if ($path) { |
|
131 | + static::$modelPath = $path . "/"; |
|
132 | + } else { |
|
133 | + static::$modelPath = __DIR__ . "/models/"; |
|
134 | + } |
|
132 | 135 | spl_autoload_register("dbObject::dbObjectAutoload"); |
133 | 136 | } |
134 | 137 | |
135 | 138 | private static function dbObjectAutoload($classname) { |
136 | 139 | $filename = static::$modelPath . $classname . ".php"; |
137 | - if (file_exists($filename)) |
|
138 | - include($filename); |
|
140 | + if (file_exists($filename)) { |
|
141 | + include($filename); |
|
142 | + } |
|
139 | 143 | } |
140 | 144 | |
141 | 145 | /** |
@@ -146,11 +150,13 @@ discard block |
||
146 | 150 | * @return mixed |
147 | 151 | */ |
148 | 152 | public function __get($name) { |
149 | - if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) |
|
150 | - return null; |
|
153 | + if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) { |
|
154 | + return null; |
|
155 | + } |
|
151 | 156 | |
152 | - if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject) |
|
153 | - return $this->data[$name]; |
|
157 | + if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject) { |
|
158 | + return $this->data[$name]; |
|
159 | + } |
|
154 | 160 | |
155 | 161 | if (property_exists($this, 'relations') && isset ($this->relations[$name])) { |
156 | 162 | $relationType = strtolower($this->relations[$name][0]); |
@@ -173,11 +179,13 @@ discard block |
||
173 | 179 | } |
174 | 180 | } |
175 | 181 | |
176 | - if (isset ($this->data[$name])) |
|
177 | - return $this->data[$name]; |
|
182 | + if (isset ($this->data[$name])) { |
|
183 | + return $this->data[$name]; |
|
184 | + } |
|
178 | 185 | |
179 | - if (property_exists($this->db, $name)) |
|
180 | - return $this->db->$name; |
|
186 | + if (property_exists($this->db, $name)) { |
|
187 | + return $this->db->$name; |
|
188 | + } |
|
181 | 189 | } |
182 | 190 | |
183 | 191 | /** |
@@ -186,18 +194,21 @@ discard block |
||
186 | 194 | * @return mixed |
187 | 195 | */ |
188 | 196 | public function __set($name, $value) { |
189 | - if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) |
|
190 | - return; |
|
197 | + if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) { |
|
198 | + return; |
|
199 | + } |
|
191 | 200 | |
192 | 201 | $this->data[$name] = $value; |
193 | 202 | } |
194 | 203 | |
195 | 204 | public function __isset($name) { |
196 | - if (isset ($this->data[$name])) |
|
197 | - return isset ($this->data[$name]); |
|
205 | + if (isset ($this->data[$name])) { |
|
206 | + return isset ($this->data[$name]); |
|
207 | + } |
|
198 | 208 | |
199 | - if (property_exists($this->db, $name)) |
|
200 | - return isset ($this->db->$name); |
|
209 | + if (property_exists($this->db, $name)) { |
|
210 | + return isset ($this->db->$name); |
|
211 | + } |
|
201 | 212 | } |
202 | 213 | |
203 | 214 | public function __unset($name) { |
@@ -210,8 +221,9 @@ discard block |
||
210 | 221 | * @return mixed insert id or false in case of failure |
211 | 222 | */ |
212 | 223 | public function save($data = null) { |
213 | - if ($this->isNew) |
|
214 | - return $this->insert(); |
|
224 | + if ($this->isNew) { |
|
225 | + return $this->insert(); |
|
226 | + } |
|
215 | 227 | return $this->update($data); |
216 | 228 | } |
217 | 229 | |
@@ -219,15 +231,18 @@ discard block |
||
219 | 231 | * @return mixed insert id or false in case of failure |
220 | 232 | */ |
221 | 233 | public function insert() { |
222 | - if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) |
|
223 | - $this->createdAt = date("Y-m-d H:i:s"); |
|
234 | + if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) { |
|
235 | + $this->createdAt = date("Y-m-d H:i:s"); |
|
236 | + } |
|
224 | 237 | $sqlData = $this->prepareData(); |
225 | - if (!$this->validate($sqlData)) |
|
226 | - return false; |
|
238 | + if (!$this->validate($sqlData)) { |
|
239 | + return false; |
|
240 | + } |
|
227 | 241 | |
228 | 242 | $id = $this->db->insert($this->dbTable, $sqlData); |
229 | - if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) |
|
230 | - $this->data[$this->primaryKey] = $id; |
|
243 | + if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) { |
|
244 | + $this->data[$this->primaryKey] = $id; |
|
245 | + } |
|
231 | 246 | $this->isNew = false; |
232 | 247 | |
233 | 248 | return $id; |
@@ -236,38 +251,44 @@ discard block |
||
236 | 251 | private function prepareData() { |
237 | 252 | $this->errors = Array(); |
238 | 253 | $sqlData = Array(); |
239 | - if (count($this->data) == 0) |
|
240 | - return Array(); |
|
254 | + if (count($this->data) == 0) { |
|
255 | + return Array(); |
|
256 | + } |
|
241 | 257 | |
242 | - if (method_exists($this, "preLoad")) |
|
243 | - $this->preLoad($this->data); |
|
258 | + if (method_exists($this, "preLoad")) { |
|
259 | + $this->preLoad($this->data); |
|
260 | + } |
|
244 | 261 | |
245 | - if (!$this->dbFields) |
|
246 | - return $this->data; |
|
262 | + if (!$this->dbFields) { |
|
263 | + return $this->data; |
|
264 | + } |
|
247 | 265 | |
248 | 266 | foreach ($this->data as $key => &$value) { |
249 | 267 | if ($value instanceof dbObject && $value->isNew == true) { |
250 | 268 | $id = $value->save(); |
251 | - if ($id) |
|
252 | - $value = $id; |
|
253 | - else |
|
254 | - $this->errors = array_merge($this->errors, $value->errors); |
|
269 | + if ($id) { |
|
270 | + $value = $id; |
|
271 | + } else { |
|
272 | + $this->errors = array_merge($this->errors, $value->errors); |
|
273 | + } |
|
255 | 274 | } |
256 | 275 | |
257 | - if (!in_array($key, array_keys($this->dbFields))) |
|
258 | - continue; |
|
276 | + if (!in_array($key, array_keys($this->dbFields))) { |
|
277 | + continue; |
|
278 | + } |
|
259 | 279 | |
260 | 280 | if (!is_array($value)) { |
261 | 281 | $sqlData[$key] = $value; |
262 | 282 | continue; |
263 | 283 | } |
264 | 284 | |
265 | - if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) |
|
266 | - $sqlData[$key] = json_encode($value); |
|
267 | - else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) |
|
268 | - $sqlData[$key] = implode("|", $value); |
|
269 | - else |
|
270 | - $sqlData[$key] = $value; |
|
285 | + if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) { |
|
286 | + $sqlData[$key] = json_encode($value); |
|
287 | + } else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) { |
|
288 | + $sqlData[$key] = implode("|", $value); |
|
289 | + } else { |
|
290 | + $sqlData[$key] = $value; |
|
291 | + } |
|
271 | 292 | } |
272 | 293 | return $sqlData; |
273 | 294 | } |
@@ -276,31 +297,37 @@ discard block |
||
276 | 297 | * @param array $data |
277 | 298 | */ |
278 | 299 | private function validate($data) { |
279 | - if (!$this->dbFields) |
|
280 | - return true; |
|
300 | + if (!$this->dbFields) { |
|
301 | + return true; |
|
302 | + } |
|
281 | 303 | |
282 | 304 | foreach ($this->dbFields as $key => $desc) { |
283 | 305 | $type = null; |
284 | 306 | $required = false; |
285 | - if (isset ($data[$key])) |
|
286 | - $value = $data[$key]; |
|
287 | - else |
|
288 | - $value = null; |
|
307 | + if (isset ($data[$key])) { |
|
308 | + $value = $data[$key]; |
|
309 | + } else { |
|
310 | + $value = null; |
|
311 | + } |
|
289 | 312 | |
290 | - if (is_array($value)) |
|
291 | - continue; |
|
313 | + if (is_array($value)) { |
|
314 | + continue; |
|
315 | + } |
|
292 | 316 | |
293 | - if (isset ($desc[0])) |
|
294 | - $type = $desc[0]; |
|
295 | - if (isset ($desc[1]) && ($desc[1] == 'required')) |
|
296 | - $required = true; |
|
317 | + if (isset ($desc[0])) { |
|
318 | + $type = $desc[0]; |
|
319 | + } |
|
320 | + if (isset ($desc[1]) && ($desc[1] == 'required')) { |
|
321 | + $required = true; |
|
322 | + } |
|
297 | 323 | |
298 | 324 | if ($required && strlen($value) == 0) { |
299 | 325 | $this->errors[] = Array($this->dbTable . "." . $key => "is required"); |
300 | 326 | continue; |
301 | 327 | } |
302 | - if ($value == null) |
|
303 | - continue; |
|
328 | + if ($value == null) { |
|
329 | + continue; |
|
330 | + } |
|
304 | 331 | |
305 | 332 | switch ($type) { |
306 | 333 | case "text"; |
@@ -322,8 +349,9 @@ discard block |
||
322 | 349 | $regexp = $type; |
323 | 350 | break; |
324 | 351 | } |
325 | - if (!$regexp) |
|
326 | - continue; |
|
352 | + if (!$regexp) { |
|
353 | + continue; |
|
354 | + } |
|
327 | 355 | |
328 | 356 | if (!preg_match($regexp, $value)) { |
329 | 357 | $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed"); |
@@ -337,23 +365,28 @@ discard block |
||
337 | 365 | * @param array $data Optional update data to apply to the object |
338 | 366 | */ |
339 | 367 | public function update($data = null) { |
340 | - if (empty ($this->dbFields)) |
|
341 | - return false; |
|
368 | + if (empty ($this->dbFields)) { |
|
369 | + return false; |
|
370 | + } |
|
342 | 371 | |
343 | - if (empty ($this->data[$this->primaryKey])) |
|
344 | - return false; |
|
372 | + if (empty ($this->data[$this->primaryKey])) { |
|
373 | + return false; |
|
374 | + } |
|
345 | 375 | |
346 | 376 | if ($data) { |
347 | - foreach ($data as $k => $v) |
|
348 | - $this->$k = $v; |
|
377 | + foreach ($data as $k => $v) { |
|
378 | + $this->$k = $v; |
|
379 | + } |
|
349 | 380 | } |
350 | 381 | |
351 | - if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) |
|
352 | - $this->updatedAt = date("Y-m-d H:i:s"); |
|
382 | + if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) { |
|
383 | + $this->updatedAt = date("Y-m-d H:i:s"); |
|
384 | + } |
|
353 | 385 | |
354 | 386 | $sqlData = $this->prepareData(); |
355 | - if (!$this->validate($sqlData)) |
|
356 | - return false; |
|
387 | + if (!$this->validate($sqlData)) { |
|
388 | + return false; |
|
389 | + } |
|
357 | 390 | |
358 | 391 | $this->db->where($this->primaryKey, $this->data[$this->primaryKey]); |
359 | 392 | return $this->db->update($this->dbTable, $sqlData); |
@@ -365,8 +398,9 @@ discard block |
||
365 | 398 | * @return boolean Indicates success. 0 or 1. |
366 | 399 | */ |
367 | 400 | public function delete() { |
368 | - if (empty ($this->data[$this->primaryKey])) |
|
369 | - return false; |
|
401 | + if (empty ($this->data[$this->primaryKey])) { |
|
402 | + return false; |
|
403 | + } |
|
370 | 404 | |
371 | 405 | $this->db->where($this->primaryKey, $this->data[$this->primaryKey]); |
372 | 406 | return $this->db->delete($this->dbTable); |
@@ -381,8 +415,9 @@ discard block |
||
381 | 415 | * @return mixed |
382 | 416 | */ |
383 | 417 | public function __call($method, $arg) { |
384 | - if (method_exists($this, $method)) |
|
385 | - return call_user_func_array(array($this, $method), $arg); |
|
418 | + if (method_exists($this, $method)) { |
|
419 | + return call_user_func_array(array($this, $method), $arg); |
|
420 | + } |
|
386 | 421 | $this->db->table($this->dbTable); |
387 | 422 | return call_user_func_array(array($this->db, $method), $arg);; |
388 | 423 | } |
@@ -414,8 +449,9 @@ discard block |
||
414 | 449 | $data = $this->data; |
415 | 450 | $this->processAllWith($data); |
416 | 451 | foreach ($data as &$d) { |
417 | - if ($d instanceof dbObject) |
|
418 | - $d = $d->data; |
|
452 | + if ($d instanceof dbObject) { |
|
453 | + $d = $d->data; |
|
454 | + } |
|
419 | 455 | } |
420 | 456 | return $data; |
421 | 457 | } |
@@ -426,8 +462,9 @@ discard block |
||
426 | 462 | * @param array $data |
427 | 463 | */ |
428 | 464 | private function processAllWith(&$data, $shouldReset = true) { |
429 | - if (count($this->_with) == 0) |
|
430 | - return; |
|
465 | + if (count($this->_with) == 0) { |
|
466 | + return; |
|
467 | + } |
|
431 | 468 | |
432 | 469 | foreach ($this->_with as $name => $opts) { |
433 | 470 | $relationType = strtolower($opts[0]); |
@@ -454,11 +491,13 @@ discard block |
||
454 | 491 | } |
455 | 492 | } |
456 | 493 | unset ($data[$table]); |
457 | - } else |
|
458 | - $data[$name] = $this->$name; |
|
494 | + } else { |
|
495 | + $data[$name] = $this->$name; |
|
496 | + } |
|
497 | + } |
|
498 | + if ($shouldReset) { |
|
499 | + $this->_with = Array(); |
|
459 | 500 | } |
460 | - if ($shouldReset) |
|
461 | - $this->_with = Array(); |
|
462 | 501 | } |
463 | 502 | |
464 | 503 | /** |
@@ -475,8 +514,9 @@ discard block |
||
475 | 514 | $objects = Array(); |
476 | 515 | $this->processHasOneWith(); |
477 | 516 | $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
478 | - if ($this->db->count == 0) |
|
479 | - return null; |
|
517 | + if ($this->db->count == 0) { |
|
518 | + return null; |
|
519 | + } |
|
480 | 520 | |
481 | 521 | foreach ($results as &$r) { |
482 | 522 | $this->processArrays($r); |
@@ -489,24 +529,28 @@ discard block |
||
489 | 529 | } |
490 | 530 | } |
491 | 531 | $this->_with = Array(); |
492 | - if ($this->returnType == 'Object') |
|
493 | - return $objects; |
|
532 | + if ($this->returnType == 'Object') { |
|
533 | + return $objects; |
|
534 | + } |
|
494 | 535 | |
495 | - if ($this->returnType == 'Json') |
|
496 | - return json_encode($results); |
|
536 | + if ($this->returnType == 'Json') { |
|
537 | + return json_encode($results); |
|
538 | + } |
|
497 | 539 | |
498 | 540 | return $results; |
499 | 541 | } |
500 | 542 | |
501 | 543 | private function processHasOneWith() { |
502 | - if (count($this->_with) == 0) |
|
503 | - return; |
|
544 | + if (count($this->_with) == 0) { |
|
545 | + return; |
|
546 | + } |
|
504 | 547 | foreach ($this->_with as $name => $opts) { |
505 | 548 | $relationType = strtolower($opts[0]); |
506 | 549 | $modelName = $opts[1]; |
507 | 550 | $key = null; |
508 | - if (isset ($opts[2])) |
|
509 | - $key = $opts[2]; |
|
551 | + if (isset ($opts[2])) { |
|
552 | + $key = $opts[2]; |
|
553 | + } |
|
510 | 554 | if ($relationType == 'hasone') { |
511 | 555 | $this->db->setQueryOption("MYSQLI_NESTJOIN"); |
512 | 556 | $this->join($modelName, $key); |
@@ -527,16 +571,19 @@ discard block |
||
527 | 571 | */ |
528 | 572 | private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
529 | 573 | $joinObj = new $objectName; |
530 | - if (!$key) |
|
531 | - $key = $objectName . "id"; |
|
574 | + if (!$key) { |
|
575 | + $key = $objectName . "id"; |
|
576 | + } |
|
532 | 577 | |
533 | - if (!$primaryKey) |
|
534 | - $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
578 | + if (!$primaryKey) { |
|
579 | + $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
580 | + } |
|
535 | 581 | |
536 | - if (!strchr($key, '.')) |
|
537 | - $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
538 | - else |
|
539 | - $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
582 | + if (!strchr($key, '.')) { |
|
583 | + $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
584 | + } else { |
|
585 | + $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
586 | + } |
|
540 | 587 | |
541 | 588 | $this->db->join($joinObj->dbTable, $joinStr, $joinType); |
542 | 589 | return $this; |
@@ -547,13 +594,15 @@ discard block |
||
547 | 594 | */ |
548 | 595 | private function processArrays(&$data) { |
549 | 596 | if (isset ($this->jsonFields) && is_array($this->jsonFields)) { |
550 | - foreach ($this->jsonFields as $key) |
|
551 | - $data[$key] = json_decode($data[$key]); |
|
597 | + foreach ($this->jsonFields as $key) { |
|
598 | + $data[$key] = json_decode($data[$key]); |
|
599 | + } |
|
552 | 600 | } |
553 | 601 | |
554 | 602 | if (isset ($this->arrayFields) && is_array($this->arrayFields)) { |
555 | - foreach ($this->arrayFields as $key) |
|
556 | - $data[$key] = explode("|", $data[$key]); |
|
603 | + foreach ($this->arrayFields as $key) { |
|
604 | + $data[$key] = explode("|", $data[$key]); |
|
605 | + } |
|
557 | 606 | } |
558 | 607 | } |
559 | 608 | |
@@ -564,8 +613,9 @@ discard block |
||
564 | 613 | */ |
565 | 614 | protected function count() { |
566 | 615 | $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
567 | - if (!$res) |
|
568 | - return 0; |
|
616 | + if (!$res) { |
|
617 | + return 0; |
|
618 | + } |
|
569 | 619 | return $res; |
570 | 620 | } |
571 | 621 | |
@@ -629,16 +679,19 @@ discard block |
||
629 | 679 | protected function getOne($fields = null) { |
630 | 680 | $this->processHasOneWith(); |
631 | 681 | $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
632 | - if ($this->db->count == 0) |
|
633 | - return null; |
|
682 | + if ($this->db->count == 0) { |
|
683 | + return null; |
|
684 | + } |
|
634 | 685 | |
635 | 686 | $this->processArrays($results); |
636 | 687 | $this->data = $results; |
637 | 688 | $this->processAllWith($results); |
638 | - if ($this->returnType == 'Json') |
|
639 | - return json_encode($results); |
|
640 | - if ($this->returnType == 'Array') |
|
641 | - return $results; |
|
689 | + if ($this->returnType == 'Json') { |
|
690 | + return json_encode($results); |
|
691 | + } |
|
692 | + if ($this->returnType == 'Array') { |
|
693 | + return $results; |
|
694 | + } |
|
642 | 695 | |
643 | 696 | $item = new static ($results); |
644 | 697 | $item->isNew = false; |
@@ -655,8 +708,9 @@ discard block |
||
655 | 708 | * @return dbObject |
656 | 709 | */ |
657 | 710 | private function with($objectName) { |
658 | - if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
|
659 | - die ("No relation with name $objectName found"); |
|
711 | + if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) { |
|
712 | + die ("No relation with name $objectName found"); |
|
713 | + } |
|
660 | 714 | |
661 | 715 | $this->_with[$objectName] = $this->relations[$objectName]; |
662 | 716 | |
@@ -683,7 +737,9 @@ discard block |
||
683 | 737 | $this->db->pageLimit = self::$pageLimit; |
684 | 738 | $res = $this->db->paginate($this->dbTable, $page, $fields); |
685 | 739 | self::$totalPages = $this->db->totalPages; |
686 | - if ($this->db->count == 0) return null; |
|
740 | + if ($this->db->count == 0) { |
|
741 | + return null; |
|
742 | + } |
|
687 | 743 | |
688 | 744 | foreach ($res as &$r) { |
689 | 745 | $this->processArrays($r); |
@@ -696,11 +752,13 @@ discard block |
||
696 | 752 | } |
697 | 753 | } |
698 | 754 | $this->_with = Array(); |
699 | - if ($this->returnType == 'Object') |
|
700 | - return $objects; |
|
755 | + if ($this->returnType == 'Object') { |
|
756 | + return $objects; |
|
757 | + } |
|
701 | 758 | |
702 | - if ($this->returnType == 'Json') |
|
703 | - return json_encode($res); |
|
759 | + if ($this->returnType == 'Json') { |
|
760 | + return json_encode($res); |
|
761 | + } |
|
704 | 762 | |
705 | 763 | return $res; |
706 | 764 | } |
@@ -9,38 +9,38 @@ discard block |
||
9 | 9 | protected $db; |
10 | 10 | protected $field; |
11 | 11 | protected $table; |
12 | - protected $limitCount = null; |
|
12 | + protected $limitCount=null; |
|
13 | 13 | |
14 | 14 | private $connPool; |
15 | 15 | |
16 | - public function connect($conn = null) { |
|
16 | + public function connect($conn=null) { |
|
17 | 17 | if ($conn === null) { |
18 | - $conn = 'db.main'; |
|
18 | + $conn='db.main'; |
|
19 | 19 | } |
20 | - $dbConf = []; |
|
20 | + $dbConf=[]; |
|
21 | 21 | if (is_string($conn)) { |
22 | - $dbConf = app('config')->get($conn); |
|
22 | + $dbConf=app('config')->get($conn); |
|
23 | 23 | } elseif (is_array($conn)) { |
24 | - $dbConf = $conn; |
|
24 | + $dbConf=$conn; |
|
25 | 25 | } else { |
26 | 26 | throw new \InvalidArgumentException("数据库配置必须为字符串或者数组"); |
27 | 27 | } |
28 | 28 | if (is_null($dbConf)) { |
29 | 29 | throw new \InvalidArgumentException("数据库配置异常!"); |
30 | 30 | } |
31 | - $confMd5 = md5(serialize($dbConf)); |
|
31 | + $confMd5=md5(serialize($dbConf)); |
|
32 | 32 | if (!isset($this->connPool[$confMd5])) { |
33 | - $obj = new Mysql($dbConf); |
|
34 | - $this->connPool[$confMd5] = $obj; |
|
33 | + $obj=new Mysql($dbConf); |
|
34 | + $this->connPool[$confMd5]=$obj; |
|
35 | 35 | } |
36 | 36 | return $this->connPool[$confMd5]; |
37 | 37 | } |
38 | 38 | |
39 | 39 | |
40 | 40 | public function __call($method, $arg) { |
41 | - $ret = $this; |
|
41 | + $ret=$this; |
|
42 | 42 | if (method_exists($this->db, $method)) { |
43 | - $ret = call_user_func_array(array($this->db, $method), $arg); |
|
43 | + $ret=call_user_func_array(array($this->db, $method), $arg); |
|
44 | 44 | } |
45 | 45 | return $ret == $this->db ? $this : $ret; |
46 | 46 | } |
@@ -49,6 +49,6 @@ discard block |
||
49 | 49 | if (property_exists($this->db, $name)) { |
50 | 50 | return $this->db->$name; |
51 | 51 | } |
52 | - throw new MemberAccessException('model Property ' . $name . ' not exists'); |
|
52 | + throw new MemberAccessException('model Property '.$name.' not exists'); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | \ No newline at end of file |
@@ -23,32 +23,32 @@ discard block |
||
23 | 23 | * Variable which holds an amount of returned rows during get/getOne/select queries |
24 | 24 | * @var string |
25 | 25 | */ |
26 | - public $count = 0; |
|
26 | + public $count=0; |
|
27 | 27 | /** |
28 | 28 | * Variable which holds an amount of returned rows during get/getOne/select queries with withTotalCount() |
29 | 29 | * @var string |
30 | 30 | */ |
31 | - public $totalCount = 0; |
|
31 | + public $totalCount=0; |
|
32 | 32 | /** |
33 | 33 | * Return type: 'array' to return results as array, 'object' as object |
34 | 34 | * 'json' as json string |
35 | 35 | * @var string |
36 | 36 | */ |
37 | - public $returnType = 'array'; |
|
38 | - public $trace = array(); |
|
37 | + public $returnType='array'; |
|
38 | + public $trace=array(); |
|
39 | 39 | /** |
40 | 40 | * Per page limit for pagination |
41 | 41 | * |
42 | 42 | * @var int |
43 | 43 | */ |
44 | 44 | |
45 | - public $pageLimit = 20; |
|
45 | + public $pageLimit=20; |
|
46 | 46 | /** |
47 | 47 | * Variable that holds total pages count of last paginate() query |
48 | 48 | * |
49 | 49 | * @var int |
50 | 50 | */ |
51 | - public $totalPages = 0; |
|
51 | + public $totalPages=0; |
|
52 | 52 | /** |
53 | 53 | * MySQLi instance |
54 | 54 | * @var mysqli |
@@ -68,53 +68,53 @@ discard block |
||
68 | 68 | * The SQL query options required after SELECT, INSERT, UPDATE or DELETE |
69 | 69 | * @var string |
70 | 70 | */ |
71 | - protected $_queryOptions = array(); |
|
71 | + protected $_queryOptions=array(); |
|
72 | 72 | /** |
73 | 73 | * An array that holds where joins |
74 | 74 | * @var array |
75 | 75 | */ |
76 | - protected $_join = array(); |
|
76 | + protected $_join=array(); |
|
77 | 77 | /** |
78 | 78 | * An array that holds where conditions |
79 | 79 | * @var array |
80 | 80 | */ |
81 | - protected $_where = array(); |
|
81 | + protected $_where=array(); |
|
82 | 82 | /** |
83 | 83 | * An array that holds where join ands |
84 | 84 | * |
85 | 85 | * @var array |
86 | 86 | */ |
87 | - protected $_joinAnd = array(); |
|
87 | + protected $_joinAnd=array(); |
|
88 | 88 | /** |
89 | 89 | * An array that holds having conditions |
90 | 90 | * @var array |
91 | 91 | */ |
92 | - protected $_having = array(); |
|
92 | + protected $_having=array(); |
|
93 | 93 | /** |
94 | 94 | * Dynamic type list for order by condition value |
95 | 95 | * @var array |
96 | 96 | */ |
97 | - protected $_orderBy = array(); // Create the empty 0 index |
|
97 | + protected $_orderBy=array(); // Create the empty 0 index |
|
98 | 98 | /** |
99 | 99 | * Dynamic type list for group by condition value |
100 | 100 | * @var array |
101 | 101 | */ |
102 | - protected $_groupBy = array(); |
|
102 | + protected $_groupBy=array(); |
|
103 | 103 | /** |
104 | 104 | * Dynamic type list for tempromary locking tables. |
105 | 105 | * @var array |
106 | 106 | */ |
107 | - protected $_tableLocks = array(); |
|
107 | + protected $_tableLocks=array(); |
|
108 | 108 | /** |
109 | 109 | * Variable which holds the current table lock method. |
110 | 110 | * @var string |
111 | 111 | */ |
112 | - protected $_tableLockMethod = "READ"; |
|
112 | + protected $_tableLockMethod="READ"; |
|
113 | 113 | /** |
114 | 114 | * Dynamic array that holds a combination of where condition/table data value types and parameter references |
115 | 115 | * @var array |
116 | 116 | */ |
117 | - protected $_bindParams = array(''); |
|
117 | + protected $_bindParams=array(''); |
|
118 | 118 | /** |
119 | 119 | * Variable which holds last statement error |
120 | 120 | * @var string |
@@ -139,39 +139,39 @@ discard block |
||
139 | 139 | * Is Subquery object |
140 | 140 | * @var bool |
141 | 141 | */ |
142 | - protected $isSubQuery = false; |
|
142 | + protected $isSubQuery=false; |
|
143 | 143 | /** |
144 | 144 | * Name of the auto increment column |
145 | 145 | * @var int |
146 | 146 | */ |
147 | - protected $_lastInsertId = null; |
|
147 | + protected $_lastInsertId=null; |
|
148 | 148 | /** |
149 | 149 | * Column names for update when using onDuplicate method |
150 | 150 | * @var array |
151 | 151 | */ |
152 | - protected $_updateColumns = null; |
|
152 | + protected $_updateColumns=null; |
|
153 | 153 | /** |
154 | 154 | * Should join() results be nested by table |
155 | 155 | * @var bool |
156 | 156 | */ |
157 | - protected $_nestJoin = false; |
|
157 | + protected $_nestJoin=false; |
|
158 | 158 | /** |
159 | 159 | * FOR UPDATE flag |
160 | 160 | * @var bool |
161 | 161 | */ |
162 | - protected $_forUpdate = false; |
|
162 | + protected $_forUpdate=false; |
|
163 | 163 | |
164 | 164 | /** |
165 | 165 | * LOCK IN SHARE MODE flag |
166 | 166 | * @var bool |
167 | 167 | */ |
168 | - protected $_lockInShareMode = false; |
|
168 | + protected $_lockInShareMode=false; |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Key field for Map()'ed result array |
172 | 172 | * @var string |
173 | 173 | */ |
174 | - protected $_mapKey = null; |
|
174 | + protected $_mapKey=null; |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * Variables for query execution tracing |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * Table prefix |
184 | 184 | * @var string |
185 | 185 | */ |
186 | - private $prefix = ''; |
|
186 | + private $prefix=''; |
|
187 | 187 | /** |
188 | 188 | * 字段列表 |
189 | 189 | * @var string |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * 含有表前缀的表名 |
194 | 194 | * @var string |
195 | 195 | */ |
196 | - private $tableName = ''; |
|
196 | + private $tableName=''; |
|
197 | 197 | |
198 | 198 | /** |
199 | 199 | * @param string $host |
@@ -203,30 +203,30 @@ discard block |
||
203 | 203 | * @param int $port |
204 | 204 | * @param string $charset |
205 | 205 | */ |
206 | - public function __construct($host = null, $username = null, $password = null, $db = null, $port = null, $charset = 'utf8') { |
|
207 | - $isSubQuery = false; |
|
206 | + public function __construct($host=null, $username=null, $password=null, $db=null, $port=null, $charset='utf8') { |
|
207 | + $isSubQuery=false; |
|
208 | 208 | |
209 | 209 | // if params were passed as array |
210 | 210 | if (is_array($host)) { |
211 | 211 | foreach ($host as $key => $val) { |
212 | - $$key = $val; |
|
212 | + $$key=$val; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | // if host were set as mysqli socket |
216 | 216 | if (is_object($host)) { |
217 | - $this->_mysqli = $host; |
|
217 | + $this->_mysqli=$host; |
|
218 | 218 | } else { |
219 | - $this->host = $host; |
|
219 | + $this->host=$host; |
|
220 | 220 | } |
221 | 221 | |
222 | - $this->_username = $username; |
|
223 | - $this->_password = $password; |
|
224 | - $this->db = $db; |
|
225 | - $this->port = $port; |
|
226 | - $this->charset = $charset; |
|
222 | + $this->_username=$username; |
|
223 | + $this->_password=$password; |
|
224 | + $this->db=$db; |
|
225 | + $this->port=$port; |
|
226 | + $this->charset=$charset; |
|
227 | 227 | |
228 | 228 | if ($isSubQuery) { |
229 | - $this->isSubQuery = true; |
|
229 | + $this->isSubQuery=true; |
|
230 | 230 | return; |
231 | 231 | } |
232 | 232 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $this->setPrefix($prefix); |
235 | 235 | } |
236 | 236 | |
237 | - self::$_instance = $this; |
|
237 | + self::$_instance=$this; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return MysqliDb |
259 | 259 | */ |
260 | - public static function subQuery($subQueryAlias = "") { |
|
260 | + public static function subQuery($subQueryAlias="") { |
|
261 | 261 | return new self(array('host' => $subQueryAlias, 'isSubQuery' => true)); |
262 | 262 | } |
263 | 263 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | if (!$this->_mysqli) |
272 | 272 | return; |
273 | 273 | $this->_mysqli->close(); |
274 | - $this->_mysqli = null; |
|
274 | + $this->_mysqli=null; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @return MysqliDb |
281 | 281 | */ |
282 | 282 | public function jsonBuilder() { |
283 | - $this->returnType = 'json'; |
|
283 | + $this->returnType='json'; |
|
284 | 284 | return $this; |
285 | 285 | } |
286 | 286 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return MysqliDb |
291 | 291 | */ |
292 | 292 | public function objectBuilder() { |
293 | - $this->returnType = 'object'; |
|
293 | + $this->returnType='object'; |
|
294 | 294 | return $this; |
295 | 295 | } |
296 | 296 | |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return array|null Contains the returned row from the query. |
306 | 306 | */ |
307 | - public function rawQueryOne($query, $bindParams = null) { |
|
308 | - $res = $this->rawQuery($query, $bindParams); |
|
307 | + public function rawQueryOne($query, $bindParams=null) { |
|
308 | + $res=$this->rawQuery($query, $bindParams); |
|
309 | 309 | if (is_array($res) && isset($res[0])) { |
310 | 310 | return $res[0]; |
311 | 311 | } |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @return array Contains the returned rows from the query. |
323 | 323 | */ |
324 | - public function rawQuery($query, $bindParams = null) { |
|
325 | - $params = array(''); // Create the empty 0 index |
|
326 | - $this->_query = $query; |
|
327 | - $stmt = $this->_prepareQuery(); |
|
324 | + public function rawQuery($query, $bindParams=null) { |
|
325 | + $params=array(''); // Create the empty 0 index |
|
326 | + $this->_query=$query; |
|
327 | + $stmt=$this->_prepareQuery(); |
|
328 | 328 | |
329 | 329 | if (is_array($bindParams) === true) { |
330 | 330 | foreach ($bindParams as $prop => $val) { |
331 | - $params[0] .= $this->_determineType($val); |
|
331 | + $params[0].=$this->_determineType($val); |
|
332 | 332 | array_push($params, $bindParams[$prop]); |
333 | 333 | } |
334 | 334 | |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | $stmt->execute(); |
339 | - $this->count = $stmt->affected_rows; |
|
340 | - $this->_stmtError = $stmt->error; |
|
341 | - $this->_stmtErrno = $stmt->errno; |
|
342 | - $this->_lastQuery = $this->replacePlaceHolders($this->_query, $params); |
|
343 | - $res = $this->_dynamicBindResults($stmt); |
|
339 | + $this->count=$stmt->affected_rows; |
|
340 | + $this->_stmtError=$stmt->error; |
|
341 | + $this->_stmtErrno=$stmt->errno; |
|
342 | + $this->_lastQuery=$this->replacePlaceHolders($this->_query, $params); |
|
343 | + $res=$this->_dynamicBindResults($stmt); |
|
344 | 344 | $this->reset(); |
345 | 345 | |
346 | 346 | return $res; |
@@ -353,15 +353,15 @@ discard block |
||
353 | 353 | * @return mysqli_stmt |
354 | 354 | */ |
355 | 355 | protected function _prepareQuery() { |
356 | - if (!$stmt = $this->mysqli()->prepare($this->_query)) { |
|
357 | - $msg = $this->mysqli()->error . " query: " . $this->_query; |
|
358 | - $num = $this->mysqli()->errno; |
|
356 | + if (!$stmt=$this->mysqli()->prepare($this->_query)) { |
|
357 | + $msg=$this->mysqli()->error." query: ".$this->_query; |
|
358 | + $num=$this->mysqli()->errno; |
|
359 | 359 | $this->reset(); |
360 | 360 | throw new Exception($msg, $num); |
361 | 361 | } |
362 | 362 | |
363 | 363 | if ($this->traceEnabled) { |
364 | - $this->traceStartQ = microtime(true); |
|
364 | + $this->traceStartQ=microtime(true); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | return $stmt; |
@@ -394,10 +394,10 @@ discard block |
||
394 | 394 | throw new Exception('MySQL host is not set'); |
395 | 395 | } |
396 | 396 | |
397 | - $this->_mysqli = new mysqli($this->host, $this->_username, $this->_password, $this->db, $this->port); |
|
397 | + $this->_mysqli=new mysqli($this->host, $this->_username, $this->_password, $this->db, $this->port); |
|
398 | 398 | |
399 | 399 | if ($this->_mysqli->connect_error) { |
400 | - throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno); |
|
400 | + throw new Exception('Connect Error '.$this->_mysqli->connect_errno.': '.$this->_mysqli->connect_error, $this->_mysqli->connect_errno); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | if ($this->charset) { |
@@ -412,26 +412,26 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function reset() { |
414 | 414 | if ($this->traceEnabled) { |
415 | - $this->trace[] = array($this->_lastQuery, (microtime(true) - $this->traceStartQ), $this->_traceGetCaller()); |
|
415 | + $this->trace[]=array($this->_lastQuery, (microtime(true) - $this->traceStartQ), $this->_traceGetCaller()); |
|
416 | 416 | } |
417 | 417 | |
418 | - $this->_where = array(); |
|
419 | - $this->_having = array(); |
|
420 | - $this->_join = array(); |
|
421 | - $this->_joinAnd = array(); |
|
422 | - $this->_orderBy = array(); |
|
423 | - $this->_groupBy = array(); |
|
424 | - $this->_bindParams = array(''); // Create the empty 0 index |
|
425 | - $this->_query = null; |
|
426 | - $this->_queryOptions = array(); |
|
427 | - $this->returnType = 'array'; |
|
428 | - $this->_nestJoin = false; |
|
429 | - $this->_forUpdate = false; |
|
430 | - $this->_lockInShareMode = false; |
|
431 | - $this->tableName = ''; |
|
432 | - $this->_lastInsertId = null; |
|
433 | - $this->_updateColumns = null; |
|
434 | - $this->_mapKey = null; |
|
418 | + $this->_where=array(); |
|
419 | + $this->_having=array(); |
|
420 | + $this->_join=array(); |
|
421 | + $this->_joinAnd=array(); |
|
422 | + $this->_orderBy=array(); |
|
423 | + $this->_groupBy=array(); |
|
424 | + $this->_bindParams=array(''); // Create the empty 0 index |
|
425 | + $this->_query=null; |
|
426 | + $this->_queryOptions=array(); |
|
427 | + $this->returnType='array'; |
|
428 | + $this->_nestJoin=false; |
|
429 | + $this->_forUpdate=false; |
|
430 | + $this->_lockInShareMode=false; |
|
431 | + $this->tableName=''; |
|
432 | + $this->_lastInsertId=null; |
|
433 | + $this->_updateColumns=null; |
|
434 | + $this->_mapKey=null; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -440,14 +440,14 @@ discard block |
||
440 | 440 | * @return string with information |
441 | 441 | */ |
442 | 442 | private function _traceGetCaller() { |
443 | - $dd = debug_backtrace(); |
|
444 | - $caller = next($dd); |
|
443 | + $dd=debug_backtrace(); |
|
444 | + $caller=next($dd); |
|
445 | 445 | while (isset($caller) && $caller["file"] == __FILE__) { |
446 | - $caller = next($dd); |
|
446 | + $caller=next($dd); |
|
447 | 447 | } |
448 | 448 | |
449 | - return __CLASS__ . "->" . $caller["function"] . "() >> file \"" . |
|
450 | - str_replace($this->traceStripPrefix, '', $caller["file"]) . "\" line #" . $caller["line"] . " "; |
|
449 | + return __CLASS__."->".$caller["function"]."() >> file \"". |
|
450 | + str_replace($this->traceStripPrefix, '', $caller["file"])."\" line #".$caller["line"]." "; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -495,9 +495,9 @@ discard block |
||
495 | 495 | //https://github.com/facebook/hhvm/issues/5155 |
496 | 496 | //Referenced data array is required by mysqli since PHP 5.3+ |
497 | 497 | if (strnatcmp(phpversion(), '5.3') >= 0) { |
498 | - $refs = array(); |
|
498 | + $refs=array(); |
|
499 | 499 | foreach ($arr as $key => $value) { |
500 | - $refs[$key] = &$arr[$key]; |
|
500 | + $refs[$key]=&$arr[$key]; |
|
501 | 501 | } |
502 | 502 | return $refs; |
503 | 503 | } |
@@ -513,25 +513,25 @@ discard block |
||
513 | 513 | * @return string |
514 | 514 | */ |
515 | 515 | protected function replacePlaceHolders($str, $vals) { |
516 | - $i = 1; |
|
517 | - $newStr = ""; |
|
516 | + $i=1; |
|
517 | + $newStr=""; |
|
518 | 518 | |
519 | 519 | if (empty($vals)) { |
520 | 520 | return $str; |
521 | 521 | } |
522 | 522 | |
523 | - while ($pos = strpos($str, "?")) { |
|
524 | - $val = $vals[$i++]; |
|
523 | + while ($pos=strpos($str, "?")) { |
|
524 | + $val=$vals[$i++]; |
|
525 | 525 | if (is_object($val)) { |
526 | - $val = '[object]'; |
|
526 | + $val='[object]'; |
|
527 | 527 | } |
528 | 528 | if ($val === null) { |
529 | - $val = 'NULL'; |
|
529 | + $val='NULL'; |
|
530 | 530 | } |
531 | - $newStr .= substr($str, 0, $pos) . "'" . $val . "'"; |
|
532 | - $str = substr($str, $pos + 1); |
|
531 | + $newStr.=substr($str, 0, $pos)."'".$val."'"; |
|
532 | + $str=substr($str, $pos + 1); |
|
533 | 533 | } |
534 | - $newStr .= $str; |
|
534 | + $newStr.=$str; |
|
535 | 535 | return $newStr; |
536 | 536 | } |
537 | 537 | |
@@ -544,34 +544,34 @@ discard block |
||
544 | 544 | * @return array The results of the SQL fetch. |
545 | 545 | */ |
546 | 546 | protected function _dynamicBindResults(\mysqli_stmt $stmt) { |
547 | - $parameters = array(); |
|
548 | - $results = array(); |
|
547 | + $parameters=array(); |
|
548 | + $results=array(); |
|
549 | 549 | /** |
550 | 550 | * @see http://php.net/manual/en/mysqli-result.fetch-fields.php |
551 | 551 | */ |
552 | - $mysqlLongType = 252; |
|
553 | - $shouldStoreResult = false; |
|
552 | + $mysqlLongType=252; |
|
553 | + $shouldStoreResult=false; |
|
554 | 554 | |
555 | - $meta = $stmt->result_metadata(); |
|
555 | + $meta=$stmt->result_metadata(); |
|
556 | 556 | |
557 | 557 | // if $meta is false yet sqlstate is true, there's no sql error but the query is |
558 | 558 | // most likely an update/insert/delete which doesn't produce any results |
559 | 559 | if (!$meta && $stmt->sqlstate) |
560 | 560 | return array(); |
561 | 561 | |
562 | - $row = array(); |
|
563 | - while ($field = $meta->fetch_field()) { |
|
562 | + $row=array(); |
|
563 | + while ($field=$meta->fetch_field()) { |
|
564 | 564 | if ($field->type == $mysqlLongType) { |
565 | - $shouldStoreResult = true; |
|
565 | + $shouldStoreResult=true; |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | if ($this->_nestJoin && $field->table != $this->tableName) { |
569 | - $field->table = substr($field->table, strlen($this->prefix)); |
|
570 | - $row[$field->table][$field->name] = null; |
|
571 | - $parameters[] = &$row[$field->table][$field->name]; |
|
569 | + $field->table=substr($field->table, strlen($this->prefix)); |
|
570 | + $row[$field->table][$field->name]=null; |
|
571 | + $parameters[]=&$row[$field->table][$field->name]; |
|
572 | 572 | } else { |
573 | - $row[$field->name] = null; |
|
574 | - $parameters[] = &$row[$field->name]; |
|
573 | + $row[$field->name]=null; |
|
574 | + $parameters[]=&$row[$field->name]; |
|
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
@@ -584,37 +584,37 @@ discard block |
||
584 | 584 | |
585 | 585 | call_user_func_array(array($stmt, 'bind_result'), $parameters); |
586 | 586 | |
587 | - $this->totalCount = 0; |
|
588 | - $this->count = 0; |
|
587 | + $this->totalCount=0; |
|
588 | + $this->count=0; |
|
589 | 589 | |
590 | 590 | while ($stmt->fetch()) { |
591 | 591 | if ($this->returnType == 'object') { |
592 | - $result = new stdClass (); |
|
592 | + $result=new stdClass(); |
|
593 | 593 | foreach ($row as $key => $val) { |
594 | 594 | if (is_array($val)) { |
595 | - $result->$key = new stdClass (); |
|
595 | + $result->$key=new stdClass(); |
|
596 | 596 | foreach ($val as $k => $v) { |
597 | - $result->$key->$k = $v; |
|
597 | + $result->$key->$k=$v; |
|
598 | 598 | } |
599 | 599 | } else { |
600 | - $result->$key = $val; |
|
600 | + $result->$key=$val; |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | } else { |
604 | - $result = array(); |
|
604 | + $result=array(); |
|
605 | 605 | foreach ($row as $key => $val) { |
606 | 606 | if (is_array($val)) { |
607 | 607 | foreach ($val as $k => $v) { |
608 | - $result[$key][$k] = $v; |
|
608 | + $result[$key][$k]=$v; |
|
609 | 609 | } |
610 | 610 | } else { |
611 | - $result[$key] = $val; |
|
611 | + $result[$key]=$val; |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | } |
615 | 615 | $this->count++; |
616 | 616 | if ($this->_mapKey) { |
617 | - $results[$row[$this->_mapKey]] = count($row) > 2 ? $result : end($result); |
|
617 | + $results[$row[$this->_mapKey]]=count($row) > 2 ? $result : end($result); |
|
618 | 618 | } else { |
619 | 619 | array_push($results, $result); |
620 | 620 | } |
@@ -632,9 +632,9 @@ discard block |
||
632 | 632 | } |
633 | 633 | |
634 | 634 | if (in_array('SQL_CALC_FOUND_ROWS', $this->_queryOptions)) { |
635 | - $stmt = $this->mysqli()->query('SELECT FOUND_ROWS()'); |
|
636 | - $totalCount = $stmt->fetch_row(); |
|
637 | - $this->totalCount = $totalCount[0]; |
|
635 | + $stmt=$this->mysqli()->query('SELECT FOUND_ROWS()'); |
|
636 | + $totalCount=$stmt->fetch_row(); |
|
637 | + $this->totalCount=$totalCount[0]; |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | if ($this->returnType == 'json') { |
@@ -654,21 +654,21 @@ discard block |
||
654 | 654 | * |
655 | 655 | * @return mixed Contains the returned rows from the query. |
656 | 656 | */ |
657 | - public function rawQueryValue($query, $bindParams = null) { |
|
658 | - $res = $this->rawQuery($query, $bindParams); |
|
657 | + public function rawQueryValue($query, $bindParams=null) { |
|
658 | + $res=$this->rawQuery($query, $bindParams); |
|
659 | 659 | if (!$res) { |
660 | 660 | return null; |
661 | 661 | } |
662 | 662 | |
663 | - $limit = preg_match('/limit\s+1;?$/i', $query); |
|
664 | - $key = key($res[0]); |
|
663 | + $limit=preg_match('/limit\s+1;?$/i', $query); |
|
664 | + $key=key($res[0]); |
|
665 | 665 | if (isset($res[0][$key]) && $limit == true) { |
666 | 666 | return $res[0][$key]; |
667 | 667 | } |
668 | 668 | |
669 | - $newRes = Array(); |
|
670 | - for ($i = 0; $i < $this->count; $i++) { |
|
671 | - $newRes[] = $res[$i][$key]; |
|
669 | + $newRes=Array(); |
|
670 | + for ($i=0; $i < $this->count; $i++) { |
|
671 | + $newRes[]=$res[$i][$key]; |
|
672 | 672 | } |
673 | 673 | return $newRes; |
674 | 674 | } |
@@ -681,13 +681,13 @@ discard block |
||
681 | 681 | * |
682 | 682 | * @return array Contains the returned rows from the query. |
683 | 683 | */ |
684 | - public function query($query, $numRows = null) { |
|
685 | - $this->_query = $query; |
|
686 | - $stmt = $this->_buildQuery($numRows); |
|
684 | + public function query($query, $numRows=null) { |
|
685 | + $this->_query=$query; |
|
686 | + $stmt=$this->_buildQuery($numRows); |
|
687 | 687 | $stmt->execute(); |
688 | - $this->_stmtError = $stmt->error; |
|
689 | - $this->_stmtErrno = $stmt->errno; |
|
690 | - $res = $this->_dynamicBindResults($stmt); |
|
688 | + $this->_stmtError=$stmt->error; |
|
689 | + $this->_stmtErrno=$stmt->errno; |
|
690 | + $res=$this->_dynamicBindResults($stmt); |
|
691 | 691 | $this->reset(); |
692 | 692 | |
693 | 693 | return $res; |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | * |
705 | 705 | * @return mysqli_stmt Returns the $stmt object. |
706 | 706 | */ |
707 | - protected function _buildQuery($numRows = null, $tableData = null) { |
|
707 | + protected function _buildQuery($numRows=null, $tableData=null) { |
|
708 | 708 | // $this->_buildJoinOld(); |
709 | 709 | $this->_buildJoin(); |
710 | 710 | $this->_buildInsertQuery($tableData); |
@@ -716,20 +716,20 @@ discard block |
||
716 | 716 | $this->_buildOnDuplicate($tableData); |
717 | 717 | |
718 | 718 | if ($this->_forUpdate) { |
719 | - $this->_query .= ' FOR UPDATE'; |
|
719 | + $this->_query.=' FOR UPDATE'; |
|
720 | 720 | } |
721 | 721 | if ($this->_lockInShareMode) { |
722 | - $this->_query .= ' LOCK IN SHARE MODE'; |
|
722 | + $this->_query.=' LOCK IN SHARE MODE'; |
|
723 | 723 | } |
724 | 724 | |
725 | - $this->_lastQuery = $this->replacePlaceHolders($this->_query, $this->_bindParams); |
|
725 | + $this->_lastQuery=$this->replacePlaceHolders($this->_query, $this->_bindParams); |
|
726 | 726 | |
727 | 727 | if ($this->isSubQuery) { |
728 | 728 | return; |
729 | 729 | } |
730 | 730 | |
731 | 731 | // Prepare query |
732 | - $stmt = $this->_prepareQuery(); |
|
732 | + $stmt=$this->_prepareQuery(); |
|
733 | 733 | |
734 | 734 | // Bind parameters to statement if any |
735 | 735 | if (count($this->_bindParams) > 1) { |
@@ -747,20 +747,20 @@ discard block |
||
747 | 747 | return; |
748 | 748 | |
749 | 749 | foreach ($this->_join as $data) { |
750 | - list ($joinType, $joinTable, $joinCondition) = $data; |
|
750 | + list ($joinType, $joinTable, $joinCondition)=$data; |
|
751 | 751 | |
752 | 752 | if (is_object($joinTable)) |
753 | - $joinStr = $this->_buildPair("", $joinTable); |
|
753 | + $joinStr=$this->_buildPair("", $joinTable); |
|
754 | 754 | else |
755 | - $joinStr = $joinTable; |
|
755 | + $joinStr=$joinTable; |
|
756 | 756 | |
757 | - $this->_query .= " " . $joinType . " JOIN " . $joinStr . " on " . $joinCondition; |
|
757 | + $this->_query.=" ".$joinType." JOIN ".$joinStr." on ".$joinCondition; |
|
758 | 758 | |
759 | 759 | // Add join and query |
760 | 760 | if (!empty($this->_joinAnd) && isset($this->_joinAnd[$joinStr])) { |
761 | 761 | foreach ($this->_joinAnd[$joinStr] as $join_and_cond) { |
762 | - list ($concat, $varName, $operator, $val) = $join_and_cond; |
|
763 | - $this->_query .= " " . $concat . " " . $varName; |
|
762 | + list ($concat, $varName, $operator, $val)=$join_and_cond; |
|
763 | + $this->_query.=" ".$concat." ".$varName; |
|
764 | 764 | $this->conditionToSql($operator, $val); |
765 | 765 | } |
766 | 766 | } |
@@ -780,13 +780,13 @@ discard block |
||
780 | 780 | protected function _buildPair($operator, $value) { |
781 | 781 | if (!is_object($value)) { |
782 | 782 | $this->_bindParam($value); |
783 | - return ' ' . $operator . ' ? '; |
|
783 | + return ' '.$operator.' ? '; |
|
784 | 784 | } |
785 | 785 | |
786 | - $subQuery = $value->getSubQuery(); |
|
786 | + $subQuery=$value->getSubQuery(); |
|
787 | 787 | $this->_bindParams($subQuery['params']); |
788 | 788 | |
789 | - return " " . $operator . " (" . $subQuery['query'] . ") " . $subQuery['alias']; |
|
789 | + return " ".$operator." (".$subQuery['query'].") ".$subQuery['alias']; |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @param string Variable value |
796 | 796 | */ |
797 | 797 | protected function _bindParam($value) { |
798 | - $this->_bindParams[0] .= $this->_determineType($value); |
|
798 | + $this->_bindParams[0].=$this->_determineType($value); |
|
799 | 799 | array_push($this->_bindParams, $value); |
800 | 800 | } |
801 | 801 | |
@@ -819,33 +819,33 @@ discard block |
||
819 | 819 | switch (strtolower($operator)) { |
820 | 820 | case 'not in': |
821 | 821 | case 'in': |
822 | - $comparison = ' ' . $operator . ' ('; |
|
822 | + $comparison=' '.$operator.' ('; |
|
823 | 823 | if (is_object($val)) { |
824 | - $comparison .= $this->_buildPair("", $val); |
|
824 | + $comparison.=$this->_buildPair("", $val); |
|
825 | 825 | } else { |
826 | 826 | foreach ($val as $v) { |
827 | - $comparison .= ' ?,'; |
|
827 | + $comparison.=' ?,'; |
|
828 | 828 | $this->_bindParam($v); |
829 | 829 | } |
830 | 830 | } |
831 | - $this->_query .= rtrim($comparison, ',') . ' ) '; |
|
831 | + $this->_query.=rtrim($comparison, ',').' ) '; |
|
832 | 832 | break; |
833 | 833 | case 'not between': |
834 | 834 | case 'between': |
835 | - $this->_query .= " $operator ? AND ? "; |
|
835 | + $this->_query.=" $operator ? AND ? "; |
|
836 | 836 | $this->_bindParams($val); |
837 | 837 | break; |
838 | 838 | case 'not exists': |
839 | 839 | case 'exists': |
840 | - $this->_query .= $operator . $this->_buildPair("", $val); |
|
840 | + $this->_query.=$operator.$this->_buildPair("", $val); |
|
841 | 841 | break; |
842 | 842 | default: |
843 | 843 | if (is_array($val)) |
844 | 844 | $this->_bindParams($val); |
845 | 845 | else if ($val === null) |
846 | - $this->_query .= $operator . " NULL"; |
|
846 | + $this->_query.=$operator." NULL"; |
|
847 | 847 | else if ($val != 'DBNULL' || $val == '0') |
848 | - $this->_query .= $this->_buildPair($operator, $val); |
|
848 | + $this->_query.=$this->_buildPair($operator, $val); |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | |
@@ -859,20 +859,20 @@ discard block |
||
859 | 859 | return; |
860 | 860 | } |
861 | 861 | |
862 | - $isInsert = preg_match('/^[INSERT|REPLACE]/', $this->_query); |
|
863 | - $dataColumns = array_keys($tableData); |
|
862 | + $isInsert=preg_match('/^[INSERT|REPLACE]/', $this->_query); |
|
863 | + $dataColumns=array_keys($tableData); |
|
864 | 864 | if ($isInsert) { |
865 | 865 | if (isset ($dataColumns[0])) |
866 | - $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) '; |
|
867 | - $this->_query .= ' VALUES ('; |
|
866 | + $this->_query.=' (`'.implode($dataColumns, '`, `').'`) '; |
|
867 | + $this->_query.=' VALUES ('; |
|
868 | 868 | } else { |
869 | - $this->_query .= " SET "; |
|
869 | + $this->_query.=" SET "; |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | $this->_buildDataPairs($tableData, $dataColumns, $isInsert); |
873 | 873 | |
874 | 874 | if ($isInsert) { |
875 | - $this->_query .= ')'; |
|
875 | + $this->_query.=')'; |
|
876 | 876 | } |
877 | 877 | } |
878 | 878 | |
@@ -887,54 +887,54 @@ discard block |
||
887 | 887 | */ |
888 | 888 | public function _buildDataPairs($tableData, $tableColumns, $isInsert) { |
889 | 889 | foreach ($tableColumns as $column) { |
890 | - $value = $tableData[$column]; |
|
890 | + $value=$tableData[$column]; |
|
891 | 891 | |
892 | 892 | if (!$isInsert) { |
893 | 893 | if (strpos($column, '.') === false) { |
894 | - $this->_query .= "`" . $column . "` = "; |
|
894 | + $this->_query.="`".$column."` = "; |
|
895 | 895 | } else { |
896 | - $this->_query .= str_replace('.', '.`', $column) . "` = "; |
|
896 | + $this->_query.=str_replace('.', '.`', $column)."` = "; |
|
897 | 897 | } |
898 | 898 | } |
899 | 899 | |
900 | 900 | // Subquery value |
901 | 901 | if ($value instanceof MysqliDb) { |
902 | - $this->_query .= $this->_buildPair("", $value) . ", "; |
|
902 | + $this->_query.=$this->_buildPair("", $value).", "; |
|
903 | 903 | continue; |
904 | 904 | } |
905 | 905 | |
906 | 906 | // Simple value |
907 | 907 | if (!is_array($value)) { |
908 | 908 | $this->_bindParam($value); |
909 | - $this->_query .= '?, '; |
|
909 | + $this->_query.='?, '; |
|
910 | 910 | continue; |
911 | 911 | } |
912 | 912 | |
913 | 913 | // Function value |
914 | - $key = key($value); |
|
915 | - $val = $value[$key]; |
|
914 | + $key=key($value); |
|
915 | + $val=$value[$key]; |
|
916 | 916 | switch ($key) { |
917 | 917 | case '[I]': |
918 | - $this->_query .= $column . $val . ", "; |
|
918 | + $this->_query.=$column.$val.", "; |
|
919 | 919 | break; |
920 | 920 | case '[F]': |
921 | - $this->_query .= $val[0] . ", "; |
|
921 | + $this->_query.=$val[0].", "; |
|
922 | 922 | if (!empty($val[1])) { |
923 | 923 | $this->_bindParams($val[1]); |
924 | 924 | } |
925 | 925 | break; |
926 | 926 | case '[N]': |
927 | 927 | if ($val == null) { |
928 | - $this->_query .= "!" . $column . ", "; |
|
928 | + $this->_query.="!".$column.", "; |
|
929 | 929 | } else { |
930 | - $this->_query .= "!" . $val . ", "; |
|
930 | + $this->_query.="!".$val.", "; |
|
931 | 931 | } |
932 | 932 | break; |
933 | 933 | default: |
934 | 934 | throw new Exception("Wrong operation"); |
935 | 935 | } |
936 | 936 | } |
937 | - $this->_query = rtrim($this->_query, ', '); |
|
937 | + $this->_query=rtrim($this->_query, ', '); |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | /** |
@@ -949,42 +949,42 @@ discard block |
||
949 | 949 | } |
950 | 950 | |
951 | 951 | //Prepare the where portion of the query |
952 | - $this->_query .= ' ' . $operator; |
|
952 | + $this->_query.=' '.$operator; |
|
953 | 953 | |
954 | 954 | foreach ($conditions as $cond) { |
955 | - list ($concat, $varName, $operator, $val) = $cond; |
|
956 | - $this->_query .= " " . $concat . " " . $varName; |
|
955 | + list ($concat, $varName, $operator, $val)=$cond; |
|
956 | + $this->_query.=" ".$concat." ".$varName; |
|
957 | 957 | |
958 | 958 | switch (strtolower($operator)) { |
959 | 959 | case 'not in': |
960 | 960 | case 'in': |
961 | - $comparison = ' ' . $operator . ' ('; |
|
961 | + $comparison=' '.$operator.' ('; |
|
962 | 962 | if (is_object($val)) { |
963 | - $comparison .= $this->_buildPair("", $val); |
|
963 | + $comparison.=$this->_buildPair("", $val); |
|
964 | 964 | } else { |
965 | 965 | foreach ($val as $v) { |
966 | - $comparison .= ' ?,'; |
|
966 | + $comparison.=' ?,'; |
|
967 | 967 | $this->_bindParam($v); |
968 | 968 | } |
969 | 969 | } |
970 | - $this->_query .= rtrim($comparison, ',') . ' ) '; |
|
970 | + $this->_query.=rtrim($comparison, ',').' ) '; |
|
971 | 971 | break; |
972 | 972 | case 'not between': |
973 | 973 | case 'between': |
974 | - $this->_query .= " $operator ? AND ? "; |
|
974 | + $this->_query.=" $operator ? AND ? "; |
|
975 | 975 | $this->_bindParams($val); |
976 | 976 | break; |
977 | 977 | case 'not exists': |
978 | 978 | case 'exists': |
979 | - $this->_query .= $operator . $this->_buildPair("", $val); |
|
979 | + $this->_query.=$operator.$this->_buildPair("", $val); |
|
980 | 980 | break; |
981 | 981 | default: |
982 | 982 | if (is_array($val)) { |
983 | 983 | $this->_bindParams($val); |
984 | 984 | } elseif ($val === null) { |
985 | - $this->_query .= ' ' . $operator . " NULL"; |
|
985 | + $this->_query.=' '.$operator." NULL"; |
|
986 | 986 | } elseif ($val != 'DBNULL' || $val == '0') { |
987 | - $this->_query .= $this->_buildPair($operator, $val); |
|
987 | + $this->_query.=$this->_buildPair($operator, $val); |
|
988 | 988 | } |
989 | 989 | } |
990 | 990 | } |
@@ -1000,13 +1000,13 @@ discard block |
||
1000 | 1000 | return; |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - $this->_query .= " GROUP BY "; |
|
1003 | + $this->_query.=" GROUP BY "; |
|
1004 | 1004 | |
1005 | 1005 | foreach ($this->_groupBy as $key => $value) { |
1006 | - $this->_query .= $value . ", "; |
|
1006 | + $this->_query.=$value.", "; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | - $this->_query = rtrim($this->_query, ', ') . " "; |
|
1009 | + $this->_query=rtrim($this->_query, ', ')." "; |
|
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | /** |
@@ -1019,16 +1019,16 @@ discard block |
||
1019 | 1019 | return; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $this->_query .= " ORDER BY "; |
|
1022 | + $this->_query.=" ORDER BY "; |
|
1023 | 1023 | foreach ($this->_orderBy as $prop => $value) { |
1024 | 1024 | if (strtolower(str_replace(" ", "", $prop)) == 'rand()') { |
1025 | - $this->_query .= "rand(), "; |
|
1025 | + $this->_query.="rand(), "; |
|
1026 | 1026 | } else { |
1027 | - $this->_query .= $prop . " " . $value . ", "; |
|
1027 | + $this->_query.=$prop." ".$value.", "; |
|
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - $this->_query = rtrim($this->_query, ', ') . " "; |
|
1031 | + $this->_query=rtrim($this->_query, ', ')." "; |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1045,9 +1045,9 @@ discard block |
||
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | if (is_array($numRows)) { |
1048 | - $this->_query .= ' LIMIT ' . (int)$numRows[0] . ', ' . (int)$numRows[1]; |
|
1048 | + $this->_query.=' LIMIT '.(int) $numRows[0].', '.(int) $numRows[1]; |
|
1049 | 1049 | } else { |
1050 | - $this->_query .= ' LIMIT ' . (int)$numRows; |
|
1050 | + $this->_query.=' LIMIT '.(int) $numRows; |
|
1051 | 1051 | } |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1058,18 +1058,18 @@ discard block |
||
1058 | 1058 | */ |
1059 | 1059 | protected function _buildOnDuplicate($tableData) { |
1060 | 1060 | if (is_array($this->_updateColumns) && !empty($this->_updateColumns)) { |
1061 | - $this->_query .= " ON DUPLICATE KEY UPDATE "; |
|
1061 | + $this->_query.=" ON DUPLICATE KEY UPDATE "; |
|
1062 | 1062 | if ($this->_lastInsertId) { |
1063 | - $this->_query .= $this->_lastInsertId . "=LAST_INSERT_ID (" . $this->_lastInsertId . "), "; |
|
1063 | + $this->_query.=$this->_lastInsertId."=LAST_INSERT_ID (".$this->_lastInsertId."), "; |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | foreach ($this->_updateColumns as $key => $val) { |
1067 | 1067 | // skip all params without a value |
1068 | 1068 | if (is_numeric($key)) { |
1069 | - $this->_updateColumns[$val] = ''; |
|
1069 | + $this->_updateColumns[$val]=''; |
|
1070 | 1070 | unset($this->_updateColumns[$key]); |
1071 | 1071 | } else { |
1072 | - $tableData[$key] = $val; |
|
1072 | + $tableData[$key]=$val; |
|
1073 | 1073 | } |
1074 | 1074 | } |
1075 | 1075 | $this->_buildDataPairs($tableData, array_keys($this->_updateColumns), false); |
@@ -1085,10 +1085,10 @@ discard block |
||
1085 | 1085 | * |
1086 | 1086 | * @return bool|array Boolean indicating the insertion failed (false), else return id-array ([int]) |
1087 | 1087 | */ |
1088 | - public function insertMulti($tableName, array $multiInsertData, array $dataKeys = null) { |
|
1088 | + public function insertMulti($tableName, array $multiInsertData, array $dataKeys=null) { |
|
1089 | 1089 | // only auto-commit our inserts, if no transaction is currently running |
1090 | - $autoCommit = (isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true); |
|
1091 | - $ids = array(); |
|
1090 | + $autoCommit=(isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true); |
|
1091 | + $ids=array(); |
|
1092 | 1092 | |
1093 | 1093 | if ($autoCommit) { |
1094 | 1094 | $this->startTransaction(); |
@@ -1097,17 +1097,17 @@ discard block |
||
1097 | 1097 | foreach ($multiInsertData as $insertData) { |
1098 | 1098 | if ($dataKeys !== null) { |
1099 | 1099 | // apply column-names if given, else assume they're already given in the data |
1100 | - $insertData = array_combine($dataKeys, $insertData); |
|
1100 | + $insertData=array_combine($dataKeys, $insertData); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | - $id = $this->insert($tableName, $insertData); |
|
1103 | + $id=$this->insert($tableName, $insertData); |
|
1104 | 1104 | if (!$id) { |
1105 | 1105 | if ($autoCommit) { |
1106 | 1106 | $this->rollback(); |
1107 | 1107 | } |
1108 | 1108 | return false; |
1109 | 1109 | } |
1110 | - $ids[] = $id; |
|
1110 | + $ids[]=$id; |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | if ($autoCommit) { |
@@ -1125,7 +1125,7 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public function startTransaction() { |
1127 | 1127 | $this->mysqli()->autocommit(false); |
1128 | - $this->_transaction_in_progress = true; |
|
1128 | + $this->_transaction_in_progress=true; |
|
1129 | 1129 | register_shutdown_function(array($this, "_transaction_status_check")); |
1130 | 1130 | } |
1131 | 1131 | |
@@ -1155,14 +1155,14 @@ discard block |
||
1155 | 1155 | return; |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - $this->_query = $operation . " " . implode(' ', $this->_queryOptions) . " INTO " . $this->prefix . $tableName; |
|
1159 | - $stmt = $this->_buildQuery(null, $insertData); |
|
1160 | - $status = $stmt->execute(); |
|
1161 | - $this->_stmtError = $stmt->error; |
|
1162 | - $this->_stmtErrno = $stmt->errno; |
|
1163 | - $haveOnDuplicate = !empty ($this->_updateColumns); |
|
1158 | + $this->_query=$operation." ".implode(' ', $this->_queryOptions)." INTO ".$this->prefix.$tableName; |
|
1159 | + $stmt=$this->_buildQuery(null, $insertData); |
|
1160 | + $status=$stmt->execute(); |
|
1161 | + $this->_stmtError=$stmt->error; |
|
1162 | + $this->_stmtErrno=$stmt->errno; |
|
1163 | + $haveOnDuplicate=!empty ($this->_updateColumns); |
|
1164 | 1164 | $this->reset(); |
1165 | - $this->count = $stmt->affected_rows; |
|
1165 | + $this->count=$stmt->affected_rows; |
|
1166 | 1166 | |
1167 | 1167 | if ($stmt->affected_rows < 1) { |
1168 | 1168 | // in case of onDuplicate() usage, if no rows were inserted |
@@ -1186,8 +1186,8 @@ discard block |
||
1186 | 1186 | * @uses mysqli->autocommit(true); |
1187 | 1187 | */ |
1188 | 1188 | public function rollback() { |
1189 | - $result = $this->mysqli()->rollback(); |
|
1190 | - $this->_transaction_in_progress = false; |
|
1189 | + $result=$this->mysqli()->rollback(); |
|
1190 | + $this->_transaction_in_progress=false; |
|
1191 | 1191 | $this->mysqli()->autocommit(true); |
1192 | 1192 | return $result; |
1193 | 1193 | } |
@@ -1199,8 +1199,8 @@ discard block |
||
1199 | 1199 | * @uses mysqli->autocommit(true); |
1200 | 1200 | */ |
1201 | 1201 | public function commit() { |
1202 | - $result = $this->mysqli()->commit(); |
|
1203 | - $this->_transaction_in_progress = false; |
|
1202 | + $result=$this->mysqli()->commit(); |
|
1203 | + $this->_transaction_in_progress=false; |
|
1204 | 1204 | $this->mysqli()->autocommit(true); |
1205 | 1205 | return $result; |
1206 | 1206 | } |
@@ -1226,8 +1226,8 @@ discard block |
||
1226 | 1226 | * |
1227 | 1227 | * @return array Contains the returned rows from the select query. |
1228 | 1228 | */ |
1229 | - public function getOne($tableName, $columns = '*') { |
|
1230 | - $res = $this->get($tableName, 1, $columns); |
|
1229 | + public function getOne($tableName, $columns='*') { |
|
1230 | + $res=$this->get($tableName, 1, $columns); |
|
1231 | 1231 | |
1232 | 1232 | if ($res instanceof MysqliDb) { |
1233 | 1233 | return $res; |
@@ -1250,31 +1250,31 @@ discard block |
||
1250 | 1250 | * |
1251 | 1251 | * @return array Contains the returned rows from the select query. |
1252 | 1252 | */ |
1253 | - public function get($tableName, $numRows = null, $columns = '*') { |
|
1253 | + public function get($tableName, $numRows=null, $columns='*') { |
|
1254 | 1254 | if (empty($columns)) { |
1255 | - $columns = '*'; |
|
1255 | + $columns='*'; |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | - $column = is_array($columns) ? implode(', ', $columns) : $columns; |
|
1258 | + $column=is_array($columns) ? implode(', ', $columns) : $columns; |
|
1259 | 1259 | |
1260 | 1260 | if (strpos($tableName, '.') === false) { |
1261 | - $this->tableName = $this->prefix . $tableName; |
|
1261 | + $this->tableName=$this->prefix.$tableName; |
|
1262 | 1262 | } else { |
1263 | - $this->tableName = $tableName; |
|
1263 | + $this->tableName=$tableName; |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | - $this->_query = 'SELECT ' . implode(' ', $this->_queryOptions) . ' ' . |
|
1267 | - $column . " FROM " . $this->tableName; |
|
1268 | - $stmt = $this->_buildQuery($numRows); |
|
1266 | + $this->_query='SELECT '.implode(' ', $this->_queryOptions).' '. |
|
1267 | + $column." FROM ".$this->tableName; |
|
1268 | + $stmt=$this->_buildQuery($numRows); |
|
1269 | 1269 | |
1270 | 1270 | if ($this->isSubQuery) { |
1271 | 1271 | return $this; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | $stmt->execute(); |
1275 | - $this->_stmtError = $stmt->error; |
|
1276 | - $this->_stmtErrno = $stmt->errno; |
|
1277 | - $res = $this->_dynamicBindResults($stmt); |
|
1275 | + $this->_stmtError=$stmt->error; |
|
1276 | + $this->_stmtErrno=$stmt->errno; |
|
1277 | + $res=$this->_dynamicBindResults($stmt); |
|
1278 | 1278 | $this->reset(); |
1279 | 1279 | |
1280 | 1280 | return $res; |
@@ -1288,19 +1288,19 @@ discard block |
||
1288 | 1288 | * |
1289 | 1289 | * @return bool |
1290 | 1290 | */ |
1291 | - public function update($tableData, $numRows = null) { |
|
1291 | + public function update($tableData, $numRows=null) { |
|
1292 | 1292 | if ($this->isSubQuery) { |
1293 | 1293 | return; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - $this->_query = "UPDATE " . $this->tableName; |
|
1296 | + $this->_query="UPDATE ".$this->tableName; |
|
1297 | 1297 | |
1298 | - $stmt = $this->_buildQuery($numRows, $tableData); |
|
1299 | - $status = $stmt->execute(); |
|
1298 | + $stmt=$this->_buildQuery($numRows, $tableData); |
|
1299 | + $status=$stmt->execute(); |
|
1300 | 1300 | $this->reset(); |
1301 | - $this->_stmtError = $stmt->error; |
|
1302 | - $this->_stmtErrno = $stmt->errno; |
|
1303 | - $this->count = $stmt->affected_rows; |
|
1301 | + $this->_stmtError=$stmt->error; |
|
1302 | + $this->_stmtErrno=$stmt->errno; |
|
1303 | + $this->count=$stmt->affected_rows; |
|
1304 | 1304 | |
1305 | 1305 | return $status; |
1306 | 1306 | } |
@@ -1313,26 +1313,26 @@ discard block |
||
1313 | 1313 | * |
1314 | 1314 | * @return bool Indicates success. 0 or 1. |
1315 | 1315 | */ |
1316 | - public function delete($numRows = null) { |
|
1316 | + public function delete($numRows=null) { |
|
1317 | 1317 | if ($this->isSubQuery) { |
1318 | 1318 | return; |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - $table = $this->tableName; |
|
1321 | + $table=$this->tableName; |
|
1322 | 1322 | |
1323 | 1323 | if (count($this->_join)) { |
1324 | - $this->_query = "DELETE " . preg_replace('/.* (.*)/', '$1', $table) . " FROM " . $table; |
|
1324 | + $this->_query="DELETE ".preg_replace('/.* (.*)/', '$1', $table)." FROM ".$table; |
|
1325 | 1325 | } else { |
1326 | - $this->_query = "DELETE FROM " . $table; |
|
1326 | + $this->_query="DELETE FROM ".$table; |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | - $stmt = $this->_buildQuery($numRows); |
|
1329 | + $stmt=$this->_buildQuery($numRows); |
|
1330 | 1330 | $stmt->execute(); |
1331 | - $this->_stmtError = $stmt->error; |
|
1332 | - $this->_stmtErrno = $stmt->errno; |
|
1331 | + $this->_stmtError=$stmt->error; |
|
1332 | + $this->_stmtErrno=$stmt->errno; |
|
1333 | 1333 | $this->reset(); |
1334 | 1334 | |
1335 | - return ($stmt->affected_rows > -1); // affected_rows returns 0 if nothing matched where statement, or required updating, -1 if error |
|
1335 | + return ($stmt->affected_rows > -1); // affected_rows returns 0 if nothing matched where statement, or required updating, -1 if error |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | /** |
@@ -1344,9 +1344,9 @@ discard block |
||
1344 | 1344 | * |
1345 | 1345 | * @return MysqliDb |
1346 | 1346 | */ |
1347 | - public function onDuplicate($updateColumns, $lastInsertId = null) { |
|
1348 | - $this->_lastInsertId = $lastInsertId; |
|
1349 | - $this->_updateColumns = $updateColumns; |
|
1347 | + public function onDuplicate($updateColumns, $lastInsertId=null) { |
|
1348 | + $this->_lastInsertId=$lastInsertId; |
|
1349 | + $this->_updateColumns=$updateColumns; |
|
1350 | 1350 | return $this; |
1351 | 1351 | } |
1352 | 1352 | |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | * |
1362 | 1362 | * @return MysqliDb |
1363 | 1363 | */ |
1364 | - public function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') { |
|
1364 | + public function orWhere($whereProp, $whereValue='DBNULL', $operator='=') { |
|
1365 | 1365 | return $this->where($whereProp, $whereValue, $operator, 'OR'); |
1366 | 1366 | } |
1367 | 1367 | |
@@ -1377,18 +1377,18 @@ discard block |
||
1377 | 1377 | * |
1378 | 1378 | * @return MysqliDb |
1379 | 1379 | */ |
1380 | - public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
|
1380 | + public function where($whereProp, $whereValue='DBNULL', $operator='=', $cond='AND') { |
|
1381 | 1381 | // forkaround for an old operation api |
1382 | - if (is_array($whereValue) && ($key = key($whereValue)) != "0") { |
|
1383 | - $operator = $key; |
|
1384 | - $whereValue = $whereValue[$key]; |
|
1382 | + if (is_array($whereValue) && ($key=key($whereValue)) != "0") { |
|
1383 | + $operator=$key; |
|
1384 | + $whereValue=$whereValue[$key]; |
|
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | if (count($this->_where) == 0) { |
1388 | - $cond = ''; |
|
1388 | + $cond=''; |
|
1389 | 1389 | } |
1390 | 1390 | |
1391 | - $this->_where[] = array($cond, $whereProp, $operator, $whereValue); |
|
1391 | + $this->_where[]=array($cond, $whereProp, $operator, $whereValue); |
|
1392 | 1392 | return $this; |
1393 | 1393 | } |
1394 | 1394 | |
@@ -1403,7 +1403,7 @@ discard block |
||
1403 | 1403 | * |
1404 | 1404 | * @return MysqliDb |
1405 | 1405 | */ |
1406 | - public function orHaving($havingProp, $havingValue = null, $operator = null) { |
|
1406 | + public function orHaving($havingProp, $havingValue=null, $operator=null) { |
|
1407 | 1407 | return $this->having($havingProp, $havingValue, $operator, 'OR'); |
1408 | 1408 | } |
1409 | 1409 | |
@@ -1419,18 +1419,18 @@ discard block |
||
1419 | 1419 | * @return MysqliDb |
1420 | 1420 | */ |
1421 | 1421 | |
1422 | - public function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
|
1422 | + public function having($havingProp, $havingValue='DBNULL', $operator='=', $cond='AND') { |
|
1423 | 1423 | // forkaround for an old operation api |
1424 | - if (is_array($havingValue) && ($key = key($havingValue)) != "0") { |
|
1425 | - $operator = $key; |
|
1426 | - $havingValue = $havingValue[$key]; |
|
1424 | + if (is_array($havingValue) && ($key=key($havingValue)) != "0") { |
|
1425 | + $operator=$key; |
|
1426 | + $havingValue=$havingValue[$key]; |
|
1427 | 1427 | } |
1428 | 1428 | |
1429 | 1429 | if (count($this->_having) == 0) { |
1430 | - $cond = ''; |
|
1430 | + $cond=''; |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | - $this->_having[] = array($cond, $havingProp, $operator, $havingValue); |
|
1433 | + $this->_having[]=array($cond, $havingProp, $operator, $havingValue); |
|
1434 | 1434 | return $this; |
1435 | 1435 | } |
1436 | 1436 | |
@@ -1446,19 +1446,19 @@ discard block |
||
1446 | 1446 | * @throws Exception |
1447 | 1447 | * @return MysqliDb |
1448 | 1448 | */ |
1449 | - public function join($joinTable, $joinCondition, $joinType = '') { |
|
1450 | - $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); |
|
1451 | - $joinType = strtoupper(trim($joinType)); |
|
1449 | + public function join($joinTable, $joinCondition, $joinType='') { |
|
1450 | + $allowedTypes=array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); |
|
1451 | + $joinType=strtoupper(trim($joinType)); |
|
1452 | 1452 | |
1453 | 1453 | if ($joinType && !in_array($joinType, $allowedTypes)) { |
1454 | - throw new Exception('Wrong JOIN type: ' . $joinType); |
|
1454 | + throw new Exception('Wrong JOIN type: '.$joinType); |
|
1455 | 1455 | } |
1456 | 1456 | |
1457 | 1457 | if (!is_object($joinTable)) { |
1458 | - $joinTable = $this->prefix . $joinTable; |
|
1458 | + $joinTable=$this->prefix.$joinTable; |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | - $this->_join[] = Array($joinType, $joinTable, $joinCondition); |
|
1461 | + $this->_join[]=Array($joinType, $joinTable, $joinCondition); |
|
1462 | 1462 | |
1463 | 1463 | return $this; |
1464 | 1464 | } |
@@ -1472,55 +1472,55 @@ discard block |
||
1472 | 1472 | * @param string $importSettings An Array defining the import settings as described in the README.md |
1473 | 1473 | * @return boolean |
1474 | 1474 | */ |
1475 | - public function loadData($importTable, $importFile, $importSettings = null) { |
|
1475 | + public function loadData($importTable, $importFile, $importSettings=null) { |
|
1476 | 1476 | // We have to check if the file exists |
1477 | 1477 | if (!file_exists($importFile)) { |
1478 | 1478 | // Throw an exception |
1479 | - throw new Exception("importCSV -> importFile " . $importFile . " does not exists!"); |
|
1479 | + throw new Exception("importCSV -> importFile ".$importFile." does not exists!"); |
|
1480 | 1480 | return; |
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | // Define the default values |
1484 | 1484 | // We will merge it later |
1485 | - $settings = Array("fieldChar" => ';', "lineChar" => PHP_EOL, "linesToIgnore" => 1); |
|
1485 | + $settings=Array("fieldChar" => ';', "lineChar" => PHP_EOL, "linesToIgnore" => 1); |
|
1486 | 1486 | |
1487 | 1487 | // Check the import settings |
1488 | 1488 | if (gettype($importSettings) == "array") { |
1489 | 1489 | // Merge the default array with the custom one |
1490 | - $settings = array_merge($settings, $importSettings); |
|
1490 | + $settings=array_merge($settings, $importSettings); |
|
1491 | 1491 | } |
1492 | 1492 | |
1493 | 1493 | // Add the prefix to the import table |
1494 | - $table = $this->prefix . $importTable; |
|
1494 | + $table=$this->prefix.$importTable; |
|
1495 | 1495 | |
1496 | 1496 | // Add 1 more slash to every slash so maria will interpret it as a path |
1497 | - $importFile = str_replace("\\", "\\\\", $importFile); |
|
1497 | + $importFile=str_replace("\\", "\\\\", $importFile); |
|
1498 | 1498 | |
1499 | 1499 | // Build SQL Syntax |
1500 | - $sqlSyntax = sprintf('LOAD DATA INFILE \'%s\' INTO TABLE %s', |
|
1500 | + $sqlSyntax=sprintf('LOAD DATA INFILE \'%s\' INTO TABLE %s', |
|
1501 | 1501 | $importFile, $table); |
1502 | 1502 | |
1503 | 1503 | // FIELDS |
1504 | - $sqlSyntax .= sprintf(' FIELDS TERMINATED BY \'%s\'', $settings["fieldChar"]); |
|
1504 | + $sqlSyntax.=sprintf(' FIELDS TERMINATED BY \'%s\'', $settings["fieldChar"]); |
|
1505 | 1505 | if (isset($settings["fieldEnclosure"])) { |
1506 | - $sqlSyntax .= sprintf(' ENCLOSED BY \'%s\'', $settings["fieldEnclosure"]); |
|
1506 | + $sqlSyntax.=sprintf(' ENCLOSED BY \'%s\'', $settings["fieldEnclosure"]); |
|
1507 | 1507 | } |
1508 | 1508 | |
1509 | 1509 | // LINES |
1510 | - $sqlSyntax .= sprintf(' LINES TERMINATED BY \'%s\'', $settings["lineChar"]); |
|
1510 | + $sqlSyntax.=sprintf(' LINES TERMINATED BY \'%s\'', $settings["lineChar"]); |
|
1511 | 1511 | if (isset($settings["lineStarting"])) { |
1512 | - $sqlSyntax .= sprintf(' STARTING BY \'%s\'', $settings["lineStarting"]); |
|
1512 | + $sqlSyntax.=sprintf(' STARTING BY \'%s\'', $settings["lineStarting"]); |
|
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | // IGNORE LINES |
1516 | - $sqlSyntax .= sprintf(' IGNORE %d LINES', $settings["linesToIgnore"]); |
|
1516 | + $sqlSyntax.=sprintf(' IGNORE %d LINES', $settings["linesToIgnore"]); |
|
1517 | 1517 | |
1518 | 1518 | // Exceute the query unprepared because LOAD DATA only works with unprepared statements. |
1519 | - $result = $this->queryUnprepared($sqlSyntax); |
|
1519 | + $result=$this->queryUnprepared($sqlSyntax); |
|
1520 | 1520 | |
1521 | 1521 | // Are there rows modified? |
1522 | 1522 | // Let the user know if the import failed / succeeded |
1523 | - return (bool)$result; |
|
1523 | + return (bool) $result; |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | /** |
@@ -1533,11 +1533,11 @@ discard block |
||
1533 | 1533 | */ |
1534 | 1534 | private function queryUnprepared($query) { |
1535 | 1535 | // Execute query |
1536 | - $stmt = $this->mysqli()->query($query); |
|
1536 | + $stmt=$this->mysqli()->query($query); |
|
1537 | 1537 | |
1538 | 1538 | // Failed? |
1539 | 1539 | if (!$stmt) { |
1540 | - throw new Exception("Unprepared Query Failed, ERRNO: " . $this->mysqli()->errno . " (" . $this->mysqli()->error . ")", $this->mysqli()->errno); |
|
1540 | + throw new Exception("Unprepared Query Failed, ERRNO: ".$this->mysqli()->errno." (".$this->mysqli()->error.")", $this->mysqli()->errno); |
|
1541 | 1541 | }; |
1542 | 1542 | |
1543 | 1543 | // return stmt for future use |
@@ -1555,7 +1555,7 @@ discard block |
||
1555 | 1555 | * |
1556 | 1556 | * @return boolean Returns true if the import succeeded, false if it failed. |
1557 | 1557 | */ |
1558 | - public function loadXml($importTable, $importFile, $importSettings = null) { |
|
1558 | + public function loadXml($importTable, $importFile, $importSettings=null) { |
|
1559 | 1559 | // We have to check if the file exists |
1560 | 1560 | if (!file_exists($importFile)) { |
1561 | 1561 | // Does not exists |
@@ -1564,37 +1564,37 @@ discard block |
||
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | // Create default values |
1567 | - $settings = Array("linesToIgnore" => 0); |
|
1567 | + $settings=Array("linesToIgnore" => 0); |
|
1568 | 1568 | |
1569 | 1569 | // Check the import settings |
1570 | 1570 | if (gettype($importSettings) == "array") { |
1571 | - $settings = array_merge($settings, $importSettings); |
|
1571 | + $settings=array_merge($settings, $importSettings); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | // Add the prefix to the import table |
1575 | - $table = $this->prefix . $importTable; |
|
1575 | + $table=$this->prefix.$importTable; |
|
1576 | 1576 | |
1577 | 1577 | // Add 1 more slash to every slash so maria will interpret it as a path |
1578 | - $importFile = str_replace("\\", "\\\\", $importFile); |
|
1578 | + $importFile=str_replace("\\", "\\\\", $importFile); |
|
1579 | 1579 | |
1580 | 1580 | // Build SQL Syntax |
1581 | - $sqlSyntax = sprintf('LOAD XML INFILE \'%s\' INTO TABLE %s', |
|
1581 | + $sqlSyntax=sprintf('LOAD XML INFILE \'%s\' INTO TABLE %s', |
|
1582 | 1582 | $importFile, $table); |
1583 | 1583 | |
1584 | 1584 | // FIELDS |
1585 | 1585 | if (isset($settings["rowTag"])) { |
1586 | - $sqlSyntax .= sprintf(' ROWS IDENTIFIED BY \'%s\'', $settings["rowTag"]); |
|
1586 | + $sqlSyntax.=sprintf(' ROWS IDENTIFIED BY \'%s\'', $settings["rowTag"]); |
|
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | // IGNORE LINES |
1590 | - $sqlSyntax .= sprintf(' IGNORE %d LINES', $settings["linesToIgnore"]); |
|
1590 | + $sqlSyntax.=sprintf(' IGNORE %d LINES', $settings["linesToIgnore"]); |
|
1591 | 1591 | |
1592 | 1592 | // Exceute the query unprepared because LOAD XML only works with unprepared statements. |
1593 | - $result = $this->queryUnprepared($sqlSyntax); |
|
1593 | + $result=$this->queryUnprepared($sqlSyntax); |
|
1594 | 1594 | |
1595 | 1595 | // Are there rows modified? |
1596 | 1596 | // Let the user know if the import failed / succeeded |
1597 | - return (bool)$result; |
|
1597 | + return (bool) $result; |
|
1598 | 1598 | } |
1599 | 1599 | |
1600 | 1600 | /** |
@@ -1609,30 +1609,30 @@ discard block |
||
1609 | 1609 | * @throws Exception |
1610 | 1610 | * @return MysqliDb |
1611 | 1611 | */ |
1612 | - public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields = null) { |
|
1613 | - $allowedDirection = Array("ASC", "DESC"); |
|
1614 | - $orderbyDirection = strtoupper(trim($orderbyDirection)); |
|
1615 | - $orderByField = preg_replace("/[^-a-z0-9\.\(\),_`\*\'\"]+/i", '', $orderByField); |
|
1612 | + public function orderBy($orderByField, $orderbyDirection="DESC", $customFields=null) { |
|
1613 | + $allowedDirection=Array("ASC", "DESC"); |
|
1614 | + $orderbyDirection=strtoupper(trim($orderbyDirection)); |
|
1615 | + $orderByField=preg_replace("/[^-a-z0-9\.\(\),_`\*\'\"]+/i", '', $orderByField); |
|
1616 | 1616 | |
1617 | 1617 | // Add table prefix to orderByField if needed. |
1618 | 1618 | //FIXME: We are adding prefix only if table is enclosed into `` to distinguish aliases |
1619 | 1619 | // from table names |
1620 | - $orderByField = preg_replace('/(\`)([`a-zA-Z0-9_]*\.)/', '\1' . $this->prefix . '\2', $orderByField); |
|
1620 | + $orderByField=preg_replace('/(\`)([`a-zA-Z0-9_]*\.)/', '\1'.$this->prefix.'\2', $orderByField); |
|
1621 | 1621 | |
1622 | 1622 | |
1623 | 1623 | if (empty($orderbyDirection) || !in_array($orderbyDirection, $allowedDirection)) { |
1624 | - throw new Exception('Wrong order direction: ' . $orderbyDirection); |
|
1624 | + throw new Exception('Wrong order direction: '.$orderbyDirection); |
|
1625 | 1625 | } |
1626 | 1626 | |
1627 | 1627 | if (is_array($customFields)) { |
1628 | 1628 | foreach ($customFields as $key => $value) { |
1629 | - $customFields[$key] = preg_replace("/[^-a-z0-9\.\(\),_` ]+/i", '', $value); |
|
1629 | + $customFields[$key]=preg_replace("/[^-a-z0-9\.\(\),_` ]+/i", '', $value); |
|
1630 | 1630 | } |
1631 | 1631 | |
1632 | - $orderByField = 'FIELD (' . $orderByField . ', "' . implode('","', $customFields) . '")'; |
|
1632 | + $orderByField='FIELD ('.$orderByField.', "'.implode('","', $customFields).'")'; |
|
1633 | 1633 | } |
1634 | 1634 | |
1635 | - $this->_orderBy[$orderByField] = $orderbyDirection; |
|
1635 | + $this->_orderBy[$orderByField]=$orderbyDirection; |
|
1636 | 1636 | return $this; |
1637 | 1637 | } |
1638 | 1638 | |
@@ -1646,9 +1646,9 @@ discard block |
||
1646 | 1646 | * @return MysqliDb |
1647 | 1647 | */ |
1648 | 1648 | public function groupBy($groupByField) { |
1649 | - $groupByField = preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField); |
|
1649 | + $groupByField=preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField); |
|
1650 | 1650 | |
1651 | - $this->_groupBy[] = $groupByField; |
|
1651 | + $this->_groupBy[]=$groupByField; |
|
1652 | 1652 | return $this; |
1653 | 1653 | } |
1654 | 1654 | |
@@ -1667,7 +1667,7 @@ discard block |
||
1667 | 1667 | // Is it READ or WRITE? |
1668 | 1668 | case "READ" || "WRITE": |
1669 | 1669 | // Succeed |
1670 | - $this->_tableLockMethod = $method; |
|
1670 | + $this->_tableLockMethod=$method; |
|
1671 | 1671 | break; |
1672 | 1672 | default: |
1673 | 1673 | // Else throw an exception |
@@ -1688,7 +1688,7 @@ discard block |
||
1688 | 1688 | */ |
1689 | 1689 | public function lock($table) { |
1690 | 1690 | // Main Query |
1691 | - $this->_query = "LOCK TABLES"; |
|
1691 | + $this->_query="LOCK TABLES"; |
|
1692 | 1692 | |
1693 | 1693 | // Is the table an array? |
1694 | 1694 | if (gettype($table) == "array") { |
@@ -1696,22 +1696,22 @@ discard block |
||
1696 | 1696 | foreach ($table as $key => $value) { |
1697 | 1697 | if (gettype($value) == "string") { |
1698 | 1698 | if ($key > 0) { |
1699 | - $this->_query .= ","; |
|
1699 | + $this->_query.=","; |
|
1700 | 1700 | } |
1701 | - $this->_query .= " " . $this->prefix . $value . " " . $this->_tableLockMethod; |
|
1701 | + $this->_query.=" ".$this->prefix.$value." ".$this->_tableLockMethod; |
|
1702 | 1702 | } |
1703 | 1703 | } |
1704 | 1704 | } else { |
1705 | 1705 | // Build the table prefix |
1706 | - $table = $this->prefix . $table; |
|
1706 | + $table=$this->prefix.$table; |
|
1707 | 1707 | |
1708 | 1708 | // Build the query |
1709 | - $this->_query = "LOCK TABLES " . $table . " " . $this->_tableLockMethod; |
|
1709 | + $this->_query="LOCK TABLES ".$table." ".$this->_tableLockMethod; |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | 1712 | // Exceute the query unprepared because LOCK only works with unprepared statements. |
1713 | - $result = $this->queryUnprepared($this->_query); |
|
1714 | - $errno = $this->mysqli()->errno; |
|
1713 | + $result=$this->queryUnprepared($this->_query); |
|
1714 | + $errno=$this->mysqli()->errno; |
|
1715 | 1715 | |
1716 | 1716 | // Reset the query |
1717 | 1717 | $this->reset(); |
@@ -1723,7 +1723,7 @@ discard block |
||
1723 | 1723 | return true; |
1724 | 1724 | } // Something went wrong |
1725 | 1725 | else { |
1726 | - throw new Exception("Locking of table " . $table . " failed", $errno); |
|
1726 | + throw new Exception("Locking of table ".$table." failed", $errno); |
|
1727 | 1727 | } |
1728 | 1728 | |
1729 | 1729 | // Return the success value |
@@ -1739,11 +1739,11 @@ discard block |
||
1739 | 1739 | */ |
1740 | 1740 | public function unlock() { |
1741 | 1741 | // Build the query |
1742 | - $this->_query = "UNLOCK TABLES"; |
|
1742 | + $this->_query="UNLOCK TABLES"; |
|
1743 | 1743 | |
1744 | 1744 | // Exceute the query unprepared because UNLOCK and LOCK only works with unprepared statements. |
1745 | - $result = $this->queryUnprepared($this->_query); |
|
1746 | - $errno = $this->mysqli()->errno; |
|
1745 | + $result=$this->queryUnprepared($this->_query); |
|
1746 | + $errno=$this->mysqli()->errno; |
|
1747 | 1747 | |
1748 | 1748 | // Reset the query |
1749 | 1749 | $this->reset(); |
@@ -1808,8 +1808,8 @@ discard block |
||
1808 | 1808 | * |
1809 | 1809 | * @return MysqliDb |
1810 | 1810 | */ |
1811 | - public function setPrefix($prefix = '') { |
|
1812 | - $this->prefix = $prefix; |
|
1811 | + public function setPrefix($prefix='') { |
|
1812 | + $this->prefix=$prefix; |
|
1813 | 1813 | return $this; |
1814 | 1814 | } |
1815 | 1815 | |
@@ -1825,7 +1825,7 @@ discard block |
||
1825 | 1825 | |
1826 | 1826 | if ($this->_mysqli) { |
1827 | 1827 | $this->_mysqli->close(); |
1828 | - $this->_mysqli = null; |
|
1828 | + $this->_mysqli=null; |
|
1829 | 1829 | } |
1830 | 1830 | } |
1831 | 1831 | |
@@ -1847,7 +1847,7 @@ discard block |
||
1847 | 1847 | if (!$this->_mysqli) { |
1848 | 1848 | return "mysqli is null"; |
1849 | 1849 | } |
1850 | - return trim($this->_stmtError . " " . $this->mysqli()->error); |
|
1850 | + return trim($this->_stmtError." ".$this->mysqli()->error); |
|
1851 | 1851 | } |
1852 | 1852 | |
1853 | 1853 | /* Helper functions */ |
@@ -1872,7 +1872,7 @@ discard block |
||
1872 | 1872 | } |
1873 | 1873 | |
1874 | 1874 | array_shift($this->_bindParams); |
1875 | - $val = Array('query' => $this->_query, |
|
1875 | + $val=Array('query' => $this->_query, |
|
1876 | 1876 | 'params' => $this->_bindParams, |
1877 | 1877 | 'alias' => $this->host |
1878 | 1878 | ); |
@@ -1891,7 +1891,7 @@ discard block |
||
1891 | 1891 | * |
1892 | 1892 | * @return array |
1893 | 1893 | */ |
1894 | - public function now($diff = null, $func = "NOW()") { |
|
1894 | + public function now($diff=null, $func="NOW()") { |
|
1895 | 1895 | return array("[F]" => Array($this->interval($diff, $func))); |
1896 | 1896 | } |
1897 | 1897 | |
@@ -1906,30 +1906,30 @@ discard block |
||
1906 | 1906 | * |
1907 | 1907 | * @return string |
1908 | 1908 | */ |
1909 | - public function interval($diff, $func = "NOW()") { |
|
1910 | - $types = Array("s" => "second", "m" => "minute", "h" => "hour", "d" => "day", "M" => "month", "Y" => "year"); |
|
1911 | - $incr = '+'; |
|
1912 | - $items = ''; |
|
1913 | - $type = 'd'; |
|
1909 | + public function interval($diff, $func="NOW()") { |
|
1910 | + $types=Array("s" => "second", "m" => "minute", "h" => "hour", "d" => "day", "M" => "month", "Y" => "year"); |
|
1911 | + $incr='+'; |
|
1912 | + $items=''; |
|
1913 | + $type='d'; |
|
1914 | 1914 | |
1915 | 1915 | if ($diff && preg_match('/([+-]?) ?([0-9]+) ?([a-zA-Z]?)/', $diff, $matches)) { |
1916 | 1916 | if (!empty($matches[1])) { |
1917 | - $incr = $matches[1]; |
|
1917 | + $incr=$matches[1]; |
|
1918 | 1918 | } |
1919 | 1919 | |
1920 | 1920 | if (!empty($matches[2])) { |
1921 | - $items = $matches[2]; |
|
1921 | + $items=$matches[2]; |
|
1922 | 1922 | } |
1923 | 1923 | |
1924 | 1924 | if (!empty($matches[3])) { |
1925 | - $type = $matches[3]; |
|
1925 | + $type=$matches[3]; |
|
1926 | 1926 | } |
1927 | 1927 | |
1928 | 1928 | if (!in_array($type, array_keys($types))) { |
1929 | 1929 | throw new Exception("invalid interval type in '{$diff}'"); |
1930 | 1930 | } |
1931 | 1931 | |
1932 | - $func .= " " . $incr . " interval " . $items . " " . $types[$type] . " "; |
|
1932 | + $func.=" ".$incr." interval ".$items." ".$types[$type]." "; |
|
1933 | 1933 | } |
1934 | 1934 | return $func; |
1935 | 1935 | } |
@@ -1942,11 +1942,11 @@ discard block |
||
1942 | 1942 | * @throws Exception |
1943 | 1943 | * @return array |
1944 | 1944 | */ |
1945 | - public function inc($num = 1) { |
|
1945 | + public function inc($num=1) { |
|
1946 | 1946 | if (!is_numeric($num)) { |
1947 | 1947 | throw new Exception('Argument supplied to inc must be a number'); |
1948 | 1948 | } |
1949 | - return array("[I]" => "+" . $num); |
|
1949 | + return array("[I]" => "+".$num); |
|
1950 | 1950 | } |
1951 | 1951 | |
1952 | 1952 | /** |
@@ -1956,11 +1956,11 @@ discard block |
||
1956 | 1956 | * |
1957 | 1957 | * @return array |
1958 | 1958 | */ |
1959 | - public function dec($num = 1) { |
|
1959 | + public function dec($num=1) { |
|
1960 | 1960 | if (!is_numeric($num)) { |
1961 | 1961 | throw new Exception('Argument supplied to dec must be a number'); |
1962 | 1962 | } |
1963 | - return array("[I]" => "-" . $num); |
|
1963 | + return array("[I]" => "-".$num); |
|
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | /** |
@@ -1970,8 +1970,8 @@ discard block |
||
1970 | 1970 | * |
1971 | 1971 | * @return array |
1972 | 1972 | */ |
1973 | - public function not($col = null) { |
|
1974 | - return array("[N]" => (string)$col); |
|
1973 | + public function not($col=null) { |
|
1974 | + return array("[N]" => (string) $col); |
|
1975 | 1975 | } |
1976 | 1976 | |
1977 | 1977 | /** |
@@ -1982,7 +1982,7 @@ discard block |
||
1982 | 1982 | * |
1983 | 1983 | * @return array |
1984 | 1984 | */ |
1985 | - public function func($expr, $bindParams = null) { |
|
1985 | + public function func($expr, $bindParams=null) { |
|
1986 | 1986 | return array("[F]" => array($expr, $bindParams)); |
1987 | 1987 | } |
1988 | 1988 | |
@@ -1992,8 +1992,8 @@ discard block |
||
1992 | 1992 | * @return MysqliDb new mysqlidb object |
1993 | 1993 | */ |
1994 | 1994 | public function copy() { |
1995 | - $copy = unserialize(serialize($this)); |
|
1996 | - $copy->_mysqli = null; |
|
1995 | + $copy=unserialize(serialize($this)); |
|
1996 | + $copy->_mysqli=null; |
|
1997 | 1997 | return $copy; |
1998 | 1998 | } |
1999 | 1999 | |
@@ -2018,9 +2018,9 @@ discard block |
||
2018 | 2018 | * |
2019 | 2019 | * @return MysqliDb |
2020 | 2020 | */ |
2021 | - public function setTrace($enabled, $stripPrefix = null) { |
|
2022 | - $this->traceEnabled = $enabled; |
|
2023 | - $this->traceStripPrefix = $stripPrefix; |
|
2021 | + public function setTrace($enabled, $stripPrefix=null) { |
|
2022 | + $this->traceEnabled=$enabled; |
|
2023 | + $this->traceStripPrefix=$stripPrefix; |
|
2024 | 2024 | return $this; |
2025 | 2025 | } |
2026 | 2026 | |
@@ -2032,14 +2032,14 @@ discard block |
||
2032 | 2032 | * @return bool True if table exists |
2033 | 2033 | */ |
2034 | 2034 | public function tableExists($tables) { |
2035 | - $tables = !is_array($tables) ? Array($tables) : $tables; |
|
2036 | - $count = count($tables); |
|
2035 | + $tables=!is_array($tables) ? Array($tables) : $tables; |
|
2036 | + $count=count($tables); |
|
2037 | 2037 | if ($count == 0) { |
2038 | 2038 | return false; |
2039 | 2039 | } |
2040 | 2040 | |
2041 | 2041 | foreach ($tables as $i => $value) |
2042 | - $tables[$i] = $this->prefix . $value; |
|
2042 | + $tables[$i]=$this->prefix.$value; |
|
2043 | 2043 | $this->where('table_schema', $this->db); |
2044 | 2044 | $this->where('table_name', $tables, 'in'); |
2045 | 2045 | $this->get('information_schema.tables', $count); |
@@ -2056,7 +2056,7 @@ discard block |
||
2056 | 2056 | * @return MysqliDb |
2057 | 2057 | */ |
2058 | 2058 | public function map($idField) { |
2059 | - $this->_mapKey = $idField; |
|
2059 | + $this->_mapKey=$idField; |
|
2060 | 2060 | return $this; |
2061 | 2061 | } |
2062 | 2062 | |
@@ -2071,7 +2071,7 @@ discard block |
||
2071 | 2071 | * |
2072 | 2072 | * @return dbWrapper |
2073 | 2073 | */ |
2074 | - public function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
|
2074 | + public function joinOrWhere($whereJoin, $whereProp, $whereValue='DBNULL', $operator='=', $cond='AND') { |
|
2075 | 2075 | return $this->joinWhere($whereJoin, $whereProp, $whereValue, $operator, 'OR'); |
2076 | 2076 | } |
2077 | 2077 | |
@@ -2086,8 +2086,8 @@ discard block |
||
2086 | 2086 | * |
2087 | 2087 | * @return dbWrapper |
2088 | 2088 | */ |
2089 | - public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
|
2090 | - $this->_joinAnd[$whereJoin][] = Array($cond, $whereProp, $operator, $whereValue); |
|
2089 | + public function joinWhere($whereJoin, $whereProp, $whereValue='DBNULL', $operator='=', $cond='AND') { |
|
2090 | + $this->_joinAnd[$whereJoin][]=Array($cond, $whereProp, $operator, $whereValue); |
|
2091 | 2091 | return $this; |
2092 | 2092 | } |
2093 | 2093 | |
@@ -2097,7 +2097,7 @@ discard block |
||
2097 | 2097 | * @return $this |
2098 | 2098 | */ |
2099 | 2099 | public function table($table) { |
2100 | - $this->tableName = $table; |
|
2100 | + $this->tableName=$table; |
|
2101 | 2101 | return $this; |
2102 | 2102 | } |
2103 | 2103 | |
@@ -2107,7 +2107,7 @@ discard block |
||
2107 | 2107 | * @return $this |
2108 | 2108 | */ |
2109 | 2109 | public function name($name) { |
2110 | - $this->tableName = $this->prefix . $name; |
|
2110 | + $this->tableName=$this->prefix.$name; |
|
2111 | 2111 | return $this; |
2112 | 2112 | } |
2113 | 2113 | |
@@ -2121,8 +2121,8 @@ discard block |
||
2121 | 2121 | * @param null $default 默认值 |
2122 | 2122 | * @return mixed|null |
2123 | 2123 | */ |
2124 | - public function value($col, $default = null) { |
|
2125 | - $result = $this->getValue($this->tableName, $col); |
|
2124 | + public function value($col, $default=null) { |
|
2125 | + $result=$this->getValue($this->tableName, $col); |
|
2126 | 2126 | return false !== $result ? $result : $default; |
2127 | 2127 | } |
2128 | 2128 | |
@@ -2135,8 +2135,8 @@ discard block |
||
2135 | 2135 | * |
2136 | 2136 | * @return mixed Contains the value of a returned column / array of values |
2137 | 2137 | */ |
2138 | - public function getValue($tableName, $column, $limit = 1) { |
|
2139 | - $res = $this->ArrayBuilder()->get($tableName, $limit, "{$column} AS retval"); |
|
2138 | + public function getValue($tableName, $column, $limit=1) { |
|
2139 | + $res=$this->ArrayBuilder()->get($tableName, $limit, "{$column} AS retval"); |
|
2140 | 2140 | |
2141 | 2141 | if (!$res) { |
2142 | 2142 | return null; |
@@ -2149,9 +2149,9 @@ discard block |
||
2149 | 2149 | return null; |
2150 | 2150 | } |
2151 | 2151 | |
2152 | - $newRes = Array(); |
|
2153 | - for ($i = 0; $i < $this->count; $i++) { |
|
2154 | - $newRes[] = $res[$i]['retval']; |
|
2152 | + $newRes=Array(); |
|
2153 | + for ($i=0; $i < $this->count; $i++) { |
|
2154 | + $newRes[]=$res[$i]['retval']; |
|
2155 | 2155 | } |
2156 | 2156 | return $newRes; |
2157 | 2157 | } |
@@ -2163,7 +2163,7 @@ discard block |
||
2163 | 2163 | * @return MysqliDb |
2164 | 2164 | */ |
2165 | 2165 | public function arrayBuilder() { |
2166 | - $this->returnType = 'array'; |
|
2166 | + $this->returnType='array'; |
|
2167 | 2167 | return $this; |
2168 | 2168 | } |
2169 | 2169 | |
@@ -2179,12 +2179,12 @@ discard block |
||
2179 | 2179 | return $this->value("SUM($field)"); |
2180 | 2180 | } |
2181 | 2181 | |
2182 | - public function count($field = '*') { |
|
2182 | + public function count($field='*') { |
|
2183 | 2183 | return $this->value("COUNT($field)"); |
2184 | 2184 | } |
2185 | 2185 | |
2186 | 2186 | public function limit($limit) { |
2187 | - $this->pageLimit = $limit; |
|
2187 | + $this->pageLimit=$limit; |
|
2188 | 2188 | return $this; |
2189 | 2189 | } |
2190 | 2190 | |
@@ -2197,7 +2197,7 @@ discard block |
||
2197 | 2197 | } |
2198 | 2198 | |
2199 | 2199 | public function field($field) { |
2200 | - $this->field = $field; |
|
2200 | + $this->field=$field; |
|
2201 | 2201 | return $this; |
2202 | 2202 | } |
2203 | 2203 | |
@@ -2216,9 +2216,9 @@ discard block |
||
2216 | 2216 | return $this->_buildInsert($this->tableName, $data, 'REPLACE'); |
2217 | 2217 | } |
2218 | 2218 | |
2219 | - public function page($page, $pageLimit = '10') { |
|
2220 | - $this->pageLimit = $pageLimit; |
|
2221 | - $info = $this->paginate($this->tableName, $page, $this->field); |
|
2219 | + public function page($page, $pageLimit='10') { |
|
2220 | + $this->pageLimit=$pageLimit; |
|
2221 | + $info=$this->paginate($this->tableName, $page, $this->field); |
|
2222 | 2222 | return $info; |
2223 | 2223 | } |
2224 | 2224 | |
@@ -2231,10 +2231,10 @@ discard block |
||
2231 | 2231 | * @param array|string $fields Array or coma separated list of fields to fetch |
2232 | 2232 | * @return array |
2233 | 2233 | */ |
2234 | - public function paginate($table, $page, $fields = null) { |
|
2235 | - $offset = $this->pageLimit * ($page - 1); |
|
2236 | - $res = $this->withTotalCount()->get($table, Array($offset, $this->pageLimit), $fields); |
|
2237 | - $this->totalPages = ceil($this->totalCount / $this->pageLimit); |
|
2234 | + public function paginate($table, $page, $fields=null) { |
|
2235 | + $offset=$this->pageLimit * ($page - 1); |
|
2236 | + $res=$this->withTotalCount()->get($table, Array($offset, $this->pageLimit), $fields); |
|
2237 | + $this->totalPages=ceil($this->totalCount / $this->pageLimit); |
|
2238 | 2238 | return $res; |
2239 | 2239 | } |
2240 | 2240 | |
@@ -2259,28 +2259,28 @@ discard block |
||
2259 | 2259 | * @return MysqliDb |
2260 | 2260 | */ |
2261 | 2261 | public function setQueryOption($options) { |
2262 | - $allowedOptions = Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT', |
|
2262 | + $allowedOptions=Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT', |
|
2263 | 2263 | 'SQL_BIG_RESULT', 'SQL_BUFFER_RESULT', 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS', |
2264 | 2264 | 'LOW_PRIORITY', 'IGNORE', 'QUICK', 'MYSQLI_NESTJOIN', 'FOR UPDATE', 'LOCK IN SHARE MODE'); |
2265 | 2265 | |
2266 | 2266 | if (!is_array($options)) { |
2267 | - $options = Array($options); |
|
2267 | + $options=Array($options); |
|
2268 | 2268 | } |
2269 | 2269 | |
2270 | 2270 | foreach ($options as $option) { |
2271 | - $option = strtoupper($option); |
|
2271 | + $option=strtoupper($option); |
|
2272 | 2272 | if (!in_array($option, $allowedOptions)) { |
2273 | - throw new Exception('Wrong query option: ' . $option); |
|
2273 | + throw new Exception('Wrong query option: '.$option); |
|
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | if ($option == 'MYSQLI_NESTJOIN') { |
2277 | - $this->_nestJoin = true; |
|
2277 | + $this->_nestJoin=true; |
|
2278 | 2278 | } elseif ($option == 'FOR UPDATE') { |
2279 | - $this->_forUpdate = true; |
|
2279 | + $this->_forUpdate=true; |
|
2280 | 2280 | } elseif ($option == 'LOCK IN SHARE MODE') { |
2281 | - $this->_lockInShareMode = true; |
|
2281 | + $this->_lockInShareMode=true; |
|
2282 | 2282 | } else { |
2283 | - $this->_queryOptions[] = $option; |
|
2283 | + $this->_queryOptions[]=$option; |
|
2284 | 2284 | } |
2285 | 2285 | } |
2286 | 2286 | |
@@ -2298,15 +2298,15 @@ discard block |
||
2298 | 2298 | } |
2299 | 2299 | |
2300 | 2300 | foreach ($this->_join as $data) { |
2301 | - list ($joinType, $joinTable, $joinCondition) = $data; |
|
2301 | + list ($joinType, $joinTable, $joinCondition)=$data; |
|
2302 | 2302 | |
2303 | 2303 | if (is_object($joinTable)) { |
2304 | - $joinStr = $this->_buildPair("", $joinTable); |
|
2304 | + $joinStr=$this->_buildPair("", $joinTable); |
|
2305 | 2305 | } else { |
2306 | - $joinStr = $joinTable; |
|
2306 | + $joinStr=$joinTable; |
|
2307 | 2307 | } |
2308 | 2308 | |
2309 | - $this->_query .= " " . $joinType . " JOIN " . $joinStr . |
|
2309 | + $this->_query.=" ".$joinType." JOIN ".$joinStr. |
|
2310 | 2310 | (false !== stripos($joinCondition, 'using') ? " " : " on ") |
2311 | 2311 | . $joinCondition; |
2312 | 2312 | } |
@@ -268,8 +268,9 @@ discard block |
||
268 | 268 | * @return void |
269 | 269 | */ |
270 | 270 | public function disconnect() { |
271 | - if (!$this->_mysqli) |
|
272 | - return; |
|
271 | + if (!$this->_mysqli) { |
|
272 | + return; |
|
273 | + } |
|
273 | 274 | $this->_mysqli->close(); |
274 | 275 | $this->_mysqli = null; |
275 | 276 | } |
@@ -556,8 +557,9 @@ discard block |
||
556 | 557 | |
557 | 558 | // if $meta is false yet sqlstate is true, there's no sql error but the query is |
558 | 559 | // most likely an update/insert/delete which doesn't produce any results |
559 | - if (!$meta && $stmt->sqlstate) |
|
560 | - return array(); |
|
560 | + if (!$meta && $stmt->sqlstate) { |
|
561 | + return array(); |
|
562 | + } |
|
561 | 563 | |
562 | 564 | $row = array(); |
563 | 565 | while ($field = $meta->fetch_field()) { |
@@ -743,16 +745,18 @@ discard block |
||
743 | 745 | * Abstraction method that will build an JOIN part of the query |
744 | 746 | */ |
745 | 747 | protected function _buildJoin() { |
746 | - if (empty ($this->_join)) |
|
747 | - return; |
|
748 | + if (empty ($this->_join)) { |
|
749 | + return; |
|
750 | + } |
|
748 | 751 | |
749 | 752 | foreach ($this->_join as $data) { |
750 | 753 | list ($joinType, $joinTable, $joinCondition) = $data; |
751 | 754 | |
752 | - if (is_object($joinTable)) |
|
753 | - $joinStr = $this->_buildPair("", $joinTable); |
|
754 | - else |
|
755 | - $joinStr = $joinTable; |
|
755 | + if (is_object($joinTable)) { |
|
756 | + $joinStr = $this->_buildPair("", $joinTable); |
|
757 | + } else { |
|
758 | + $joinStr = $joinTable; |
|
759 | + } |
|
756 | 760 | |
757 | 761 | $this->_query .= " " . $joinType . " JOIN " . $joinStr . " on " . $joinCondition; |
758 | 762 | |
@@ -840,12 +844,13 @@ discard block |
||
840 | 844 | $this->_query .= $operator . $this->_buildPair("", $val); |
841 | 845 | break; |
842 | 846 | default: |
843 | - if (is_array($val)) |
|
844 | - $this->_bindParams($val); |
|
845 | - else if ($val === null) |
|
846 | - $this->_query .= $operator . " NULL"; |
|
847 | - else if ($val != 'DBNULL' || $val == '0') |
|
848 | - $this->_query .= $this->_buildPair($operator, $val); |
|
847 | + if (is_array($val)) { |
|
848 | + $this->_bindParams($val); |
|
849 | + } else if ($val === null) { |
|
850 | + $this->_query .= $operator . " NULL"; |
|
851 | + } else if ($val != 'DBNULL' || $val == '0') { |
|
852 | + $this->_query .= $this->_buildPair($operator, $val); |
|
853 | + } |
|
849 | 854 | } |
850 | 855 | } |
851 | 856 | |
@@ -862,8 +867,9 @@ discard block |
||
862 | 867 | $isInsert = preg_match('/^[INSERT|REPLACE]/', $this->_query); |
863 | 868 | $dataColumns = array_keys($tableData); |
864 | 869 | if ($isInsert) { |
865 | - if (isset ($dataColumns[0])) |
|
866 | - $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) '; |
|
870 | + if (isset ($dataColumns[0])) { |
|
871 | + $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) '; |
|
872 | + } |
|
867 | 873 | $this->_query .= ' VALUES ('; |
868 | 874 | } else { |
869 | 875 | $this->_query .= " SET "; |
@@ -2038,8 +2044,9 @@ discard block |
||
2038 | 2044 | return false; |
2039 | 2045 | } |
2040 | 2046 | |
2041 | - foreach ($tables as $i => $value) |
|
2042 | - $tables[$i] = $this->prefix . $value; |
|
2047 | + foreach ($tables as $i => $value) { |
|
2048 | + $tables[$i] = $this->prefix . $value; |
|
2049 | + } |
|
2043 | 2050 | $this->where('table_schema', $this->db); |
2044 | 2051 | $this->where('table_name', $tables, 'in'); |
2045 | 2052 | $this->get('information_schema.tables', $count); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @param string $subQueryAlias |
257 | 257 | * |
258 | - * @return MysqliDb |
|
258 | + * @return Mysql |
|
259 | 259 | */ |
260 | 260 | public static function subQuery($subQueryAlias = "") { |
261 | 261 | return new self(array('host' => $subQueryAlias, 'isSubQuery' => true)); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | /** |
278 | 278 | * Helper function to create dbObject with JSON return type |
279 | 279 | * |
280 | - * @return MysqliDb |
|
280 | + * @return Mysql |
|
281 | 281 | */ |
282 | 282 | public function jsonBuilder() { |
283 | 283 | $this->returnType = 'json'; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | /** |
288 | 288 | * Helper function to create dbObject with object return type. |
289 | 289 | * |
290 | - * @return MysqliDb |
|
290 | + * @return Mysql |
|
291 | 291 | */ |
292 | 292 | public function objectBuilder() { |
293 | 293 | $this->returnType = 'object'; |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | * Method attempts to prepare the SQL query |
351 | 351 | * and throws an error if there was a problem. |
352 | 352 | * |
353 | - * @return mysqli_stmt |
|
353 | + * @return \mysqli_stmt |
|
354 | 354 | */ |
355 | 355 | protected function _prepareQuery() { |
356 | 356 | if (!$stmt = $this->mysqli()->prepare($this->_query)) { |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | * This helper method takes care of prepared statements' "bind_result method |
540 | 540 | * , when the number of variables to pass is unknown. |
541 | 541 | * |
542 | - * @param mysqli_stmt $stmt Equal to the prepared statement object. |
|
542 | + * @param \mysqli_stmt $stmt Equal to the prepared statement object. |
|
543 | 543 | * |
544 | 544 | * @return array The results of the SQL fetch. |
545 | 545 | */ |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * or only $count |
703 | 703 | * @param array $tableData Should contain an array of data for updating the database. |
704 | 704 | * |
705 | - * @return mysqli_stmt Returns the $stmt object. |
|
705 | + * @return null|\mysqli_stmt Returns the $stmt object. |
|
706 | 706 | */ |
707 | 707 | protected function _buildQuery($numRows = null, $tableData = null) { |
708 | 708 | // $this->_buildJoinOld(); |
@@ -1209,9 +1209,8 @@ discard block |
||
1209 | 1209 | * A convenient function that returns TRUE if exists at least an element that |
1210 | 1210 | * satisfy the where condition specified calling the "where" method before this one. |
1211 | 1211 | * |
1212 | - * @param string $tableName The name of the database table to work with. |
|
1213 | 1212 | * |
1214 | - * @return array Contains the returned rows from the select query. |
|
1213 | + * @return boolean Contains the returned rows from the select query. |
|
1215 | 1214 | */ |
1216 | 1215 | public function has() { |
1217 | 1216 | $this->getOne($this->tableName, '1'); |
@@ -1311,7 +1310,7 @@ discard block |
||
1311 | 1310 | * @param int|array $numRows Array to define SQL limit in format Array ($count, $offset) |
1312 | 1311 | * or only $count |
1313 | 1312 | * |
1314 | - * @return bool Indicates success. 0 or 1. |
|
1313 | + * @return null|boolean Indicates success. 0 or 1. |
|
1315 | 1314 | */ |
1316 | 1315 | public function delete($numRows = null) { |
1317 | 1316 | if ($this->isSubQuery) { |
@@ -1342,7 +1341,7 @@ discard block |
||
1342 | 1341 | * @param array $updateColumns Variable with values |
1343 | 1342 | * @param string $lastInsertId Variable value |
1344 | 1343 | * |
1345 | - * @return MysqliDb |
|
1344 | + * @return Mysql |
|
1346 | 1345 | */ |
1347 | 1346 | public function onDuplicate($updateColumns, $lastInsertId = null) { |
1348 | 1347 | $this->_lastInsertId = $lastInsertId; |
@@ -1359,7 +1358,7 @@ discard block |
||
1359 | 1358 | * @param mixed $whereValue The value of the database field. |
1360 | 1359 | * @param string $operator Comparison operator. Default is = |
1361 | 1360 | * |
1362 | - * @return MysqliDb |
|
1361 | + * @return Mysql |
|
1363 | 1362 | */ |
1364 | 1363 | public function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') { |
1365 | 1364 | return $this->where($whereProp, $whereValue, $operator, 'OR'); |
@@ -1375,7 +1374,7 @@ discard block |
||
1375 | 1374 | * @param string $operator Comparison operator. Default is = |
1376 | 1375 | * @param string $cond Condition of where statement (OR, AND) |
1377 | 1376 | * |
1378 | - * @return MysqliDb |
|
1377 | + * @return Mysql |
|
1379 | 1378 | */ |
1380 | 1379 | public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
1381 | 1380 | // forkaround for an old operation api |
@@ -1401,7 +1400,7 @@ discard block |
||
1401 | 1400 | * @param mixed $havingValue The value of the database field. |
1402 | 1401 | * @param string $operator Comparison operator. Default is = |
1403 | 1402 | * |
1404 | - * @return MysqliDb |
|
1403 | + * @return Mysql |
|
1405 | 1404 | */ |
1406 | 1405 | public function orHaving($havingProp, $havingValue = null, $operator = null) { |
1407 | 1406 | return $this->having($havingProp, $havingValue, $operator, 'OR'); |
@@ -1416,7 +1415,7 @@ discard block |
||
1416 | 1415 | * @param mixed $havingValue The value of the database field. |
1417 | 1416 | * @param string $operator Comparison operator. Default is = |
1418 | 1417 | * |
1419 | - * @return MysqliDb |
|
1418 | + * @return Mysql |
|
1420 | 1419 | */ |
1421 | 1420 | |
1422 | 1421 | public function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
@@ -1444,7 +1443,7 @@ discard block |
||
1444 | 1443 | * @param string $joinType 'LEFT', 'INNER' etc. |
1445 | 1444 | * |
1446 | 1445 | * @throws Exception |
1447 | - * @return MysqliDb |
|
1446 | + * @return Mysql |
|
1448 | 1447 | */ |
1449 | 1448 | public function join($joinTable, $joinCondition, $joinType = '') { |
1450 | 1449 | $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); |
@@ -1529,7 +1528,7 @@ discard block |
||
1529 | 1528 | * This method does not escape strings by default so make sure you'll never use it in production. |
1530 | 1529 | * |
1531 | 1530 | * @author Jonas Barascu |
1532 | - * @param [[Type]] $query [[Description]] |
|
1531 | + * @param string $query [[Description]] |
|
1533 | 1532 | */ |
1534 | 1533 | private function queryUnprepared($query) { |
1535 | 1534 | // Execute query |
@@ -1603,11 +1602,11 @@ discard block |
||
1603 | 1602 | * @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc'); |
1604 | 1603 | * |
1605 | 1604 | * @param string $orderByField The name of the database field. |
1606 | - * @param string $orderByDirection Order direction. |
|
1605 | + * @param string $orderbyDirection Order direction. |
|
1607 | 1606 | * @param array $customFields Fieldset for ORDER BY FIELD() ordering |
1608 | 1607 | * |
1609 | 1608 | * @throws Exception |
1610 | - * @return MysqliDb |
|
1609 | + * @return Mysql |
|
1611 | 1610 | */ |
1612 | 1611 | public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields = null) { |
1613 | 1612 | $allowedDirection = Array("ASC", "DESC"); |
@@ -1643,7 +1642,7 @@ discard block |
||
1643 | 1642 | * |
1644 | 1643 | * @param string $groupByField The name of the database field. |
1645 | 1644 | * |
1646 | - * @return MysqliDb |
|
1645 | + * @return Mysql |
|
1647 | 1646 | */ |
1648 | 1647 | public function groupBy($groupByField) { |
1649 | 1648 | $groupByField = preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField); |
@@ -1659,7 +1658,7 @@ discard block |
||
1659 | 1658 | * @param string $method The table lock method. Can be READ or WRITE. |
1660 | 1659 | * |
1661 | 1660 | * @throws Exception |
1662 | - * @return MysqliDb |
|
1661 | + * @return Mysql |
|
1663 | 1662 | */ |
1664 | 1663 | public function setLockMethod($method) { |
1665 | 1664 | // Switch the uppercase string |
@@ -1806,7 +1805,7 @@ discard block |
||
1806 | 1805 | * |
1807 | 1806 | * @param string $prefix Contains a tableprefix |
1808 | 1807 | * |
1809 | - * @return MysqliDb |
|
1808 | + * @return Mysql |
|
1810 | 1809 | */ |
1811 | 1810 | public function setPrefix($prefix = '') { |
1812 | 1811 | $this->prefix = $prefix; |
@@ -2016,7 +2015,7 @@ discard block |
||
2016 | 2015 | * @param bool $enabled Enable execution time tracking |
2017 | 2016 | * @param string $stripPrefix Prefix to strip from the path in exec log |
2018 | 2017 | * |
2019 | - * @return MysqliDb |
|
2018 | + * @return Mysql |
|
2020 | 2019 | */ |
2021 | 2020 | public function setTrace($enabled, $stripPrefix = null) { |
2022 | 2021 | $this->traceEnabled = $enabled; |
@@ -2053,7 +2052,7 @@ discard block |
||
2053 | 2052 | * |
2054 | 2053 | * @param string $idField field name to use for a mapped element key |
2055 | 2054 | * |
2056 | - * @return MysqliDb |
|
2055 | + * @return Mysql |
|
2057 | 2056 | */ |
2058 | 2057 | public function map($idField) { |
2059 | 2058 | $this->_mapKey = $idField; |
@@ -2069,7 +2068,7 @@ discard block |
||
2069 | 2068 | * @param string $whereProp The name of the database field. |
2070 | 2069 | * @param mixed $whereValue The value of the database field. |
2071 | 2070 | * |
2072 | - * @return dbWrapper |
|
2071 | + * @return Mysql |
|
2073 | 2072 | */ |
2074 | 2073 | public function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
2075 | 2074 | return $this->joinWhere($whereJoin, $whereProp, $whereValue, $operator, 'OR'); |
@@ -2084,7 +2083,7 @@ discard block |
||
2084 | 2083 | * @param string $whereProp The name of the database field. |
2085 | 2084 | * @param mixed $whereValue The value of the database field. |
2086 | 2085 | * |
2087 | - * @return dbWrapper |
|
2086 | + * @return Mysql |
|
2088 | 2087 | */ |
2089 | 2088 | public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
2090 | 2089 | $this->_joinAnd[$whereJoin][] = Array($cond, $whereProp, $operator, $whereValue); |
@@ -2160,7 +2159,7 @@ discard block |
||
2160 | 2159 | * Helper function to create dbObject with array return type |
2161 | 2160 | * Added for consistency as thats default output type |
2162 | 2161 | * |
2163 | - * @return MysqliDb |
|
2162 | + * @return Mysql |
|
2164 | 2163 | */ |
2165 | 2164 | public function arrayBuilder() { |
2166 | 2165 | $this->returnType = 'array'; |
@@ -2241,7 +2240,7 @@ discard block |
||
2241 | 2240 | /** |
2242 | 2241 | * Function to enable SQL_CALC_FOUND_ROWS in the get queries |
2243 | 2242 | * |
2244 | - * @return MysqliDb |
|
2243 | + * @return Mysql |
|
2245 | 2244 | */ |
2246 | 2245 | public function withTotalCount() { |
2247 | 2246 | $this->setQueryOption('SQL_CALC_FOUND_ROWS'); |
@@ -2253,10 +2252,10 @@ discard block |
||
2253 | 2252 | * |
2254 | 2253 | * @uses $MySqliDb->setQueryOption('name'); |
2255 | 2254 | * |
2256 | - * @param string|array $options The optons name of the query. |
|
2255 | + * @param string $options The optons name of the query. |
|
2257 | 2256 | * |
2258 | 2257 | * @throws Exception |
2259 | - * @return MysqliDb |
|
2258 | + * @return Mysql |
|
2260 | 2259 | */ |
2261 | 2260 | public function setQueryOption($options) { |
2262 | 2261 | $allowedOptions = Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT', |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @var array |
17 | 17 | */ |
18 | - protected $loadedConfigurations = []; |
|
18 | + protected $loadedConfigurations=[]; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * 应用的根目录. |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | $this->initConfig(); |
31 | 31 | } |
32 | 32 | |
33 | - private function initEnv(){ |
|
34 | - try{ |
|
35 | - $dotEnv = new Dotenv($this->basePath); |
|
33 | + private function initEnv() { |
|
34 | + try { |
|
35 | + $dotEnv=new Dotenv($this->basePath); |
|
36 | 36 | $dotEnv->load(); |
37 | 37 | } |
38 | - catch (\Dotenv\Exception\InvalidPathException $e){ |
|
38 | + catch (\Dotenv\Exception\InvalidPathException $e) { |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai')); |
42 | 42 | define('IS_CLI', $this->runningInConsole()); |
43 | - define('IS_DEBUG',env('DEBUG',false)); |
|
43 | + define('IS_DEBUG', env('DEBUG', false)); |
|
44 | 44 | if (IS_DEBUG) { |
45 | 45 | error_reporting(E_ALL); |
46 | 46 | @ini_set('display_errors', 'On'); |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | */ |
69 | 69 | private function initContainer() { |
70 | 70 | static::setInstance($this); |
71 | - $this->instance('app',$this); |
|
72 | - $this->instance('config',new Config()); |
|
73 | - $this->instance('request',new Request($this->config)); |
|
74 | - $this->instance('route',new Route($this->request)); |
|
71 | + $this->instance('app', $this); |
|
72 | + $this->instance('config', new Config()); |
|
73 | + $this->instance('request', new Request($this->config)); |
|
74 | + $this->instance('route', new Route($this->request)); |
|
75 | 75 | $this->regexBind('#^(\w+)_model$#', "\\app\\models\\\\$1"); |
76 | - $this->bind('pinyin','\puck\helpers\PinYin'); |
|
77 | - $this->bind('curl','\puck\helpers\Curl'); |
|
76 | + $this->bind('pinyin', '\puck\helpers\PinYin'); |
|
77 | + $this->bind('curl', '\puck\helpers\Curl'); |
|
78 | 78 | $this->bind('dom', '\puck\helpers\Dom'); |
79 | 79 | $this->bind('db', '\puck\Db'); |
80 | 80 | } |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | return; |
96 | 96 | } |
97 | 97 | //标记为已加载 |
98 | - $this->loadedConfigurations[$name] = true; |
|
99 | - $path = $this->getConfigurationPath($name); |
|
98 | + $this->loadedConfigurations[$name]=true; |
|
99 | + $path=$this->getConfigurationPath($name); |
|
100 | 100 | if ($path) { |
101 | 101 | $this->make('config')->set($name, require $path); |
102 | 102 | } |
@@ -112,21 +112,21 @@ discard block |
||
112 | 112 | * @param string|null $name |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - public function getConfigurationPath($name = null) |
|
115 | + public function getConfigurationPath($name=null) |
|
116 | 116 | { |
117 | - if (! $name) { |
|
118 | - $appConfigDir = $this->basePath('configs').'/'; |
|
117 | + if (!$name) { |
|
118 | + $appConfigDir=$this->basePath('configs').'/'; |
|
119 | 119 | |
120 | 120 | if (file_exists($appConfigDir)) { |
121 | 121 | return $appConfigDir; |
122 | - } elseif (file_exists($path = __DIR__.'/configs/')) { |
|
122 | + } elseif (file_exists($path=__DIR__.'/configs/')) { |
|
123 | 123 | return $path; |
124 | 124 | } |
125 | 125 | } else { |
126 | - $appConfigPath = $this->basePath('configs').'/'.$name.'.php'; |
|
126 | + $appConfigPath=$this->basePath('configs').'/'.$name.'.php'; |
|
127 | 127 | if (file_exists($appConfigPath)) { |
128 | 128 | return $appConfigPath; |
129 | - } elseif (file_exists($path = __DIR__.'/configs/'.$name.'.php')) { |
|
129 | + } elseif (file_exists($path=__DIR__.'/configs/'.$name.'.php')) { |
|
130 | 130 | return $path; |
131 | 131 | } |
132 | 132 | } |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | * @param string|null $path |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function basePath($path = null) { |
|
141 | + public function basePath($path=null) { |
|
142 | 142 | if (isset($this->basePath)) { |
143 | - return $this->basePath . ($path ? '/' . $path : $path); |
|
143 | + return $this->basePath.($path ? '/'.$path : $path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | if ($this->runningInConsole()) { |
147 | - $this->basePath = getcwd(); |
|
147 | + $this->basePath=getcwd(); |
|
148 | 148 | } else { |
149 | - $this->basePath = realpath(getcwd() . '/../'); |
|
149 | + $this->basePath=realpath(getcwd().'/../'); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return $this->basePath($path); |
@@ -34,8 +34,7 @@ |
||
34 | 34 | try{ |
35 | 35 | $dotEnv = new Dotenv($this->basePath); |
36 | 36 | $dotEnv->load(); |
37 | - } |
|
38 | - catch (\Dotenv\Exception\InvalidPathException $e){ |
|
37 | + } catch (\Dotenv\Exception\InvalidPathException $e){ |
|
39 | 38 | |
40 | 39 | } |
41 | 40 | date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai')); |