|
| 1 | +<?php |
| 2 | +namespace PHPDataGen\Model; |
| 3 | +class Data_FieldModel { |
| 4 | +use \PHPDataGen\DataClassTrait; |
| 5 | +private $name = null; |
| 6 | +private $editable = null; |
| 7 | +private $direct = null; |
| 8 | +private $type = null; |
| 9 | +private $validators = null; |
| 10 | +private $filterDefault = null; |
| 11 | +private $default = null; |
| 12 | +public function __construct(array $init = []) { |
| 13 | +$this->editable = $this->validate_editable(false); |
| 14 | +$this->direct = $this->validate_direct(false); |
| 15 | +$this->filterDefault = $this->validate_filterDefault(true); |
| 16 | +foreach ($init as $field => $value) { |
| 17 | + $validate = "validate_$field"; |
| 18 | + $this->$field = $this->$validate($value); |
| 19 | +} |
| 20 | +} |
| 21 | +public function get_name() { return $this->name; } |
| 22 | +protected function validate_name($value) { |
| 23 | +if (!is_string($value) && !is_null($value)) { throw new \InvalidArgumentException('Field name has type string'); } |
| 24 | +return $value; |
| 25 | +} |
| 26 | +public function get_editable() { return $this->editable; } |
| 27 | +protected function validate_editable($value) { |
| 28 | +if (!is_bool($value) && !is_null($value)) { throw new \InvalidArgumentException('Field editable has type bool'); } |
| 29 | +return $value; |
| 30 | +} |
| 31 | +public function get_direct() { return $this->direct; } |
| 32 | +protected function validate_direct($value) { |
| 33 | +if (!is_bool($value) && !is_null($value)) { throw new \InvalidArgumentException('Field direct has type bool'); } |
| 34 | +return $value; |
| 35 | +} |
| 36 | +public function get_type() { return $this->type; } |
| 37 | +protected function validate_type($value) { |
| 38 | +if (!is_a($value, \PHPDataGen\Type::class) && !is_null($value)) { throw new \InvalidArgumentException('Field type has type \PHPDataGen\Type'); } |
| 39 | +return $value; |
| 40 | +} |
| 41 | +public function get_validators() { return $this->validators; } |
| 42 | +protected function validate_validators($value) { |
| 43 | +if (!is_array($value) && !is_null($value)) { throw new \InvalidArgumentException('Field validators has type array'); } |
| 44 | +return $value; |
| 45 | +} |
| 46 | +public function get_filterDefault() { return $this->filterDefault; } |
| 47 | +protected function validate_filterDefault($value) { |
| 48 | +if (!is_bool($value) && !is_null($value)) { throw new \InvalidArgumentException('Field filterDefault has type bool'); } |
| 49 | +return $value; |
| 50 | +} |
| 51 | +public function get_default() { return $this->default; } |
| 52 | +protected function validate_default($value) { |
| 53 | +if (!is_string($value) && !is_null($value)) { throw new \InvalidArgumentException('Field default has type string'); } |
| 54 | +return $value; |
| 55 | +} |
| 56 | +} |
0 commit comments