forked from GNUsocial/gnu-social
[TOOLS] Update generate_entity_fields
This commit is contained in:
parent
bd8f4bd277
commit
689a5df670
@ -12,8 +12,8 @@ const types = [
|
|||||||
'blob' => '',
|
'blob' => '',
|
||||||
'bool' => 'bool',
|
'bool' => 'bool',
|
||||||
'char' => 'string',
|
'char' => 'string',
|
||||||
'datetime' => '\DateTimeInterface',
|
'datetime' => 'DateTimeInterface',
|
||||||
'timestamp' => '\DateTimeInterface',
|
'timestamp' => 'DateTimeInterface',
|
||||||
'html' => 'string',
|
'html' => 'string',
|
||||||
'int' => 'int',
|
'int' => 'int',
|
||||||
'numeric' => 'float',
|
'numeric' => 'float',
|
||||||
@ -28,12 +28,20 @@ $path = str_replace('%kernel.project_dir%', ROOT, $path);
|
|||||||
|
|
||||||
$files = glob($path . '/*.php');
|
$files = glob($path . '/*.php');
|
||||||
|
|
||||||
|
$classes = [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
require_once $file;
|
require_once $file;
|
||||||
|
|
||||||
$declared = get_declared_classes();
|
$declared = get_declared_classes();
|
||||||
$class = end($declared);
|
foreach ($declared as $dc) {
|
||||||
|
if (preg_match('/App\\\\Entity/', $dc) && !in_array($dc, $classes)) {
|
||||||
|
$class = $dc;
|
||||||
|
$classes[] = $class;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$no_ns_class = preg_replace('/.*?\\\\/', '', $class);
|
$no_ns_class = preg_replace('/.*?\\\\/', '', $class);
|
||||||
$schema = $class::schemaDef();
|
$schema = $class::schemaDef();
|
||||||
@ -60,9 +68,9 @@ foreach ($files as $file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$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" .
|
"\n {\n \$this->{$field} = \${$field};\n return \$this;\n }" . "\n\n" .
|
||||||
" public function get{$method_name}()" . ($type !== '' ? ": {$type}" : '') .
|
" public function get{$method_name}()" . ($type !== '' ? ": {$type}" : '') .
|
||||||
"{ return \$this->{$field}; }" . "\n";
|
"\n {\n return \$this->{$field};\n }" . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields_code = implode("\n", $fields_code);
|
$fields_code = implode("\n", $fields_code);
|
||||||
@ -77,8 +85,7 @@ foreach ($files as $file) {
|
|||||||
|
|
||||||
{$methods_code}
|
{$methods_code}
|
||||||
|
|
||||||
{$end}
|
{$end}";
|
||||||
";
|
|
||||||
|
|
||||||
foreach (['/\\//' => '\\/', '/ /' => '\\ '] as $from => $to) {
|
foreach (['/\\//' => '\\/', '/ /' => '\\ '] as $from => $to) {
|
||||||
$begin = preg_replace($from, $to, $begin);
|
$begin = preg_replace($from, $to, $begin);
|
||||||
|
Loading…
Reference in New Issue
Block a user