@@ -3,4 +3,4 @@ |
||
3 | 3 | |
4 | 4 | use Exception; |
5 | 5 | |
6 | -class InvalidFieldTypeException extends Exception{} |
|
7 | 6 | \ No newline at end of file |
7 | +class InvalidFieldTypeException extends Exception {} |
|
8 | 8 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
7 | 7 | |
8 | 8 | class FieldException extends Exception{ |
9 | 9 | |
10 | - public function __construct(\ReflectionProperty $prop, $message = "", $code = 0, ?\Throwable $previous = null){ |
|
10 | + public function __construct(\ReflectionProperty $prop, $message = "", $code = 0, ?\Throwable $previous = null){ |
|
11 | 11 | |
12 | 12 | $this->line = Functions::getDeclarationLine($prop); |
13 | 13 | $this->file = $prop->getDeclaringClass()->getFileName(); |
14 | 14 | parent::__construct($message, $code, $previous); |
15 | - } |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -5,9 +5,9 @@ |
||
5 | 5 | use Throwable; |
6 | 6 | use Lepton\Helpers\Functions; |
7 | 7 | |
8 | -class FieldException extends Exception{ |
|
8 | +class FieldException extends Exception { |
|
9 | 9 | |
10 | - public function __construct(\ReflectionProperty $prop, $message = "", $code = 0, ?\Throwable $previous = null){ |
|
10 | + public function __construct(\ReflectionProperty $prop, $message = "", $code = 0, ?\Throwable $previous = null) { |
|
11 | 11 | |
12 | 12 | $this->line = Functions::getDeclarationLine($prop); |
13 | 13 | $this->file = $prop->getDeclaringClass()->getFileName(); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * The reverse OneToMany and OneToOne relationships of the model. |
27 | 27 | * @var array |
28 | - */ |
|
28 | + */ |
|
29 | 29 | |
30 | 30 | private array $reverseForeignKeys; |
31 | 31 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * Update the data in the database using prepared queries. |
494 | 494 | * |
495 | 495 | * @return bool |
496 | - */ |
|
496 | + */ |
|
497 | 497 | private function update() |
498 | 498 | { |
499 | 499 | $db = Application::getDb(); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | if (!isset(static::$tableName)) { |
102 | 102 | $class = new \ReflectionClass(get_class($this)); |
103 | 103 | try { |
104 | - $className = explode("\\", $class->getName()); |
|
104 | + $className = explode("\\", $class->getName()); |
|
105 | 105 | static::$tableName = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', end($className))); |
106 | 106 | } catch (\Exception $e) { |
107 | 107 | throw new Exceptions\TableNameNotSetException($class); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $this->pkName = $maybeField->getName(); |
140 | 140 | |
141 | 141 | // If column name is not set, use field name |
142 | - if($field->db_column() == "") { |
|
142 | + if ($field->db_column() == "") { |
|
143 | 143 | $field->set_db_column($maybeField->getName()); |
144 | 144 | } |
145 | 145 | } |
@@ -150,12 +150,12 @@ discard block |
||
150 | 150 | elseif ($fieldType->getName() == DataTypes\ForeignKey::class) { |
151 | 151 | $this->foreignKeys[$maybeField->getName()] = $field; |
152 | 152 | // If column name is not set, build it as {fieldName}_{parentPrimaryKeyName} |
153 | - if($field->db_column() == "") { |
|
153 | + if ($field->db_column() == "") { |
|
154 | 154 | $props = (new \ReflectionClass($field->parent))->getProperties(\ReflectionProperty::IS_PROTECTED); |
155 | 155 | $parentPkName = ""; |
156 | - foreach($props as $prop) { |
|
156 | + foreach ($props as $prop) { |
|
157 | 157 | $attributes = $prop->getAttributes(DataTypes\PrimaryKey::class); |
158 | - if(count($attributes)) { |
|
158 | + if (count($attributes)) { |
|
159 | 159 | $parentPkName = $prop->getName(); |
160 | 160 | } |
161 | 161 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $this->fields[$maybeField->getName()] = $field; |
177 | 177 | |
178 | 178 | // If column name is not set, use field name |
179 | - if($field->db_column() == "") { |
|
179 | + if ($field->db_column() == "") { |
|
180 | 180 | $field->set_db_column($maybeField->getName()); |
181 | 181 | } |
182 | 182 | $this->db_columns[$maybeField->getName()] = $field->db_column(); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | if (is_subclass_of(($attribute->getName()), DataTypes\Field::class)) { |
242 | 242 | // A field should have only one field type |
243 | 243 | if (is_null($fieldType)) { |
244 | - $fieldType = $attribute; |
|
244 | + $fieldType = $attribute; |
|
245 | 245 | } else { |
246 | 246 | throw new Exceptions\MultipleFieldAttributeException($prop); |
247 | 247 | } |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | private function checkFieldsAreProtected() |
265 | 265 | { |
266 | 266 | $properties = (new \ReflectionClass(get_class($this)))->getProperties( |
267 | - \ReflectionProperty::IS_PUBLIC | |
|
268 | - \ReflectionProperty::IS_READONLY | |
|
267 | + \ReflectionProperty::IS_PUBLIC| |
|
268 | + \ReflectionProperty::IS_READONLY| |
|
269 | 269 | \ReflectionProperty::IS_STATIC |
270 | 270 | ); |
271 | 271 | foreach ($properties as $prop) { |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | return $parent; |
302 | 302 | } elseif ($property == $this->pkName) { |
303 | 303 | return $this->getPk(); |
304 | - } elseif($this->isReverseForeignKey($property)) { |
|
304 | + } elseif ($this->isReverseForeignKey($property)) { |
|
305 | 305 | $child = $this->reverseForeignKeys[$property]->child; |
306 | 306 | $arguments = [ |
307 | 307 | $this->reverseForeignKeys[$property]->foreignKey => $this |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | |
575 | 575 | public static function get(...$filters): Model|bool |
576 | 576 | { |
577 | - if ((count($filters) == 1) && array_key_first($filters) == 0) { |
|
577 | + if ((count($filters) == 1) && array_key_first($filters) == 0) { |
|
578 | 578 | $filters = array((new static())->pkName => $filters[0]); |
579 | 579 | } |
580 | 580 | |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | |
585 | 585 | $result = $querySet->do(); |
586 | 586 | if ($result->count() == 0) { |
587 | - return false;//throw new \Exception("No result found"); |
|
587 | + return false; //throw new \Exception("No result found"); |
|
588 | 588 | } elseif ($result->count() > 1) { |
589 | 589 | throw new \Exception("Only one result allowed when using get, multiple obtained"); |
590 | 590 | } else { |
@@ -4,48 +4,48 @@ |
||
4 | 4 | |
5 | 5 | class Field{ |
6 | 6 | |
7 | - protected array $default_error_messages = array( |
|
7 | + protected array $default_error_messages = array( |
|
8 | 8 | "invalid_choice" => "Value %value is not a valid choice.", |
9 | 9 | "null" => "This field cannot be null.", |
10 | 10 | "blank" => "This field cannot be blank.", |
11 | 11 | "unique" => "A %model_name with this %field_label already exists.", |
12 | 12 | "unique_for" => "Field %field_label must be unique for fields with same %unique_for." |
13 | - ); |
|
14 | - |
|
15 | - protected array $validation_errors = array(); |
|
16 | - |
|
17 | - public function __construct( |
|
18 | - protected bool $null = false, |
|
19 | - protected bool $blank = true, |
|
20 | - protected array $choices = array(), |
|
21 | - protected string $db_column = "", |
|
22 | - protected mixed $default = "", |
|
23 | - protected bool $editable = true, |
|
24 | - protected array $error_messages = array(), |
|
25 | - protected string $help_text = "", |
|
26 | - protected bool $primary_key = false, |
|
27 | - protected bool $unique = false, |
|
28 | - protected string $unique_for = "", |
|
29 | - protected string $verbose_name = "", |
|
30 | - protected array $validators = array() |
|
13 | + ); |
|
14 | + |
|
15 | + protected array $validation_errors = array(); |
|
16 | + |
|
17 | + public function __construct( |
|
18 | + protected bool $null = false, |
|
19 | + protected bool $blank = true, |
|
20 | + protected array $choices = array(), |
|
21 | + protected string $db_column = "", |
|
22 | + protected mixed $default = "", |
|
23 | + protected bool $editable = true, |
|
24 | + protected array $error_messages = array(), |
|
25 | + protected string $help_text = "", |
|
26 | + protected bool $primary_key = false, |
|
27 | + protected bool $unique = false, |
|
28 | + protected string $unique_for = "", |
|
29 | + protected string $verbose_name = "", |
|
30 | + protected array $validators = array() |
|
31 | 31 | ) |
32 | - { |
|
32 | + { |
|
33 | 33 | return; |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - protected function check(){ |
|
37 | + protected function check(){ |
|
38 | 38 | return true; |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - public function db_column(): string{ |
|
44 | + public function db_column(): string{ |
|
45 | 45 | return $this->db_column; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public function set_db_column(string $column_name): void{ |
|
48 | + public function set_db_column(string $column_name): void{ |
|
49 | 49 | $this->db_column = $column_name; |
50 | - } |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -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.", |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | |
37 | - protected function check(){ |
|
37 | + protected function check() { |
|
38 | 38 | return true; |
39 | 39 | } |
40 | 40 |
@@ -3,12 +3,12 @@ |
||
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | 5 | class DateField extends Field{ |
6 | - public function __construct(...$args){ |
|
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 | return true; |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | 14 | } |
15 | 15 | \ 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 | return true; |
12 | 12 | } |
13 | 13 |
@@ -3,12 +3,12 @@ |
||
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | 5 | class PrimaryKey extends Field{ |
6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
6 | + public function __construct(private int $max_length = 32, mixed ...$options){ |
|
7 | 7 | parent::__construct(...$options); |
8 | - } |
|
8 | + } |
|
9 | 9 | |
10 | - public function validate($value){ |
|
10 | + public function validate($value){ |
|
11 | 11 | if(is_null($value) && (!$this->null)) return false; |
12 | 12 | return true; |
13 | - } |
|
13 | + } |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -2,13 +2,13 @@ |
||
2 | 2 | namespace Lepton\Boson\DataTypes; |
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | -class PrimaryKey extends Field{ |
|
6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
5 | +class PrimaryKey extends Field { |
|
6 | + public function __construct(private int $max_length = 32, mixed ...$options) { |
|
7 | 7 | parent::__construct(...$options); |
8 | 8 | } |
9 | 9 | |
10 | - public function validate($value){ |
|
11 | - if(is_null($value) && (!$this->null)) return false; |
|
10 | + public function validate($value) { |
|
11 | + if (is_null($value) && (!$this->null)) return false; |
|
12 | 12 | return true; |
13 | 13 | } |
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -8,7 +8,9 @@ |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | public function validate($value){ |
11 | - if(is_null($value) && (!$this->null)) return false; |
|
11 | + if(is_null($value) && (!$this->null)) { |
|
12 | + return false; |
|
13 | + } |
|
12 | 14 | return true; |
13 | 15 | } |
14 | 16 | } |
15 | 17 | \ No newline at end of file |
@@ -3,12 +3,12 @@ |
||
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | 5 | class NumberField extends Field{ |
6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
6 | + public function __construct(private int $max_length = 32, mixed ...$options){ |
|
7 | 7 | parent::__construct(...$options); |
8 | - } |
|
8 | + } |
|
9 | 9 | |
10 | - public function validate($value){ |
|
10 | + public function validate($value){ |
|
11 | 11 | if(is_null($value) && (!$this->null)) return false; |
12 | 12 | return true; |
13 | - } |
|
13 | + } |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -2,13 +2,13 @@ |
||
2 | 2 | namespace Lepton\Boson\DataTypes; |
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | -class NumberField extends Field{ |
|
6 | - public function __construct(private int $max_length = 32, mixed ...$options){ |
|
5 | +class NumberField extends Field { |
|
6 | + public function __construct(private int $max_length = 32, mixed ...$options) { |
|
7 | 7 | parent::__construct(...$options); |
8 | 8 | } |
9 | 9 | |
10 | - public function validate($value){ |
|
11 | - if(is_null($value) && (!$this->null)) return false; |
|
10 | + public function validate($value) { |
|
11 | + if (is_null($value) && (!$this->null)) return false; |
|
12 | 12 | return true; |
13 | 13 | } |
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -8,7 +8,9 @@ |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | public function validate($value){ |
11 | - if(is_null($value) && (!$this->null)) return false; |
|
11 | + if(is_null($value) && (!$this->null)) { |
|
12 | + return false; |
|
13 | + } |
|
12 | 14 | return true; |
13 | 15 | } |
14 | 16 | } |
15 | 17 | \ No newline at end of file |
@@ -5,18 +5,18 @@ |
||
5 | 5 | class TextField extends Field{ |
6 | 6 | |
7 | 7 | |
8 | - private $max_length; |
|
9 | - private $nullable; |
|
8 | + private $max_length; |
|
9 | + private $nullable; |
|
10 | 10 | |
11 | - public function __construct($max_length = 128, $nullable = false ){ |
|
11 | + public function __construct($max_length = 128, $nullable = false ){ |
|
12 | 12 | $this->max_length = $max_length; |
13 | 13 | $this->nullable = $nullable; |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - public function validate($value){ |
|
16 | + public function validate($value){ |
|
17 | 17 | return true; |
18 | 18 | if(is_null($value) && (!$this->nullable)) return false; |
19 | 19 | if(strlen($value) > $this->max_length) return false; |
20 | 20 | return true; |
21 | - } |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -2,21 +2,21 @@ |
||
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 | private $max_length; |
9 | 9 | private $nullable; |
10 | 10 | |
11 | - public function __construct($max_length = 128, $nullable = false ){ |
|
11 | + public function __construct($max_length = 128, $nullable = false) { |
|
12 | 12 | $this->max_length = $max_length; |
13 | 13 | $this->nullable = $nullable; |
14 | 14 | } |
15 | 15 | |
16 | - public function validate($value){ |
|
16 | + public function validate($value) { |
|
17 | 17 | return true; |
18 | - if(is_null($value) && (!$this->nullable)) return false; |
|
19 | - if(strlen($value) > $this->max_length) return false; |
|
18 | + if (is_null($value) && (!$this->nullable)) return false; |
|
19 | + if (strlen($value) > $this->max_length) return false; |
|
20 | 20 | return true; |
21 | 21 | } |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -15,8 +15,12 @@ |
||
15 | 15 | |
16 | 16 | public function validate($value){ |
17 | 17 | return true; |
18 | - if(is_null($value) && (!$this->nullable)) return false; |
|
19 | - if(strlen($value) > $this->max_length) return false; |
|
18 | + if(is_null($value) && (!$this->nullable)) { |
|
19 | + return false; |
|
20 | + } |
|
21 | + if(strlen($value) > $this->max_length) { |
|
22 | + return false; |
|
23 | + } |
|
20 | 24 | return true; |
21 | 25 | } |
22 | 26 | } |
23 | 27 | \ No newline at end of file |
@@ -12,8 +12,8 @@ |
||
12 | 12 | |
13 | 13 | public function validate($value) |
14 | 14 | { |
15 | - if(is_null($value) && (!$this->null)) return false; |
|
16 | - if(strlen($value) > $this->max_length) return false; |
|
15 | + if (is_null($value) && (!$this->null)) return false; |
|
16 | + if (strlen($value) > $this->max_length) return false; |
|
17 | 17 | return true; |
18 | 18 | } |
19 | 19 | } |
@@ -12,8 +12,12 @@ |
||
12 | 12 | |
13 | 13 | public function validate($value) |
14 | 14 | { |
15 | - if(is_null($value) && (!$this->null)) return false; |
|
16 | - if(strlen($value) > $this->max_length) return false; |
|
15 | + if(is_null($value) && (!$this->null)) { |
|
16 | + return false; |
|
17 | + } |
|
18 | + if(strlen($value) > $this->max_length) { |
|
19 | + return false; |
|
20 | + } |
|
17 | 21 | return true; |
18 | 22 | } |
19 | 23 | } |