@@ -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 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | public function __call($method, $arg) { |
| 384 | 384 | if (method_exists($this, $method)) |
| 385 | 385 | return call_user_func_array(array($this, $method), $arg); |
| 386 | - return call_user_func_array(array($this->db, $method), $arg);; |
|
| 386 | + return call_user_func_array(array($this->db, $method), $arg); ; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | * @return array Converted data |
| 411 | 411 | */ |
| 412 | 412 | public function toArray() { |
| 413 | - $data = $this->data; |
|
| 413 | + $data=$this->data; |
|
| 414 | 414 | $this->processAllWith($data); |
| 415 | 415 | foreach ($data as &$d) { |
| 416 | 416 | if ($d instanceof dbObject) |
| 417 | - $d = $d->data; |
|
| 417 | + $d=$d->data; |
|
| 418 | 418 | } |
| 419 | 419 | return $data; |
| 420 | 420 | } |
@@ -424,40 +424,40 @@ discard block |
||
| 424 | 424 | * |
| 425 | 425 | * @param array $data |
| 426 | 426 | */ |
| 427 | - private function processAllWith(&$data, $shouldReset = true) { |
|
| 427 | + private function processAllWith(&$data, $shouldReset=true) { |
|
| 428 | 428 | if (count($this->_with) == 0) |
| 429 | 429 | return; |
| 430 | 430 | |
| 431 | 431 | foreach ($this->_with as $name => $opts) { |
| 432 | - $relationType = strtolower($opts[0]); |
|
| 433 | - $modelName = $opts[1]; |
|
| 432 | + $relationType=strtolower($opts[0]); |
|
| 433 | + $modelName=$opts[1]; |
|
| 434 | 434 | if ($relationType == 'hasone') { |
| 435 | - $obj = new $modelName; |
|
| 436 | - $table = $obj->dbTable; |
|
| 437 | - $primaryKey = $obj->primaryKey; |
|
| 435 | + $obj=new $modelName; |
|
| 436 | + $table=$obj->dbTable; |
|
| 437 | + $primaryKey=$obj->primaryKey; |
|
| 438 | 438 | |
| 439 | 439 | if (!isset ($data[$table])) { |
| 440 | - $data[$name] = $this->$name; |
|
| 440 | + $data[$name]=$this->$name; |
|
| 441 | 441 | continue; |
| 442 | 442 | } |
| 443 | 443 | if ($data[$table][$primaryKey] === null) { |
| 444 | - $data[$name] = null; |
|
| 444 | + $data[$name]=null; |
|
| 445 | 445 | } else { |
| 446 | 446 | if ($this->returnType == 'Object') { |
| 447 | - $item = new $modelName ($data[$table]); |
|
| 448 | - $item->returnType = $this->returnType; |
|
| 449 | - $item->isNew = false; |
|
| 450 | - $data[$name] = $item; |
|
| 447 | + $item=new $modelName($data[$table]); |
|
| 448 | + $item->returnType=$this->returnType; |
|
| 449 | + $item->isNew=false; |
|
| 450 | + $data[$name]=$item; |
|
| 451 | 451 | } else { |
| 452 | - $data[$name] = $data[$table]; |
|
| 452 | + $data[$name]=$data[$table]; |
|
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | unset ($data[$table]); |
| 456 | 456 | } else |
| 457 | - $data[$name] = $this->$name; |
|
| 457 | + $data[$name]=$this->$name; |
|
| 458 | 458 | } |
| 459 | 459 | if ($shouldReset) |
| 460 | - $this->_with = Array(); |
|
| 460 | + $this->_with=Array(); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -470,24 +470,24 @@ discard block |
||
| 470 | 470 | * |
| 471 | 471 | * @return array Array of dbObjects |
| 472 | 472 | */ |
| 473 | - protected function get($limit = null, $fields = null) { |
|
| 474 | - $objects = Array(); |
|
| 473 | + protected function get($limit=null, $fields=null) { |
|
| 474 | + $objects=Array(); |
|
| 475 | 475 | $this->processHasOneWith(); |
| 476 | - $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
| 476 | + $results=$this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
| 477 | 477 | if ($this->db->count == 0) |
| 478 | 478 | return null; |
| 479 | 479 | |
| 480 | 480 | foreach ($results as &$r) { |
| 481 | 481 | $this->processArrays($r); |
| 482 | - $this->data = $r; |
|
| 482 | + $this->data=$r; |
|
| 483 | 483 | $this->processAllWith($r, false); |
| 484 | 484 | if ($this->returnType == 'Object') { |
| 485 | - $item = new static ($r); |
|
| 486 | - $item->isNew = false; |
|
| 487 | - $objects[] = $item; |
|
| 485 | + $item=new static ($r); |
|
| 486 | + $item->isNew=false; |
|
| 487 | + $objects[]=$item; |
|
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | - $this->_with = Array(); |
|
| 490 | + $this->_with=Array(); |
|
| 491 | 491 | if ($this->returnType == 'Object') |
| 492 | 492 | return $objects; |
| 493 | 493 | |
@@ -501,11 +501,11 @@ discard block |
||
| 501 | 501 | if (count($this->_with) == 0) |
| 502 | 502 | return; |
| 503 | 503 | foreach ($this->_with as $name => $opts) { |
| 504 | - $relationType = strtolower($opts[0]); |
|
| 505 | - $modelName = $opts[1]; |
|
| 506 | - $key = null; |
|
| 504 | + $relationType=strtolower($opts[0]); |
|
| 505 | + $modelName=$opts[1]; |
|
| 506 | + $key=null; |
|
| 507 | 507 | if (isset ($opts[2])) |
| 508 | - $key = $opts[2]; |
|
| 508 | + $key=$opts[2]; |
|
| 509 | 509 | if ($relationType == 'hasone') { |
| 510 | 510 | $this->db->setQueryOption("MYSQLI_NESTJOIN"); |
| 511 | 511 | $this->join($modelName, $key); |
@@ -524,18 +524,18 @@ discard block |
||
| 524 | 524 | * |
| 525 | 525 | * @return dbObject |
| 526 | 526 | */ |
| 527 | - private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
|
| 528 | - $joinObj = new $objectName; |
|
| 527 | + private function join($objectName, $key=null, $joinType='LEFT', $primaryKey=null) { |
|
| 528 | + $joinObj=new $objectName; |
|
| 529 | 529 | if (!$key) |
| 530 | - $key = $objectName . "id"; |
|
| 530 | + $key=$objectName."id"; |
|
| 531 | 531 | |
| 532 | 532 | if (!$primaryKey) |
| 533 | - $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
| 533 | + $primaryKey=$this->db->getPrefix().$joinObj->dbTable.".".$joinObj->primaryKey; |
|
| 534 | 534 | |
| 535 | 535 | if (!strchr($key, '.')) |
| 536 | - $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
| 536 | + $joinStr=$this->db->getPrefix().$this->dbTable.".{$key} = ".$primaryKey; |
|
| 537 | 537 | else |
| 538 | - $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
| 538 | + $joinStr=$this->db->getPrefix()."{$key} = ".$primaryKey; |
|
| 539 | 539 | |
| 540 | 540 | $this->db->join($joinObj->dbTable, $joinStr, $joinType); |
| 541 | 541 | return $this; |
@@ -547,12 +547,12 @@ discard block |
||
| 547 | 547 | private function processArrays(&$data) { |
| 548 | 548 | if (isset ($this->jsonFields) && is_array($this->jsonFields)) { |
| 549 | 549 | foreach ($this->jsonFields as $key) |
| 550 | - $data[$key] = json_decode($data[$key]); |
|
| 550 | + $data[$key]=json_decode($data[$key]); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | if (isset ($this->arrayFields) && is_array($this->arrayFields)) { |
| 554 | 554 | foreach ($this->arrayFields as $key) |
| 555 | - $data[$key] = explode("|", $data[$key]); |
|
| 555 | + $data[$key]=explode("|", $data[$key]); |
|
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @return int |
| 563 | 563 | */ |
| 564 | 564 | protected function count() { |
| 565 | - $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
| 565 | + $res=$this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
| 566 | 566 | if (!$res) |
| 567 | 567 | return 0; |
| 568 | 568 | return $res; |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @return dbObject |
| 575 | 575 | */ |
| 576 | 576 | private function JsonBuilder() { |
| 577 | - $this->returnType = 'Json'; |
|
| 577 | + $this->returnType='Json'; |
|
| 578 | 578 | return $this; |
| 579 | 579 | } |
| 580 | 580 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * @return dbObject |
| 589 | 589 | */ |
| 590 | 590 | private function ArrayBuilder() { |
| 591 | - $this->returnType = 'Array'; |
|
| 591 | + $this->returnType='Array'; |
|
| 592 | 592 | return $this; |
| 593 | 593 | } |
| 594 | 594 | |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | * @return dbObject |
| 600 | 600 | */ |
| 601 | 601 | private function ObjectBuilder() { |
| 602 | - $this->returnType = 'Object'; |
|
| 602 | + $this->returnType='Object'; |
|
| 603 | 603 | return $this; |
| 604 | 604 | } |
| 605 | 605 | |
@@ -612,8 +612,8 @@ discard block |
||
| 612 | 612 | * |
| 613 | 613 | * @return dbObject|array |
| 614 | 614 | */ |
| 615 | - private function byId($id, $fields = null) { |
|
| 616 | - $this->db->where($this->db->getPrefix() . $this->dbTable . '.' . $this->primaryKey, $id); |
|
| 615 | + private function byId($id, $fields=null) { |
|
| 616 | + $this->db->where($this->db->getPrefix().$this->dbTable.'.'.$this->primaryKey, $id); |
|
| 617 | 617 | return $this->getOne($fields); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -625,22 +625,22 @@ discard block |
||
| 625 | 625 | * |
| 626 | 626 | * @return dbObject |
| 627 | 627 | */ |
| 628 | - protected function getOne($fields = null) { |
|
| 628 | + protected function getOne($fields=null) { |
|
| 629 | 629 | $this->processHasOneWith(); |
| 630 | - $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
| 630 | + $results=$this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
| 631 | 631 | if ($this->db->count == 0) |
| 632 | 632 | return null; |
| 633 | 633 | |
| 634 | 634 | $this->processArrays($results); |
| 635 | - $this->data = $results; |
|
| 635 | + $this->data=$results; |
|
| 636 | 636 | $this->processAllWith($results); |
| 637 | 637 | if ($this->returnType == 'Json') |
| 638 | 638 | return json_encode($results); |
| 639 | 639 | if ($this->returnType == 'Array') |
| 640 | 640 | return $results; |
| 641 | 641 | |
| 642 | - $item = new static ($results); |
|
| 643 | - $item->isNew = false; |
|
| 642 | + $item=new static ($results); |
|
| 643 | + $item->isNew=false; |
|
| 644 | 644 | |
| 645 | 645 | return $item; |
| 646 | 646 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
| 658 | 658 | die ("No relation with name $objectName found"); |
| 659 | 659 | |
| 660 | - $this->_with[$objectName] = $this->relations[$objectName]; |
|
| 660 | + $this->_with[$objectName]=$this->relations[$objectName]; |
|
| 661 | 661 | |
| 662 | 662 | return $this; |
| 663 | 663 | } |
@@ -678,23 +678,23 @@ discard block |
||
| 678 | 678 | * @param array|string $fields Array or coma separated list of fields to fetch |
| 679 | 679 | * @return array |
| 680 | 680 | */ |
| 681 | - private function paginate($page, $fields = null) { |
|
| 682 | - $this->db->pageLimit = self::$pageLimit; |
|
| 683 | - $res = $this->db->paginate($this->dbTable, $page, $fields); |
|
| 684 | - self::$totalPages = $this->db->totalPages; |
|
| 681 | + private function paginate($page, $fields=null) { |
|
| 682 | + $this->db->pageLimit=self::$pageLimit; |
|
| 683 | + $res=$this->db->paginate($this->dbTable, $page, $fields); |
|
| 684 | + self::$totalPages=$this->db->totalPages; |
|
| 685 | 685 | if ($this->db->count == 0) return null; |
| 686 | 686 | |
| 687 | 687 | foreach ($res as &$r) { |
| 688 | 688 | $this->processArrays($r); |
| 689 | - $this->data = $r; |
|
| 689 | + $this->data=$r; |
|
| 690 | 690 | $this->processAllWith($r, false); |
| 691 | 691 | if ($this->returnType == 'Object') { |
| 692 | - $item = new static ($r); |
|
| 693 | - $item->isNew = false; |
|
| 694 | - $objects[] = $item; |
|
| 692 | + $item=new static ($r); |
|
| 693 | + $item->isNew=false; |
|
| 694 | + $objects[]=$item; |
|
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | - $this->_with = Array(); |
|
| 697 | + $this->_with=Array(); |
|
| 698 | 698 | if ($this->returnType == 'Object') |
| 699 | 699 | return $objects; |
| 700 | 700 | |
@@ -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 | return call_user_func_array(array($this->db, $method), $arg);; |
| 387 | 422 | } |
| 388 | 423 | |
@@ -413,8 +448,9 @@ discard block |
||
| 413 | 448 | $data = $this->data; |
| 414 | 449 | $this->processAllWith($data); |
| 415 | 450 | foreach ($data as &$d) { |
| 416 | - if ($d instanceof dbObject) |
|
| 417 | - $d = $d->data; |
|
| 451 | + if ($d instanceof dbObject) { |
|
| 452 | + $d = $d->data; |
|
| 453 | + } |
|
| 418 | 454 | } |
| 419 | 455 | return $data; |
| 420 | 456 | } |
@@ -425,8 +461,9 @@ discard block |
||
| 425 | 461 | * @param array $data |
| 426 | 462 | */ |
| 427 | 463 | private function processAllWith(&$data, $shouldReset = true) { |
| 428 | - if (count($this->_with) == 0) |
|
| 429 | - return; |
|
| 464 | + if (count($this->_with) == 0) { |
|
| 465 | + return; |
|
| 466 | + } |
|
| 430 | 467 | |
| 431 | 468 | foreach ($this->_with as $name => $opts) { |
| 432 | 469 | $relationType = strtolower($opts[0]); |
@@ -453,11 +490,13 @@ discard block |
||
| 453 | 490 | } |
| 454 | 491 | } |
| 455 | 492 | unset ($data[$table]); |
| 456 | - } else |
|
| 457 | - $data[$name] = $this->$name; |
|
| 493 | + } else { |
|
| 494 | + $data[$name] = $this->$name; |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + if ($shouldReset) { |
|
| 498 | + $this->_with = Array(); |
|
| 458 | 499 | } |
| 459 | - if ($shouldReset) |
|
| 460 | - $this->_with = Array(); |
|
| 461 | 500 | } |
| 462 | 501 | |
| 463 | 502 | /** |
@@ -474,8 +513,9 @@ discard block |
||
| 474 | 513 | $objects = Array(); |
| 475 | 514 | $this->processHasOneWith(); |
| 476 | 515 | $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
| 477 | - if ($this->db->count == 0) |
|
| 478 | - return null; |
|
| 516 | + if ($this->db->count == 0) { |
|
| 517 | + return null; |
|
| 518 | + } |
|
| 479 | 519 | |
| 480 | 520 | foreach ($results as &$r) { |
| 481 | 521 | $this->processArrays($r); |
@@ -488,24 +528,28 @@ discard block |
||
| 488 | 528 | } |
| 489 | 529 | } |
| 490 | 530 | $this->_with = Array(); |
| 491 | - if ($this->returnType == 'Object') |
|
| 492 | - return $objects; |
|
| 531 | + if ($this->returnType == 'Object') { |
|
| 532 | + return $objects; |
|
| 533 | + } |
|
| 493 | 534 | |
| 494 | - if ($this->returnType == 'Json') |
|
| 495 | - return json_encode($results); |
|
| 535 | + if ($this->returnType == 'Json') { |
|
| 536 | + return json_encode($results); |
|
| 537 | + } |
|
| 496 | 538 | |
| 497 | 539 | return $results; |
| 498 | 540 | } |
| 499 | 541 | |
| 500 | 542 | private function processHasOneWith() { |
| 501 | - if (count($this->_with) == 0) |
|
| 502 | - return; |
|
| 543 | + if (count($this->_with) == 0) { |
|
| 544 | + return; |
|
| 545 | + } |
|
| 503 | 546 | foreach ($this->_with as $name => $opts) { |
| 504 | 547 | $relationType = strtolower($opts[0]); |
| 505 | 548 | $modelName = $opts[1]; |
| 506 | 549 | $key = null; |
| 507 | - if (isset ($opts[2])) |
|
| 508 | - $key = $opts[2]; |
|
| 550 | + if (isset ($opts[2])) { |
|
| 551 | + $key = $opts[2]; |
|
| 552 | + } |
|
| 509 | 553 | if ($relationType == 'hasone') { |
| 510 | 554 | $this->db->setQueryOption("MYSQLI_NESTJOIN"); |
| 511 | 555 | $this->join($modelName, $key); |
@@ -526,16 +570,19 @@ discard block |
||
| 526 | 570 | */ |
| 527 | 571 | private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
| 528 | 572 | $joinObj = new $objectName; |
| 529 | - if (!$key) |
|
| 530 | - $key = $objectName . "id"; |
|
| 573 | + if (!$key) { |
|
| 574 | + $key = $objectName . "id"; |
|
| 575 | + } |
|
| 531 | 576 | |
| 532 | - if (!$primaryKey) |
|
| 533 | - $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
| 577 | + if (!$primaryKey) { |
|
| 578 | + $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
| 579 | + } |
|
| 534 | 580 | |
| 535 | - if (!strchr($key, '.')) |
|
| 536 | - $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
| 537 | - else |
|
| 538 | - $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
| 581 | + if (!strchr($key, '.')) { |
|
| 582 | + $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
| 583 | + } else { |
|
| 584 | + $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
| 585 | + } |
|
| 539 | 586 | |
| 540 | 587 | $this->db->join($joinObj->dbTable, $joinStr, $joinType); |
| 541 | 588 | return $this; |
@@ -546,13 +593,15 @@ discard block |
||
| 546 | 593 | */ |
| 547 | 594 | private function processArrays(&$data) { |
| 548 | 595 | if (isset ($this->jsonFields) && is_array($this->jsonFields)) { |
| 549 | - foreach ($this->jsonFields as $key) |
|
| 550 | - $data[$key] = json_decode($data[$key]); |
|
| 596 | + foreach ($this->jsonFields as $key) { |
|
| 597 | + $data[$key] = json_decode($data[$key]); |
|
| 598 | + } |
|
| 551 | 599 | } |
| 552 | 600 | |
| 553 | 601 | if (isset ($this->arrayFields) && is_array($this->arrayFields)) { |
| 554 | - foreach ($this->arrayFields as $key) |
|
| 555 | - $data[$key] = explode("|", $data[$key]); |
|
| 602 | + foreach ($this->arrayFields as $key) { |
|
| 603 | + $data[$key] = explode("|", $data[$key]); |
|
| 604 | + } |
|
| 556 | 605 | } |
| 557 | 606 | } |
| 558 | 607 | |
@@ -563,8 +612,9 @@ discard block |
||
| 563 | 612 | */ |
| 564 | 613 | protected function count() { |
| 565 | 614 | $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
| 566 | - if (!$res) |
|
| 567 | - return 0; |
|
| 615 | + if (!$res) { |
|
| 616 | + return 0; |
|
| 617 | + } |
|
| 568 | 618 | return $res; |
| 569 | 619 | } |
| 570 | 620 | |
@@ -628,16 +678,19 @@ discard block |
||
| 628 | 678 | protected function getOne($fields = null) { |
| 629 | 679 | $this->processHasOneWith(); |
| 630 | 680 | $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
| 631 | - if ($this->db->count == 0) |
|
| 632 | - return null; |
|
| 681 | + if ($this->db->count == 0) { |
|
| 682 | + return null; |
|
| 683 | + } |
|
| 633 | 684 | |
| 634 | 685 | $this->processArrays($results); |
| 635 | 686 | $this->data = $results; |
| 636 | 687 | $this->processAllWith($results); |
| 637 | - if ($this->returnType == 'Json') |
|
| 638 | - return json_encode($results); |
|
| 639 | - if ($this->returnType == 'Array') |
|
| 640 | - return $results; |
|
| 688 | + if ($this->returnType == 'Json') { |
|
| 689 | + return json_encode($results); |
|
| 690 | + } |
|
| 691 | + if ($this->returnType == 'Array') { |
|
| 692 | + return $results; |
|
| 693 | + } |
|
| 641 | 694 | |
| 642 | 695 | $item = new static ($results); |
| 643 | 696 | $item->isNew = false; |
@@ -654,8 +707,9 @@ discard block |
||
| 654 | 707 | * @return dbObject |
| 655 | 708 | */ |
| 656 | 709 | private function with($objectName) { |
| 657 | - if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
|
| 658 | - die ("No relation with name $objectName found"); |
|
| 710 | + if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) { |
|
| 711 | + die ("No relation with name $objectName found"); |
|
| 712 | + } |
|
| 659 | 713 | |
| 660 | 714 | $this->_with[$objectName] = $this->relations[$objectName]; |
| 661 | 715 | |
@@ -682,7 +736,9 @@ discard block |
||
| 682 | 736 | $this->db->pageLimit = self::$pageLimit; |
| 683 | 737 | $res = $this->db->paginate($this->dbTable, $page, $fields); |
| 684 | 738 | self::$totalPages = $this->db->totalPages; |
| 685 | - if ($this->db->count == 0) return null; |
|
| 739 | + if ($this->db->count == 0) { |
|
| 740 | + return null; |
|
| 741 | + } |
|
| 686 | 742 | |
| 687 | 743 | foreach ($res as &$r) { |
| 688 | 744 | $this->processArrays($r); |
@@ -695,11 +751,13 @@ discard block |
||
| 695 | 751 | } |
| 696 | 752 | } |
| 697 | 753 | $this->_with = Array(); |
| 698 | - if ($this->returnType == 'Object') |
|
| 699 | - return $objects; |
|
| 754 | + if ($this->returnType == 'Object') { |
|
| 755 | + return $objects; |
|
| 756 | + } |
|
| 700 | 757 | |
| 701 | - if ($this->returnType == 'Json') |
|
| 702 | - return json_encode($res); |
|
| 758 | + if ($this->returnType == 'Json') { |
|
| 759 | + return json_encode($res); |
|
| 760 | + } |
|
| 703 | 761 | |
| 704 | 762 | return $res; |
| 705 | 763 | } |
@@ -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(); |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | * |
| 1212 | 1212 | * @param string $tableName The name of the database table to work with. |
| 1213 | 1213 | * |
| 1214 | - * @return array Contains the returned rows from the select query. |
|
| 1214 | + * @return boolean Contains the returned rows from the select query. |
|
| 1215 | 1215 | */ |
| 1216 | 1216 | public function has($tableName) { |
| 1217 | 1217 | $this->getOne($tableName, '1'); |
@@ -1311,7 +1311,7 @@ discard block |
||
| 1311 | 1311 | * @param int|array $numRows Array to define SQL limit in format Array ($count, $offset) |
| 1312 | 1312 | * or only $count |
| 1313 | 1313 | * |
| 1314 | - * @return bool Indicates success. 0 or 1. |
|
| 1314 | + * @return null|boolean Indicates success. 0 or 1. |
|
| 1315 | 1315 | */ |
| 1316 | 1316 | public function delete($numRows = null) { |
| 1317 | 1317 | if ($this->isSubQuery) { |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | * @param array $updateColumns Variable with values |
| 1343 | 1343 | * @param string $lastInsertId Variable value |
| 1344 | 1344 | * |
| 1345 | - * @return MysqliDb |
|
| 1345 | + * @return Mysql |
|
| 1346 | 1346 | */ |
| 1347 | 1347 | public function onDuplicate($updateColumns, $lastInsertId = null) { |
| 1348 | 1348 | $this->_lastInsertId = $lastInsertId; |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | * @param mixed $whereValue The value of the database field. |
| 1360 | 1360 | * @param string $operator Comparison operator. Default is = |
| 1361 | 1361 | * |
| 1362 | - * @return MysqliDb |
|
| 1362 | + * @return Mysql |
|
| 1363 | 1363 | */ |
| 1364 | 1364 | public function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') { |
| 1365 | 1365 | return $this->where($whereProp, $whereValue, $operator, 'OR'); |
@@ -1375,7 +1375,7 @@ discard block |
||
| 1375 | 1375 | * @param string $operator Comparison operator. Default is = |
| 1376 | 1376 | * @param string $cond Condition of where statement (OR, AND) |
| 1377 | 1377 | * |
| 1378 | - * @return MysqliDb |
|
| 1378 | + * @return Mysql |
|
| 1379 | 1379 | */ |
| 1380 | 1380 | public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
| 1381 | 1381 | // forkaround for an old operation api |
@@ -1401,7 +1401,7 @@ discard block |
||
| 1401 | 1401 | * @param mixed $havingValue The value of the database field. |
| 1402 | 1402 | * @param string $operator Comparison operator. Default is = |
| 1403 | 1403 | * |
| 1404 | - * @return MysqliDb |
|
| 1404 | + * @return Mysql |
|
| 1405 | 1405 | */ |
| 1406 | 1406 | public function orHaving($havingProp, $havingValue = null, $operator = null) { |
| 1407 | 1407 | return $this->having($havingProp, $havingValue, $operator, 'OR'); |
@@ -1416,7 +1416,7 @@ discard block |
||
| 1416 | 1416 | * @param mixed $havingValue The value of the database field. |
| 1417 | 1417 | * @param string $operator Comparison operator. Default is = |
| 1418 | 1418 | * |
| 1419 | - * @return MysqliDb |
|
| 1419 | + * @return Mysql |
|
| 1420 | 1420 | */ |
| 1421 | 1421 | |
| 1422 | 1422 | public function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
@@ -1444,7 +1444,7 @@ discard block |
||
| 1444 | 1444 | * @param string $joinType 'LEFT', 'INNER' etc. |
| 1445 | 1445 | * |
| 1446 | 1446 | * @throws Exception |
| 1447 | - * @return MysqliDb |
|
| 1447 | + * @return Mysql |
|
| 1448 | 1448 | */ |
| 1449 | 1449 | public function join($joinTable, $joinCondition, $joinType = '') { |
| 1450 | 1450 | $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); |
@@ -1529,7 +1529,7 @@ discard block |
||
| 1529 | 1529 | * This method does not escape strings by default so make sure you'll never use it in production. |
| 1530 | 1530 | * |
| 1531 | 1531 | * @author Jonas Barascu |
| 1532 | - * @param [[Type]] $query [[Description]] |
|
| 1532 | + * @param string $query [[Description]] |
|
| 1533 | 1533 | */ |
| 1534 | 1534 | private function queryUnprepared($query) { |
| 1535 | 1535 | // Execute query |
@@ -1603,11 +1603,11 @@ discard block |
||
| 1603 | 1603 | * @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc'); |
| 1604 | 1604 | * |
| 1605 | 1605 | * @param string $orderByField The name of the database field. |
| 1606 | - * @param string $orderByDirection Order direction. |
|
| 1606 | + * @param string $orderbyDirection Order direction. |
|
| 1607 | 1607 | * @param array $customFields Fieldset for ORDER BY FIELD() ordering |
| 1608 | 1608 | * |
| 1609 | 1609 | * @throws Exception |
| 1610 | - * @return MysqliDb |
|
| 1610 | + * @return Mysql |
|
| 1611 | 1611 | */ |
| 1612 | 1612 | public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields = null) { |
| 1613 | 1613 | $allowedDirection = Array("ASC", "DESC"); |
@@ -1643,7 +1643,7 @@ discard block |
||
| 1643 | 1643 | * |
| 1644 | 1644 | * @param string $groupByField The name of the database field. |
| 1645 | 1645 | * |
| 1646 | - * @return MysqliDb |
|
| 1646 | + * @return Mysql |
|
| 1647 | 1647 | */ |
| 1648 | 1648 | public function groupBy($groupByField) { |
| 1649 | 1649 | $groupByField = preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField); |
@@ -1659,7 +1659,7 @@ discard block |
||
| 1659 | 1659 | * @param string $method The table lock method. Can be READ or WRITE. |
| 1660 | 1660 | * |
| 1661 | 1661 | * @throws Exception |
| 1662 | - * @return MysqliDb |
|
| 1662 | + * @return Mysql |
|
| 1663 | 1663 | */ |
| 1664 | 1664 | public function setLockMethod($method) { |
| 1665 | 1665 | // Switch the uppercase string |
@@ -1806,7 +1806,7 @@ discard block |
||
| 1806 | 1806 | * |
| 1807 | 1807 | * @param string $prefix Contains a tableprefix |
| 1808 | 1808 | * |
| 1809 | - * @return MysqliDb |
|
| 1809 | + * @return Mysql |
|
| 1810 | 1810 | */ |
| 1811 | 1811 | public function setPrefix($prefix = '') { |
| 1812 | 1812 | $this->prefix = $prefix; |
@@ -2016,7 +2016,7 @@ discard block |
||
| 2016 | 2016 | * @param bool $enabled Enable execution time tracking |
| 2017 | 2017 | * @param string $stripPrefix Prefix to strip from the path in exec log |
| 2018 | 2018 | * |
| 2019 | - * @return MysqliDb |
|
| 2019 | + * @return Mysql |
|
| 2020 | 2020 | */ |
| 2021 | 2021 | public function setTrace($enabled, $stripPrefix = null) { |
| 2022 | 2022 | $this->traceEnabled = $enabled; |
@@ -2053,7 +2053,7 @@ discard block |
||
| 2053 | 2053 | * |
| 2054 | 2054 | * @param string $idField field name to use for a mapped element key |
| 2055 | 2055 | * |
| 2056 | - * @return MysqliDb |
|
| 2056 | + * @return Mysql |
|
| 2057 | 2057 | */ |
| 2058 | 2058 | public function map($idField) { |
| 2059 | 2059 | $this->_mapKey = $idField; |
@@ -2069,7 +2069,7 @@ discard block |
||
| 2069 | 2069 | * @param string $whereProp The name of the database field. |
| 2070 | 2070 | * @param mixed $whereValue The value of the database field. |
| 2071 | 2071 | * |
| 2072 | - * @return dbWrapper |
|
| 2072 | + * @return Mysql |
|
| 2073 | 2073 | */ |
| 2074 | 2074 | public function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
| 2075 | 2075 | return $this->joinWhere($whereJoin, $whereProp, $whereValue, $operator, 'OR'); |
@@ -2084,7 +2084,7 @@ discard block |
||
| 2084 | 2084 | * @param string $whereProp The name of the database field. |
| 2085 | 2085 | * @param mixed $whereValue The value of the database field. |
| 2086 | 2086 | * |
| 2087 | - * @return dbWrapper |
|
| 2087 | + * @return Mysql |
|
| 2088 | 2088 | */ |
| 2089 | 2089 | public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') { |
| 2090 | 2090 | $this->_joinAnd[$whereJoin][] = Array($cond, $whereProp, $operator, $whereValue); |
@@ -2160,7 +2160,7 @@ discard block |
||
| 2160 | 2160 | * Helper function to create dbObject with array return type |
| 2161 | 2161 | * Added for consistency as thats default output type |
| 2162 | 2162 | * |
| 2163 | - * @return MysqliDb |
|
| 2163 | + * @return Mysql |
|
| 2164 | 2164 | */ |
| 2165 | 2165 | public function arrayBuilder() { |
| 2166 | 2166 | $this->returnType = 'array'; |
@@ -2241,7 +2241,7 @@ discard block |
||
| 2241 | 2241 | /** |
| 2242 | 2242 | * Function to enable SQL_CALC_FOUND_ROWS in the get queries |
| 2243 | 2243 | * |
| 2244 | - * @return MysqliDb |
|
| 2244 | + * @return Mysql |
|
| 2245 | 2245 | */ |
| 2246 | 2246 | public function withTotalCount() { |
| 2247 | 2247 | $this->setQueryOption('SQL_CALC_FOUND_ROWS'); |
@@ -2253,10 +2253,10 @@ discard block |
||
| 2253 | 2253 | * |
| 2254 | 2254 | * @uses $MySqliDb->setQueryOption('name'); |
| 2255 | 2255 | * |
| 2256 | - * @param string|array $options The optons name of the query. |
|
| 2256 | + * @param string $options The optons name of the query. |
|
| 2257 | 2257 | * |
| 2258 | 2258 | * @throws Exception |
| 2259 | - * @return MysqliDb |
|
| 2259 | + * @return Mysql |
|
| 2260 | 2260 | */ |
| 2261 | 2261 | public function setQueryOption($options) { |
| 2262 | 2262 | $allowedOptions = Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT', |
@@ -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); |
@@ -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 |
@@ -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')); |