[TOOLS] Update generate fields script to output default values

This commit is contained in:
Hugo Sales 2020-07-25 01:54:18 +00:00 committed by Hugo Sales
parent 672e2b80eb
commit 72bf62adc3
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -44,7 +44,20 @@ foreach ($files as $file) {
$type = types[$schema['fields'][$field]['type']];
$type = $type !== '' ? $nullable . $type : $type;
$method_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $field)));
$fields_code[] = " private {$type} \${$field};";
$default = @$schema['fields'][$field]['default'];
if (isset($default) && $nullable != '?' && $type != '\DateTimeInterface') {
if (is_string($default)) {
$default = "'{$default}'";
} elseif ($type == 'bool') {
$default = $default ? 'true' : 'false';
}
$fields_code[] = " private {$type} \${$field} = {$default};";
} else {
$fields_code[] = " private {$type} \${$field};";
}
$methods_code[] = " public function set{$method_name}({$type} \${$field}): self " .
"{ \$this->{$field} = \${$field}; return \$this; }" . "\n" .
" public function get{$method_name}()" . ($type !== '' ? ": {$type} " : ' ') .