[TOOLS] Update bin/generate_entity_fields script

This commit is contained in:
Hugo Sales 2020-06-30 18:19:50 +00:00 committed by Hugo Sales
parent 5eae3dc351
commit 2eab90bbb0
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -13,6 +13,7 @@ const types = [
'bool' => 'bool', 'bool' => 'bool',
'char' => 'string', 'char' => 'string',
'datetime' => '\DateTimeInterface', 'datetime' => '\DateTimeInterface',
'timestamp' => '\DateTimeInterface',
'html' => 'string', 'html' => 'string',
'int' => 'int', 'int' => 'int',
'numeric' => 'float', 'numeric' => 'float',
@ -21,12 +22,13 @@ const types = [
'varchar' => 'string', 'varchar' => 'string',
]; ];
$path = Yaml::parseFile(ROOT . '/config/services.yaml')['services']['app.util.schemadef_driver']['arguments'][0]; $path = Yaml::parseFile(ROOT . '/config/services.yaml')['services']['app.core.schemadef_driver']['arguments'][0];
$path = str_replace('%kernel.project_dir%', ROOT, $path); $path = str_replace('%kernel.project_dir%', ROOT, $path);
$files = glob($path . '/*.php'); $files = glob($path . '/*.php');
foreach ($files as $file) { foreach ($files as $file) {
require_once $file; require_once $file;
$declared = get_declared_classes(); $declared = get_declared_classes();
@ -45,7 +47,7 @@ foreach ($files as $file) {
$fields_code[] = " private {$type} \${$field};"; $fields_code[] = " private {$type} \${$field};";
$methods_code[] = " public function set{$method_name}({$type} \${$field}): self " . $methods_code[] = " public function set{$method_name}({$type} \${$field}): self " .
"{ \$this->{$field} = \${$field}; return \$this; }" . "\n" . "{ \$this->{$field} = \${$field}; return \$this; }" . "\n" .
" public function get{$method_name}()" . ($type !== '' ? ': ' . $type : '') . " public function get{$method_name}()" . ($type !== '' ? ": {$type} " : ' ') .
"{ return \$this->{$field}; }" . "\n"; "{ return \$this->{$field}; }" . "\n";
} }