@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | |
| 5 | -class Field{ |
|
| 5 | +class Field { |
|
| 6 | 6 | |
| 7 | 7 | protected array $default_error_messages = array( |
| 8 | 8 | "invalid_choice" => "Value %value is not a valid choice.", |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - protected function validate($value){ |
|
| 36 | + protected function validate($value) { |
|
| 37 | 37 | if (is_null($value) && (!$this->null)) return false; |
| 38 | 38 | if (empty($value) && (!$this->blank)) return false; |
| 39 | 39 | if (!empty($this->choices) && !in_array($value, $this->choices)) return false; |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - private function validate_with_validators($value){ |
|
| 47 | - foreach($this->validators as $validator){ |
|
| 46 | + private function validate_with_validators($value) { |
|
| 47 | + foreach ($this->validators as $validator) { |
|
| 48 | 48 | if (!$validator($value)) return false; |
| 49 | 49 | } |
| 50 | 50 | return true; |
@@ -2,17 +2,17 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class TextField extends Field{ |
|
| 5 | +class TextField extends Field { |
|
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - public function __construct(private $max_length = 128, ...$options ){ |
|
| 9 | + public function __construct(private $max_length = 128, ...$options) { |
|
| 10 | 10 | parent::__construct(...$options); |
| 11 | 11 | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function validate($value){ |
|
| 15 | - if(strlen($value) > $this->max_length) return false; |
|
| 14 | + public function validate($value) { |
|
| 15 | + if (strlen($value) > $this->max_length) return false; |
|
| 16 | 16 | return parent::validate($value); |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -2,12 +2,12 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class DateField extends Field{ |
|
| 6 | - public function __construct(...$args){ |
|
| 5 | +class DateField extends Field { |
|
| 6 | + public function __construct(...$args) { |
|
| 7 | 7 | parent::__construct(...$args); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 10 | + public function validate($value) { |
|
| 11 | 11 | if (!preg_match("/\d{4}-\d{2}-\d{2}/", $value)) return false; |
| 12 | 12 | return parent::validate($value); |
| 13 | 13 | } |
@@ -2,13 +2,13 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class NumberField extends Field{ |
|
| 6 | - public function __construct(mixed ...$options){ |
|
| 5 | +class NumberField extends Field { |
|
| 6 | + public function __construct(mixed ...$options) { |
|
| 7 | 7 | parent::__construct(...$options); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 11 | - if(!is_numeric($value)) return false; |
|
| 10 | + public function validate($value) { |
|
| 11 | + if (!is_numeric($value)) return false; |
|
| 12 | 12 | return parent::validate($value); |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -2,14 +2,14 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class PrimaryKey extends Field{ |
|
| 6 | - public function __construct(mixed ...$options){ |
|
| 5 | +class PrimaryKey extends Field { |
|
| 6 | + public function __construct(mixed ...$options) { |
|
| 7 | 7 | $this->null = false; |
| 8 | 8 | parent::__construct(...$options); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | - public function validate($value){ |
|
| 12 | - if(!is_numeric($value)) return false; |
|
| 11 | + public function validate($value) { |
|
| 12 | + if (!is_numeric($value)) return false; |
|
| 13 | 13 | return parent::validate($value); |
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | \ No newline at end of file |
@@ -2,12 +2,12 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class DateTimeField extends Field{ |
|
| 6 | - public function __construct(...$args){ |
|
| 5 | +class DateTimeField extends Field { |
|
| 6 | + public function __construct(...$args) { |
|
| 7 | 7 | parent::__construct(...$args); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public function validate($value){ |
|
| 10 | + public function validate($value) { |
|
| 11 | 11 | if (!preg_match("/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/", $value)) return false; |
| 12 | 12 | return parent::validate($value); |
| 13 | 13 | } |
@@ -2,16 +2,16 @@ |
||
| 2 | 2 | namespace Lepton\Boson\DataTypes; |
| 3 | 3 | |
| 4 | 4 | #[\Attribute] |
| 5 | -class JSONField extends Field{ |
|
| 5 | +class JSONField extends Field { |
|
| 6 | 6 | |
| 7 | 7 | |
| 8 | - public function __construct(...$options ){ |
|
| 8 | + public function __construct(...$options) { |
|
| 9 | 9 | parent::__construct(...$options); |
| 10 | 10 | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - public function validate($value){ |
|
| 14 | - if(!is_array(json_decode($value, true))) return false; |
|
| 13 | + public function validate($value) { |
|
| 14 | + if (!is_array(json_decode($value, true))) return false; |
|
| 15 | 15 | return parent::validate($value); |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | public function rewind(): void |
| 179 | 179 | { |
| 180 | 180 | $this->index = -1; |
| 181 | - if (! isset($this->result)) { |
|
| 181 | + if (!isset($this->result)) { |
|
| 182 | 182 | $this->cache = array(); |
| 183 | 183 | $this->do(); |
| 184 | 184 | } |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | $db_columns = $this->current->db_columns(); |
| 220 | 220 | // Convert column names to field names |
| 221 | 221 | $fields = array(); |
| 222 | - foreach($items as $column => $value){ |
|
| 223 | - $fieldName = array_search($column ,$db_columns); |
|
| 222 | + foreach ($items as $column => $value) { |
|
| 223 | + $fieldName = array_search($column, $db_columns); |
|
| 224 | 224 | $fields[$fieldName] = $value; |
| 225 | 225 | } |
| 226 | 226 | $this->current->load(...$fields); |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $this->current->clearEditedFields(); |
| 229 | 229 | } else { |
| 230 | 230 | $this->current = null; |
| 231 | - $this->index = -1; |
|
| 231 | + $this->index = -1; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | public function first() |
| 241 | 241 | { |
| 242 | - if(!isset($this->cache)) { |
|
| 242 | + if (!isset($this->cache)) { |
|
| 243 | 243 | $this->rewind(); |
| 244 | 244 | } |
| 245 | 245 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $this->modifiers["ORDER BY"] = []; |
| 387 | - foreach($filters as $filter){ |
|
| 387 | + foreach ($filters as $filter) { |
|
| 388 | 388 | $this->modifiers["ORDER BY"][] = is_array($filter) ? $filter : [$filter => "ASC"]; |
| 389 | 389 | } |
| 390 | 390 | $this->modifiers["ORDER BY"] = $filters; |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | public function count(): int |
| 405 | 405 | { |
| 406 | - if (! isset($this->result)) { |
|
| 406 | + if (!isset($this->result)) { |
|
| 407 | 407 | $this->do(); |
| 408 | 408 | } |
| 409 | 409 | return $this->result->num_rows; |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | |
| 440 | 440 | // Get the result |
| 441 | - $this->result = $result->fetch_result() ; |
|
| 441 | + $this->result = $result->fetch_result(); |
|
| 442 | 442 | return $this; |
| 443 | 443 | } |
| 444 | 444 | |
@@ -473,12 +473,12 @@ discard block |
||
| 473 | 473 | $modifiers = ""; |
| 474 | 474 | |
| 475 | 475 | // it there are any ORDER BY, build the clause |
| 476 | - if (count($this->modifiers)> 0) { |
|
| 476 | + if (count($this->modifiers) > 0) { |
|
| 477 | 477 | list($modifiers, $join) = $this->buildModifiers(); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | // if there are any filters build WHERE clause |
| 481 | - if (count($this->filters)> 0) { |
|
| 481 | + if (count($this->filters) > 0) { |
|
| 482 | 482 | list($whereClause, $values, $join_t) = $this->buildWhereClause($this->filters); |
| 483 | 483 | } |
| 484 | 484 | |
@@ -488,12 +488,12 @@ discard block |
||
| 488 | 488 | $query .= " ".$this->buildJoin($join); |
| 489 | 489 | $query .= " ".$this->buildJoin($join_t); |
| 490 | 490 | |
| 491 | - if(count($this->filters)>0){ |
|
| 491 | + if (count($this->filters) > 0) { |
|
| 492 | 492 | $query .= sprintf(" WHERE %s ", $whereClause); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // it there are any ORDER BY, build the clause |
| 496 | - if (count($this->modifiers)> 0) { |
|
| 496 | + if (count($this->modifiers) > 0) { |
|
| 497 | 497 | $query .= sprintf(" ORDER BY %s", $modifiers); |
| 498 | 498 | } |
| 499 | 499 | |
@@ -523,10 +523,10 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | $clause = array(); |
| 525 | 525 | for ($i = 1; $i < count($join); $i++) { |
| 526 | - $clause[] = sprintf( |
|
| 526 | + $clause[] = sprintf( |
|
| 527 | 527 | " %s ON %s.%s = %s.%s", |
| 528 | 528 | $join[$i]["table"], |
| 529 | - $join[$i-1]["table"], |
|
| 529 | + $join[$i - 1]["table"], |
|
| 530 | 530 | $join[$i]["column"], |
| 531 | 531 | $join[$i]["table"], |
| 532 | 532 | $join[$i]["column"] |
@@ -548,8 +548,8 @@ discard block |
||
| 548 | 548 | $conditions = array(); |
| 549 | 549 | $join = array(); |
| 550 | 550 | |
| 551 | - foreach($order_by as $order_clause) { |
|
| 552 | - if(is_array($order_clause)) { |
|
| 551 | + foreach ($order_by as $order_clause) { |
|
| 552 | + if (is_array($order_clause)) { |
|
| 553 | 553 | $raw = array_key_first($order_clause); |
| 554 | 554 | $method = $order_clause[$raw]; |
| 555 | 555 | } else { |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | $values = array(); |
| 609 | 609 | $join = array(); |
| 610 | 610 | |
| 611 | - foreach($filters as $key => $value) { |
|
| 611 | + foreach ($filters as $key => $value) { |
|
| 612 | 612 | $lookup = $this->lookup($key); |
| 613 | 613 | |
| 614 | 614 | $column = $lookup["column"]; |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | // Now match has only joins |
| 657 | 657 | $join = array(); |
| 658 | 658 | foreach ($match as $k) { |
| 659 | - if($last->isForeignKey($k)) { |
|
| 660 | - $new= new ($last->getRelationshipParentModel($k))(); |
|
| 659 | + if ($last->isForeignKey($k)) { |
|
| 660 | + $new = new ($last->getRelationshipParentModel($k))(); |
|
| 661 | 661 | |
| 662 | 662 | $join[] = array( |
| 663 | 663 | "column"=> $last->getColumnFromField($k), |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
| 24 | 24 | if ($this->connection->connect_error) { |
| 25 | - $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
| 25 | + $this->error('Failed to connect to MySQL - '.$this->connection->connect_error); |
|
| 26 | 26 | } |
| 27 | 27 | $this->connection->set_charset($charset); |
| 28 | 28 | } |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $this->query->execute(); |
| 50 | 50 | if ($this->query->errno) { |
| 51 | - $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error); |
|
| 51 | + $this->error('Unable to process MySQL query (check your params) - '.$this->query->error); |
|
| 52 | 52 | } |
| 53 | 53 | $this->query_closed = FALSE; |
| 54 | 54 | } else { |
| 55 | - $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
| 55 | + $this->error('Unable to prepare MySQL statement (check your syntax) - '.$this->connection->error); |
|
| 56 | 56 | } |
| 57 | 57 | return $this; |
| 58 | 58 | } |