@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use PDOException; |
7 | 7 | use PDO; |
8 | 8 | |
9 | -trait CrudTrait{ |
|
9 | +trait CrudTrait { |
|
10 | 10 | |
11 | 11 | protected function transaction(string $transaction): ?int |
12 | 12 | { |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - protected function select(string $query,array $data): ?array |
|
26 | + protected function select(string $query, array $data): ?array |
|
27 | 27 | { |
28 | - try{ |
|
28 | + try { |
|
29 | 29 | $stmt = Connect::getInstance()->prepare("{$query}"); |
30 | 30 | $stmt->execute($data); |
31 | 31 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
32 | - }catch(Exception $exception){ |
|
32 | + } catch (Exception $exception) { |
|
33 | 33 | $this->fail = $exception; |
34 | 34 | } |
35 | 35 | return []; |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | |
38 | 38 | protected function describe(): ?array |
39 | 39 | { |
40 | - try{ |
|
40 | + try { |
|
41 | 41 | $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}"); |
42 | 42 | $stmt->execute(); |
43 | 43 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
44 | - }catch(Exception $exception){ |
|
44 | + } catch (Exception $exception) { |
|
45 | 45 | $this->fail = $exception; |
46 | 46 | return null; |
47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | try { |
53 | 53 | $columns = implode(", ", array_keys($data)); |
54 | - $values = ":" . implode(", :", array_keys($data)); |
|
54 | + $values = ":".implode(", :", array_keys($data)); |
|
55 | 55 | |
56 | 56 | $stmt = Connect::getInstance()->prepare("INSERT INTO {$this->table} ({$columns}) VALUES ({$values})"); |
57 | 57 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | try { |
89 | 89 | $stmt = Connect::getInstance()->prepare("DELETE FROM {$this->table} WHERE {$terms}"); |
90 | 90 | |
91 | - if($params){ |
|
91 | + if ($params) { |
|
92 | 92 | parse_str($params, $params); |
93 | 93 | $stmt->execute($params); |
94 | 94 | return true; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $stmt = Connect::getInstance()->prepare("{$query}"); |
30 | 30 | $stmt->execute($data); |
31 | 31 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
32 | - }catch(Exception $exception){ |
|
32 | + } catch(Exception $exception){ |
|
33 | 33 | $this->fail = $exception; |
34 | 34 | } |
35 | 35 | return []; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}"); |
42 | 42 | $stmt->execute(); |
43 | 43 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
44 | - }catch(Exception $exception){ |
|
44 | + } catch(Exception $exception){ |
|
45 | 45 | $this->fail = $exception; |
46 | 46 | return null; |
47 | 47 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | private ?string $clause = null; |
19 | 19 | |
20 | 20 | |
21 | - private array $where = [''=> ["1",'=',"1"] ]; |
|
21 | + private array $where = [''=> ["1", '=', "1"]]; |
|
22 | 22 | private ?string $order = null; |
23 | 23 | private ?string $limit = null; |
24 | 24 | private ?int $offset = null; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $this->primary = $primary; |
35 | 35 | $describe = $this->describe(); |
36 | 36 | |
37 | - if($this->fail){ |
|
37 | + if ($this->fail) { |
|
38 | 38 | throw $this->fail; |
39 | 39 | } |
40 | 40 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | case 'Type': |
57 | 57 | $type = $value; |
58 | 58 | |
59 | - if(strpos($value,'(')){ |
|
60 | - switch (substr($value,0,strpos($value,'('))) { |
|
59 | + if (strpos($value, '(')) { |
|
60 | + switch (substr($value, 0, strpos($value, '('))) { |
|
61 | 61 | case 'varchar': |
62 | 62 | case 'char': |
63 | 63 | case 'text': $type = 'string'; break; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | case 'string': |
79 | 79 | case 'float': |
80 | 80 | case 'int': |
81 | - $this->$field = ['maxlength' => substr($value,(strpos($value,'(')+1),-1) ]; |
|
81 | + $this->$field = ['maxlength' => substr($value, (strpos($value, '(') + 1), -1)]; |
|
82 | 82 | break; |
83 | 83 | case 'date': |
84 | 84 | $this->$field = ['maxlength' => 10]; |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | return $this; |
119 | 119 | } |
120 | 120 | |
121 | - public function __set(string $prop,$value): Datamanager |
|
121 | + public function __set(string $prop, $value): Datamanager |
|
122 | 122 | { |
123 | 123 | |
124 | - if(is_array($value)){ |
|
124 | + if (is_array($value)) { |
|
125 | 125 | $attr = array_keys($value)[0]; |
126 | 126 | $this->data[$prop][$attr] = $value[$attr]; |
127 | 127 | return $this; |
128 | 128 | } |
129 | 129 | |
130 | - if($this->full && !array_key_exists($prop,$this->data)){ |
|
130 | + if ($this->full && !array_key_exists($prop, $this->data)) { |
|
131 | 131 | throw new Exception("{$prop} field does not exist in the table {$this->table}."); |
132 | 132 | } |
133 | 133 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | public function __get(string $field) |
146 | 146 | { |
147 | - if($this->full && !array_key_exists($field,$this->data)){ |
|
147 | + if ($this->full && !array_key_exists($field, $this->data)) { |
|
148 | 148 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
149 | 149 | } |
150 | 150 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
162 | 162 | |
163 | 163 | foreach ($deniable as $field) { |
164 | - if(!array_key_exists($field,$this->data)){ |
|
164 | + if (!array_key_exists($field, $this->data)) { |
|
165 | 165 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
166 | 166 | } |
167 | 167 | |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | |
182 | 182 | public function orderBy(string $field, string $ord = 'ASC'): Datamanager |
183 | 183 | { |
184 | - if(!array_key_exists(str_replace(['asc','ASC','desc','DESC',' '],'',$field),$this->data) && $this->full){ |
|
184 | + if (!array_key_exists(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field), $this->data) && $this->full) { |
|
185 | 185 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
186 | 186 | } |
187 | 187 | |
188 | - if(strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')){ |
|
188 | + if (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) { |
|
189 | 189 | $ord = ''; |
190 | 190 | } |
191 | 191 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $params = (is_array($params)) ? $params : [$params]; |
199 | 199 | $this->select = []; |
200 | 200 | foreach ($params as $field) { |
201 | - if(!array_key_exists($field,$this->data) && $this->full){ |
|
201 | + if (!array_key_exists($field, $this->data) && $this->full) { |
|
202 | 202 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
203 | 203 | } |
204 | 204 | |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | |
211 | 211 | public function where(array $where): Datamanager |
212 | 212 | { |
213 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
213 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
214 | 214 | $w = []; |
215 | 215 | foreach ($where as $condition => $values) { |
216 | 216 | |
217 | 217 | |
218 | - if(is_array($values)){ |
|
219 | - if(count($values) != 3){ |
|
220 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$values)); |
|
218 | + if (is_array($values)) { |
|
219 | + if (count($values) != 3) { |
|
220 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $values)); |
|
221 | 221 | } |
222 | 222 | |
223 | - if(!array_key_exists($values[0],$this->data) && $this->full){ |
|
223 | + if (!array_key_exists($values[0], $this->data) && $this->full) { |
|
224 | 224 | throw new Exception("{$values[0]} field does not exist in the table {$this->table}."); |
225 | 225 | } |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $w['AND'][] = $values; |
233 | 233 | } |
234 | 234 | |
235 | - $this->where = array_merge($this->where,$w); |
|
235 | + $this->where = array_merge($this->where, $w); |
|
236 | 236 | |
237 | 237 | return $this; |
238 | 238 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | public function offset(int $offset): Datamanager |
247 | 247 | { |
248 | - if(is_null($this->limit)){ |
|
248 | + if (is_null($this->limit)) { |
|
249 | 249 | throw new Exception("The limit must be set before the offset."); |
250 | 250 | } |
251 | 251 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | foreach ($arrayValues as $key => $value) { |
277 | 277 | |
278 | - if(!array_key_exists($key,$this->data)){ |
|
278 | + if (!array_key_exists($key, $this->data)) { |
|
279 | 279 | throw new Exception("{$key} field does not exist in the table {$this->table}."); |
280 | 280 | } |
281 | 281 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $string = ''; |
290 | 290 | foreach ($this->data as $key => $value) { |
291 | 291 | |
292 | - if(gettype($value)==='object'){ |
|
292 | + if (gettype($value) === 'object') { |
|
293 | 293 | $value = $value->getData()[$this->primary]['value']; |
294 | 294 | } |
295 | 295 | |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | |
301 | 301 | public function remove(?bool $exec = false): Datamanager |
302 | 302 | { |
303 | - if($exec){ |
|
303 | + if ($exec) { |
|
304 | 304 | $this->clause = null; |
305 | 305 | |
306 | - if(count($this->where) == 1){ |
|
306 | + if (count($this->where) == 1) { |
|
307 | 307 | $this->removeById(); |
308 | 308 | return $this; |
309 | 309 | } |
310 | 310 | |
311 | 311 | $where = ''; |
312 | 312 | $data = ''; |
313 | - foreach($this->where as $clause => $condition){ |
|
314 | - if(strlen($clause) === 0){ |
|
313 | + foreach ($this->where as $clause => $condition) { |
|
314 | + if (strlen($clause) === 0) { |
|
315 | 315 | $where .= " {$clause} "; |
316 | 316 | $where .= " {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
317 | 317 | $data .= "q_{$condition[0]}={$condition[2]}&"; |
318 | 318 | continue; |
319 | 319 | } |
320 | 320 | |
321 | - foreach($condition as $column => $value){ |
|
321 | + foreach ($condition as $column => $value) { |
|
322 | 322 | $where .= " {$clause} "; |
323 | 323 | $where .= " {$value[0]} {$value[1]} :q_{$value[0]} "; |
324 | 324 | $data .= "q_{$value[0]}={$value[2]}&"; |
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | - $data = substr($data,0,-1); |
|
329 | - if(!$this->delete($where,$data)){ |
|
328 | + $data = substr($data, 0, -1); |
|
329 | + if (!$this->delete($where, $data)) { |
|
330 | 330 | throw $this->fail; |
331 | 331 | } |
332 | 332 | |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | |
341 | 341 | private function removeById(): bool |
342 | 342 | { |
343 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
343 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
344 | 344 | |
345 | - if($this->fail){ |
|
345 | + if ($this->fail) { |
|
346 | 346 | throw $this->fail; |
347 | 347 | } |
348 | 348 | |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | { |
354 | 354 | $data = []; |
355 | 355 | foreach ($this->data as $key => $value) { |
356 | - if($this->data[$key]['key'] === 'PRI' || strstr($this->data[$key]['extra'],'auto_increment')){ |
|
356 | + if ($this->data[$key]['key'] === 'PRI' || strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
357 | 357 | continue; |
358 | 358 | } |
359 | 359 | |
360 | - if($this->data[$key]['changed'] && $this->data[$key]['upgradeable']){ |
|
360 | + if ($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) { |
|
361 | 361 | $data[$key] = $this->data[$key]['value']; |
362 | 362 | } |
363 | 363 | } |
@@ -366,15 +366,15 @@ discard block |
||
366 | 366 | $params = $this->primary.'='.$this->getData()[$this->primary]['value']; |
367 | 367 | |
368 | 368 | $this->transaction('begin'); |
369 | - try{ |
|
369 | + try { |
|
370 | 370 | $this->update($data, $terms, $params); |
371 | 371 | |
372 | - if($this->fail){ |
|
372 | + if ($this->fail) { |
|
373 | 373 | throw $this->fail; |
374 | 374 | } |
375 | 375 | |
376 | 376 | $this->transaction('commit'); |
377 | - }catch(Exception $er){ |
|
377 | + } catch (Exception $er) { |
|
378 | 378 | $this->transaction('rollback'); |
379 | 379 | throw $er; |
380 | 380 | } |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | $data = []; |
390 | 390 | |
391 | 391 | foreach ($this->data as $key => $value) { |
392 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
392 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
393 | 393 | continue; |
394 | 394 | } |
395 | 395 | |
396 | - if(strlen($value['value']) > $value['maxlength']){ |
|
396 | + if (strlen($value['value']) > $value['maxlength']) { |
|
397 | 397 | throw new Exception("The information provided for column {$key} of table {$this->table} exceeded that allowed."); |
398 | 398 | } |
399 | 399 | |
@@ -402,15 +402,15 @@ discard block |
||
402 | 402 | $data[$key] = $value['value']; |
403 | 403 | } |
404 | 404 | |
405 | - $columns = substr($columns,0,-1); |
|
406 | - $values = substr($values,0,-1); |
|
405 | + $columns = substr($columns, 0, -1); |
|
406 | + $values = substr($values, 0, -1); |
|
407 | 407 | |
408 | 408 | $this->transaction('begin'); |
409 | - try{ |
|
409 | + try { |
|
410 | 410 | |
411 | 411 | $id = $this->insert($data); |
412 | 412 | |
413 | - if($this->fail){ |
|
413 | + if ($this->fail) { |
|
414 | 414 | throw $this->fail; |
415 | 415 | } |
416 | 416 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | $this->transaction('commit'); |
420 | 420 | |
421 | - }catch(Exception $er){ |
|
421 | + } catch (Exception $er) { |
|
422 | 422 | $this->transaction('rollback'); |
423 | 423 | throw $er; |
424 | 424 | } |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | { |
431 | 431 | $entity = null; |
432 | 432 | |
433 | - if($this->getCount() === 0){ |
|
433 | + if ($this->getCount() === 0) { |
|
434 | 434 | return null; |
435 | 435 | } |
436 | 436 | |
437 | 437 | $entity = $this->setByDatabase($this->result[0]); |
438 | 438 | |
439 | - if(count($this->result) > 1){ |
|
439 | + if (count($this->result) > 1) { |
|
440 | 440 | $entity = []; |
441 | 441 | foreach ($this->result as $key => $value) { |
442 | 442 | $entity[] = $this->setByDatabase($value); |
@@ -448,14 +448,14 @@ discard block |
||
448 | 448 | |
449 | 449 | public function findById($id): Datamanager |
450 | 450 | { |
451 | - $this->where([$this->primary,'=',$id]); |
|
451 | + $this->where([$this->primary, '=', $id]); |
|
452 | 452 | return $this; |
453 | 453 | } |
454 | 454 | |
455 | 455 | public function execute(): Datamanager |
456 | 456 | { |
457 | - if(!is_null($this->clause)){ |
|
458 | - if($this->clause == 'remove'){ |
|
457 | + if (!is_null($this->clause)) { |
|
458 | + if ($this->clause == 'remove') { |
|
459 | 459 | return $this->remove(true); |
460 | 460 | } |
461 | 461 | } |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | $select .= "{$key},"; |
468 | 468 | } |
469 | 469 | |
470 | - $select = substr($select,0,-1); |
|
471 | - $this->query = str_replace("*",$select,$this->query); |
|
470 | + $select = substr($select, 0, -1); |
|
471 | + $this->query = str_replace("*", $select, $this->query); |
|
472 | 472 | |
473 | 473 | $where = ''; |
474 | 474 | $whereData = []; |
@@ -476,33 +476,33 @@ discard block |
||
476 | 476 | $key = (!$key) ? '' : " {$key} "; |
477 | 477 | |
478 | 478 | |
479 | - if(is_array($value[0])){ |
|
479 | + if (is_array($value[0])) { |
|
480 | 480 | foreach ($value as $k => $v) { |
481 | 481 | $where .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
482 | 482 | $whereData["q_{$v[0]}"] = $v[2]; |
483 | 483 | } |
484 | - }else{ |
|
484 | + } else { |
|
485 | 485 | $where .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]} "; |
486 | 486 | $whereData["q_{$value[0]}"] = $value[2]; |
487 | 487 | } |
488 | 488 | |
489 | 489 | } |
490 | - $where = substr($where,0,-1); |
|
490 | + $where = substr($where, 0, -1); |
|
491 | 491 | $this->query .= " WHERE {$where} "; |
492 | 492 | |
493 | 493 | $this->query .= $this->order; |
494 | 494 | |
495 | - if(!is_null($this->limit)){ |
|
495 | + if (!is_null($this->limit)) { |
|
496 | 496 | $this->query .= " LIMIT {$this->limit}"; |
497 | 497 | } |
498 | 498 | |
499 | - if(!is_null($this->offset)){ |
|
499 | + if (!is_null($this->offset)) { |
|
500 | 500 | $this->query .= " OFFSET {$this->offset}"; |
501 | 501 | } |
502 | 502 | |
503 | - $this->result = $this->select($this->query,$whereData); |
|
503 | + $this->result = $this->select($this->query, $whereData); |
|
504 | 504 | |
505 | - if($this->fail){ |
|
505 | + if ($this->fail) { |
|
506 | 506 | throw $this->fail; |
507 | 507 | } |
508 | 508 | |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | { |
517 | 517 | $this->query = " SELECT * FROM {$this->table} "; |
518 | 518 | |
519 | - if(is_int($key)){ |
|
519 | + if (is_int($key)) { |
|
520 | 520 | return $this->findById($key); |
521 | 521 | } |
522 | 522 |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | $this->transaction('commit'); |
377 | - }catch(Exception $er){ |
|
377 | + } catch(Exception $er){ |
|
378 | 378 | $this->transaction('rollback'); |
379 | 379 | throw $er; |
380 | 380 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | $this->transaction('commit'); |
420 | 420 | |
421 | - }catch(Exception $er){ |
|
421 | + } catch(Exception $er){ |
|
422 | 422 | $this->transaction('rollback'); |
423 | 423 | throw $er; |
424 | 424 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | $where .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
482 | 482 | $whereData["q_{$v[0]}"] = $v[2]; |
483 | 483 | } |
484 | - }else{ |
|
484 | + } else{ |
|
485 | 485 | $where .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]} "; |
486 | 486 | $whereData["q_{$value[0]}"] = $value[2]; |
487 | 487 | } |
@@ -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 |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Datamanager\Datamanager; |
6 | 6 | |
7 | -class User extends Datamanager{ |
|
7 | +class User extends Datamanager { |
|
8 | 8 | |
9 | 9 | public function __construct() |
10 | 10 | { |
11 | - parent::create('user','id'); |
|
11 | + parent::create('user', 'id'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -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($er->getCode().' - '.$er->getMessage()); |
52 | 52 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | ['name','=','Other Name'], |
47 | 47 | 'OR' => ['email','LIKE','[email protected]'] |
48 | 48 | ])->execute(); |
49 | -}catch(Exception $er){ |
|
49 | +} catch(Exception $er){ |
|
50 | 50 | |
51 | 51 | die($er->getCode().' - '.$er->getMessage()); |
52 | 52 |