@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | if (empty(self::$instance)) { |
| 15 | 15 | try { |
| 16 | 16 | |
| 17 | - if(!defined('DATAMANAGER_CONFIG')){ |
|
| 17 | + if (!defined('DATAMANAGER_CONFIG')) { |
|
| 18 | 18 | throw new Exception("Information for connection to the database not defined."); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | self::$instance = new PDO( |
| 22 | - DATAMANAGER_CONFIG['driver'] . ':host='.DATAMANAGER_CONFIG['host'] . ';port='.DATAMANAGER_CONFIG['port'] . ';dbname='.DATAMANAGER_CONFIG['database'] . ';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 22 | + DATAMANAGER_CONFIG['driver'].':host='.DATAMANAGER_CONFIG['host'].';port='.DATAMANAGER_CONFIG['port'].';dbname='.DATAMANAGER_CONFIG['database'].';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 23 | 23 | DATAMANAGER_CONFIG['username'], |
| 24 | 24 | DATAMANAGER_CONFIG['password'], |
| 25 | 25 | DATAMANAGER_CONFIG['options'] |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | return self::$instance; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public static function destroy(){ |
|
| 34 | + public static function destroy() { |
|
| 35 | 35 | self::$instance = null; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -9,11 +9,11 @@ |
||
| 9 | 9 | * @property string $email |
| 10 | 10 | * @property string $password |
| 11 | 11 | */ |
| 12 | -class User extends Datamanager{ |
|
| 12 | +class User extends Datamanager { |
|
| 13 | 13 | |
| 14 | 14 | public function __construct() |
| 15 | 15 | { |
| 16 | - parent::create('user','id'); |
|
| 16 | + parent::create('user', 'id'); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -6,24 +6,24 @@ discard block |
||
| 6 | 6 | use PDOException; |
| 7 | 7 | use PDO; |
| 8 | 8 | |
| 9 | -trait CrudTrait{ |
|
| 9 | +trait CrudTrait { |
|
| 10 | 10 | |
| 11 | 11 | protected ?Exception $fail = null; |
| 12 | 12 | |
| 13 | 13 | protected function check_fail() |
| 14 | 14 | { |
| 15 | - if(!is_null($this->fail)){ |
|
| 15 | + if (!is_null($this->fail)) { |
|
| 16 | 16 | throw $this->fail; |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | protected function transaction(string $transaction): ?bool |
| 21 | 21 | { |
| 22 | - if(array_key_exists($transaction,['begin','commit','rollback'])){ |
|
| 22 | + if (array_key_exists($transaction, ['begin', 'commit', 'rollback'])) { |
|
| 23 | 23 | throw new Exception("{$transaction} é um estado inválido para transações."); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if(!Connect::getInstance()->inTransaction()){ |
|
| 26 | + if (!Connect::getInstance()->inTransaction()) { |
|
| 27 | 27 | return Connect::getInstance()->beginTransaction(); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - protected function select(string $query,array $data): ?array |
|
| 37 | + protected function select(string $query, array $data): ?array |
|
| 38 | 38 | { |
| 39 | - try{ |
|
| 39 | + try { |
|
| 40 | 40 | $stmt = Connect::getInstance()->prepare("{$query}"); |
| 41 | 41 | $stmt->execute($data); |
| 42 | 42 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 43 | - }catch(Exception $exception){ |
|
| 43 | + } catch (Exception $exception) { |
|
| 44 | 44 | $this->fail = $exception; |
| 45 | 45 | } |
| 46 | 46 | return []; |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | protected function describe(): array |
| 50 | 50 | { |
| 51 | - try{ |
|
| 51 | + try { |
|
| 52 | 52 | $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}"); |
| 53 | 53 | $stmt->execute(); |
| 54 | 54 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 55 | - }catch(Exception $exception){ |
|
| 55 | + } catch (Exception $exception) { |
|
| 56 | 56 | $this->fail = $exception; |
| 57 | 57 | return []; |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | try { |
| 64 | 64 | $columns = implode(", ", array_keys($data)); |
| 65 | - $values = ":" . implode(", :", array_keys($data)); |
|
| 65 | + $values = ":".implode(", :", array_keys($data)); |
|
| 66 | 66 | |
| 67 | 67 | $stmt = Connect::getInstance()->prepare("INSERT INTO {$this->table} ({$columns}) VALUES ({$values})"); |
| 68 | 68 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | try { |
| 101 | 101 | $stmt = Connect::getInstance()->prepare("DELETE FROM {$this->table} WHERE {$terms}"); |
| 102 | 102 | |
| 103 | - if($params){ |
|
| 103 | + if ($params) { |
|
| 104 | 104 | parse_str($params, $arr); |
| 105 | 105 | $stmt->execute($arr); |
| 106 | 106 | return true; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $entity = new User(); |
| 12 | 12 | |
| 13 | -try{ |
|
| 13 | +try { |
|
| 14 | 14 | /* Set new info for insert in database */ |
| 15 | 15 | $entity->name = 'Henri Azevedo'; |
| 16 | 16 | $entity->email = '[email protected]'; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | $user = $entity->find()->execute()->first()->toEntity(); |
| 24 | 24 | |
| 25 | 25 | /* Search only for columns defined in advance */ |
| 26 | - $user = $entity->find()->only(['name','email'])->execute()->first(); |
|
| 26 | + $user = $entity->find()->only(['name', 'email'])->execute()->first(); |
|
| 27 | 27 | $name = $user->name; |
| 28 | 28 | $email = $user->email; |
| 29 | 29 | /* OR */ |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | /* Remove by cause *Where* */ |
| 45 | 45 | $user->remove()->where([ |
| 46 | - ['name','=','Other Name'], |
|
| 47 | - 'OR' => ['email','LIKE','[email protected]'] |
|
| 46 | + ['name', '=', 'Other Name'], |
|
| 47 | + 'OR' => ['email', 'LIKE', '[email protected]'] |
|
| 48 | 48 | ])->execute(); |
| 49 | -}catch(Exception $er){ |
|
| 49 | +} catch (Exception $er) { |
|
| 50 | 50 | |
| 51 | 51 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 52 | 52 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait DataTrait{ |
|
| 7 | +trait DataTrait { |
|
| 8 | 8 | protected ?string $table = null; |
| 9 | 9 | protected ?string $primary = null; |
| 10 | 10 | |
@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | return $this; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function __set(string $prop,$value): Datamanager |
|
| 32 | + public function __set(string $prop, $value): Datamanager |
|
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - if(is_array($value)){ |
|
| 35 | + if (is_array($value)) { |
|
| 36 | 36 | $attr = array_keys($value)[0]; |
| 37 | 37 | $this->data[$prop][$attr] = $value[$attr]; |
| 38 | 38 | return $this; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if($this->full && !array_key_exists($prop,$this->data)){ |
|
| 41 | + if ($this->full && !array_key_exists($prop, $this->data)) { |
|
| 42 | 42 | throw new Exception("{$prop} field does not exist in the table {$this->table}."); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function __get(string $field) |
| 57 | 57 | { |
| 58 | - if($this->full && !array_key_exists($field,$this->data)){ |
|
| 58 | + if ($this->full && !array_key_exists($field, $this->data)) { |
|
| 59 | 59 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
| 73 | 73 | |
| 74 | 74 | foreach ($deniable as $field) { |
| 75 | - if(!array_key_exists($field,$this->data)){ |
|
| 75 | + if (!array_key_exists($field, $this->data)) { |
|
| 76 | 76 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | public function orderBy(string $field, string $ord = 'ASC'): Datamanager |
| 94 | 94 | { |
| 95 | - if(!array_key_exists(str_replace(['asc','ASC','desc','DESC',' '],'',$field),$this->data) && $this->full){ |
|
| 95 | + if (!array_key_exists(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field), $this->data) && $this->full) { |
|
| 96 | 96 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if(strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')){ |
|
| 99 | + if (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) { |
|
| 100 | 100 | $ord = ''; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | foreach ($params as $field) { |
| 113 | 113 | |
| 114 | - if(!array_key_exists($field,$this->data) && $this->full){ |
|
| 114 | + if (!array_key_exists($field, $this->data) && $this->full) { |
|
| 115 | 115 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function where(array $where): Datamanager |
| 126 | 126 | { |
| 127 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
| 127 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
| 128 | 128 | $w = []; |
| 129 | 129 | foreach ($where as $condition => $values) { |
| 130 | 130 | |
| 131 | - if(!is_array($values)){ |
|
| 131 | + if (!is_array($values)) { |
|
| 132 | 132 | $w['AND'][] = $values; |
| 133 | 133 | continue; |
| 134 | 134 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $this->where = array_merge($this->where,$w); |
|
| 142 | + $this->where = array_merge($this->where, $w); |
|
| 143 | 143 | |
| 144 | 144 | return $this; |
| 145 | 145 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | public function offset(int $offset): Datamanager |
| 154 | 154 | { |
| 155 | - if(is_null($this->limit)){ |
|
| 155 | + if (is_null($this->limit)) { |
|
| 156 | 156 | throw new Exception("The limit must be set before the offset."); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | foreach ($arrayValues as $key => $value) { |
| 184 | 184 | |
| 185 | - if(!array_key_exists($key,$this->data)){ |
|
| 185 | + if (!array_key_exists($key, $this->data)) { |
|
| 186 | 186 | throw new Exception("{$key} field does not exist in the table {$this->table}."); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $string = ''; |
| 197 | 197 | foreach ($this->data as $key => $value) { |
| 198 | 198 | |
| 199 | - if(gettype($value)==='object'){ |
|
| 199 | + if (gettype($value) === 'object') { |
|
| 200 | 200 | $value = $value->getData()[$this->primary]['value']; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -207,19 +207,19 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | public function remove(?bool $exec = false): Datamanager |
| 209 | 209 | { |
| 210 | - if(!$exec){ |
|
| 210 | + if (!$exec) { |
|
| 211 | 211 | $this->clause = 'remove'; |
| 212 | 212 | return $this; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | $this->clause = null; |
| 216 | 216 | |
| 217 | - if(count($this->where) == 1){ |
|
| 217 | + if (count($this->where) == 1) { |
|
| 218 | 218 | $this->removeById(); |
| 219 | 219 | return $this; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) ); |
|
| 222 | + $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1)); |
|
| 223 | 223 | |
| 224 | 224 | $this->check_fail(); |
| 225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | private function removeById(): bool |
| 230 | 230 | { |
| 231 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
| 231 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
| 232 | 232 | |
| 233 | 233 | $this->check_fail(); |
| 234 | 234 | |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | $data = []; |
| 243 | 243 | |
| 244 | 244 | foreach ($this->data as $key => $value) { |
| 245 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
| 245 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if(strlen($value['value']) > $value['maxlength']){ |
|
| 249 | + if (strlen($value['value']) > $value['maxlength']) { |
|
| 250 | 250 | throw new Exception("The information provided for column {$key} of table {$this->table} exceeded that allowed."); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $this->transaction('begin'); |
| 259 | - try{ |
|
| 259 | + try { |
|
| 260 | 260 | |
| 261 | 261 | $id = $this->insert($data); |
| 262 | 262 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | $this->transaction('commit'); |
| 268 | 268 | |
| 269 | - }catch(Exception $er){ |
|
| 269 | + } catch (Exception $er) { |
|
| 270 | 270 | $this->transaction('rollback'); |
| 271 | 271 | throw $er; |
| 272 | 272 | } |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | public function toEntity() |
| 278 | 278 | { |
| 279 | - if($this->getCount() === 0){ |
|
| 279 | + if ($this->getCount() === 0) { |
|
| 280 | 280 | return null; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $entity = $this->setByDatabase($this->result[0]); |
| 284 | 284 | |
| 285 | - if(count($this->result) > 1){ |
|
| 285 | + if (count($this->result) > 1) { |
|
| 286 | 286 | $entity = []; |
| 287 | 287 | foreach ($this->result as $key => $value) { |
| 288 | 288 | $entity[] = $this->setByDatabase($value); |
@@ -294,13 +294,13 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | public function findById($id): Datamanager |
| 296 | 296 | { |
| 297 | - $this->where([$this->primary,'=',$id]); |
|
| 297 | + $this->where([$this->primary, '=', $id]); |
|
| 298 | 298 | return $this; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | public function execute(): Datamanager |
| 302 | 302 | { |
| 303 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
| 303 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
| 304 | 304 | return $this->remove(true); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | $this->mountSelect(); |
| 310 | 310 | |
| 311 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
| 311 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
| 312 | 312 | $this->query .= " WHERE {$where} "; |
| 313 | 313 | |
| 314 | 314 | $this->query .= $this->order; |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | { |
| 331 | 331 | $this->query = " SELECT * FROM {$this->table} "; |
| 332 | 332 | |
| 333 | - if(is_int($key)){ |
|
| 333 | + if (is_int($key)) { |
|
| 334 | 334 | return $this->findById($key); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | private bool $full = false; |
| 15 | 15 | private ?string $clause = null; |
| 16 | 16 | |
| 17 | - private array $where = [''=> ["1",'=',"1"] ]; |
|
| 17 | + private array $where = [''=> ["1", '=', "1"]]; |
|
| 18 | 18 | |
| 19 | 19 | private function mountTable_Field(string $field, $value = null) |
| 20 | 20 | { |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | $type = $value; |
| 27 | 27 | $maxlength = null; |
| 28 | 28 | |
| 29 | - if(strpos($value,'(')){ |
|
| 30 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type; |
|
| 31 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type; |
|
| 32 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type; |
|
| 29 | + if (strpos($value, '(')) { |
|
| 30 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type; |
|
| 31 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type; |
|
| 32 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - $maxlength = (in_array( $type , ['string','float','int'])) ? substr($value,(strpos($value,'(')+1),-1) : $maxlength; |
|
| 36 | - $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength; |
|
| 37 | - $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength; |
|
| 38 | - $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength; |
|
| 35 | + $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($value, (strpos($value, '(') + 1), -1) : $maxlength; |
|
| 36 | + $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength; |
|
| 37 | + $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength; |
|
| 38 | + $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength; |
|
| 39 | 39 | |
| 40 | 40 | $this->$field = ['maxlength' => $maxlength]; |
| 41 | 41 | $this->$field = ['type' => $type]; |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | public function check_where_array(array $where) |
| 80 | 80 | { |
| 81 | - if(count($where) != 3){ |
|
| 82 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$where)); |
|
| 81 | + if (count($where) != 3) { |
|
| 82 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $where)); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if(!array_key_exists($where[0],$this->data) && $this->full){ |
|
| 85 | + if (!array_key_exists($where[0], $this->data) && $this->full) { |
|
| 86 | 86 | throw new Exception("{$where[0]} field does not exist in the table {$this->table}."); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | private function mountRemove(): array |
| 91 | 91 | { |
| 92 | 92 | $return = ['data' => [], 'where' => '']; |
| 93 | - foreach($this->where as $clause => $condition){ |
|
| 94 | - if(strlen($clause) === 0){ |
|
| 93 | + foreach ($this->where as $clause => $condition) { |
|
| 94 | + if (strlen($clause) === 0) { |
|
| 95 | 95 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
| 96 | 96 | $return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - foreach($condition as $value){ |
|
| 100 | + foreach ($condition as $value) { |
|
| 101 | 101 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
| 102 | 102 | $return['data'] .= "q_{$value[0]}={$value[2]}&"; |
| 103 | 103 | } |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | $return = ['data' => []]; |
| 111 | 111 | |
| 112 | 112 | foreach ($this->data as $key => $value) { |
| 113 | - if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){ |
|
| 113 | + if (strstr($this->data[$key]['extra'], 'auto_increment') && $key !== $this->primary) { |
|
| 114 | 114 | continue; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){ |
|
| 117 | + if (($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key) { |
|
| 118 | 118 | $return['data'][$key] = $this->data[$key]['value']; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $this->transaction('begin'); |
| 128 | 128 | |
| 129 | - try{ |
|
| 129 | + try { |
|
| 130 | 130 | $this->update( |
| 131 | 131 | $this->mountSave()['data'], |
| 132 | 132 | "{$this->primary}=:{$this->primary}", |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $this->check_fail(); |
| 137 | 137 | |
| 138 | 138 | $this->transaction('commit'); |
| 139 | - }catch(Exception $er){ |
|
| 139 | + } catch (Exception $er) { |
|
| 140 | 140 | $this->transaction('rollback'); |
| 141 | 141 | throw $er; |
| 142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | $key = (!$key) ? '' : " {$key} "; |
| 154 | 154 | |
| 155 | - if(is_array($value[0])){ |
|
| 155 | + if (is_array($value[0])) { |
|
| 156 | 156 | |
| 157 | 157 | foreach ($value as $k => $v) { |
| 158 | 158 | $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
@@ -171,21 +171,21 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | private function mountSelect() |
| 173 | 173 | { |
| 174 | - $select = implode(',',array_keys($this->select)); |
|
| 174 | + $select = implode(',', array_keys($this->select)); |
|
| 175 | 175 | |
| 176 | - $this->query = str_replace('*', $select,$this->query); |
|
| 176 | + $this->query = str_replace('*', $select, $this->query); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | private function mountLimit() |
| 180 | 180 | { |
| 181 | - if(!is_null($this->limit)){ |
|
| 181 | + if (!is_null($this->limit)) { |
|
| 182 | 182 | $this->query .= " LIMIT {$this->limit}"; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | private function mountOffset() |
| 187 | 187 | { |
| 188 | - if(!is_null($this->offset)){ |
|
| 188 | + if (!is_null($this->offset)) { |
|
| 189 | 189 | $this->query .= " OFFSET {$this->offset}"; |
| 190 | 190 | } |
| 191 | 191 | } |