|
1 | 1 | <?php |
2 | | - |
3 | | -/* MIT License |
4 | | -
|
5 | | -Copyright (c) 2018 Eridan Domoratskiy |
6 | | -
|
7 | | -Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | | -of this software and associated documentation files (the "Software"), to deal |
9 | | -in the Software without restriction, including without limitation the rights |
10 | | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | | -copies of the Software, and to permit persons to whom the Software is |
12 | | -furnished to do so, subject to the following conditions: |
13 | | -
|
14 | | -The above copyright notice and this permission notice shall be included in all |
15 | | -copies or substantial portions of the Software. |
16 | | -
|
17 | | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | | -SOFTWARE. */ |
24 | | - |
25 | 2 | namespace PHPDataGen\Model; |
26 | | - |
27 | | -/** |
28 | | - * Class model |
29 | | - */ |
30 | | -class ClassModel extends Data_ClassModel {} |
| 3 | +class ClassModel { |
| 4 | +use \PHPDataGen\DataClassTrait; |
| 5 | +private $name = ''; |
| 6 | +private $final = false; |
| 7 | +private $finalFinal = false; |
| 8 | +private $extends = null; |
| 9 | +private $implements = []; |
| 10 | +private $fields = []; |
| 11 | +public function __construct(array $init = []) { |
| 12 | +foreach ($init as $field => $value) { |
| 13 | + $validate = "validate_$field"; |
| 14 | + $this->$field = $this->$validate($value); |
| 15 | +} |
| 16 | +} |
| 17 | +public function get_name() { return $this->name; } |
| 18 | +protected function validate_name($value) { |
| 19 | +if (!is_string($value)) { throw new \InvalidArgumentException('Field name has type string'); } |
| 20 | +return $value; |
| 21 | +} |
| 22 | +public function &get_final() { return $this->final; } |
| 23 | +protected function validate_final($value) { |
| 24 | +if (!is_bool($value)) { throw new \InvalidArgumentException('Field final has type bool'); } |
| 25 | +return $value; |
| 26 | +} |
| 27 | +public function set_final($value) { $this->final = $this->validate_final($value);} |
| 28 | +public function &get_finalFinal() { return $this->finalFinal; } |
| 29 | +protected function validate_finalFinal($value) { |
| 30 | +if (!is_bool($value)) { throw new \InvalidArgumentException('Field finalFinal has type bool'); } |
| 31 | +return $value; |
| 32 | +} |
| 33 | +public function set_finalFinal($value) { $this->finalFinal = $this->validate_finalFinal($value);} |
| 34 | +public function get_extends() { return $this->extends; } |
| 35 | +protected function validate_extends($value) { |
| 36 | +if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field extends has type string'); } |
| 37 | +return $value; |
| 38 | +} |
| 39 | +public function &get_implements() { return $this->implements; } |
| 40 | +protected function validate_implements($value) { |
| 41 | +if (!is_array($value)) { throw new \InvalidArgumentException('Field implements has type array'); } |
| 42 | +return $value; |
| 43 | +} |
| 44 | +public function set_implements($value) { $this->implements = $this->validate_implements($value);} |
| 45 | +public function &get_fields() { return $this->fields; } |
| 46 | +protected function validate_fields($value) { |
| 47 | +if (!is_array($value)) { throw new \InvalidArgumentException('Field fields has type array'); } |
| 48 | +return $value; |
| 49 | +} |
| 50 | +public function set_fields($value) { $this->fields = $this->validate_fields($value);} |
| 51 | +} |
0 commit comments