Skip to content
This repository was archived by the owner on Jun 19, 2022. It is now read-only.

Commit 4c7507d

Browse files
committed
allow continiously ask for new property
1 parent 01e34df commit 4c7507d

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/Maker/MakeHslDto.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,10 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
6767
);
6868

6969
$fieldArray = [];
70-
$addNewProperty = "first_property";
70+
$addNewProperty = $io->ask('New property name (press <return> to stop adding fields)');
7171

72-
do
72+
while(!empty($addNewProperty))
7373
{
74-
$addNewProperty = $io->ask('New property name (press <return> to stop adding fields)', null, function($answer) {
75-
if(empty($answer))
76-
{
77-
throw new RuntimeCommandException('This value cannot be blank.');
78-
}
79-
80-
return $answer;
81-
});
82-
8374
$fieldName = Str::asLowerCamelCase($addNewProperty);
8475

8576
if(in_array($fieldName, $fieldArray))
@@ -103,7 +94,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
10394
'name' => $fieldName,
10495
'type' => $requestType
10596
];
106-
}while(empty($addNewProperty));
97+
98+
$addNewProperty = $io->ask('New property name (press <return> to stop adding fields)');
99+
}
107100

108101
// generate dto
109102
$generator->generateClass(

src/Resources/skeleton/dto/Dto.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class <?= $class_name ?> implements DtoRequestInterface
1616
public function __construct(Request $request)
1717
{
1818
<?php foreach($fieldArray as $field): ?>
19-
$this-><?= $field['name'] ?> = <?php if ($field['type'] === 'json'): ?>$request->get('<?= $field['name'] ?>'); <?php elseif ($field['type'] === 'form'): ?>$request->request->get('<?= $field['name'] ?>'); <?php else: ?>$request->files->get('<?= $field['name'] ?>');<?php endif; ?>
19+
$this-><?= $field['name'] ?> = <?php if ($field['type'] === 'json'): ?>$request->get('<?= $field['name'] ?>'); <?php elseif ($field['type'] === 'form'): ?>$request->request->get('<?= $field['name'] ?>'); <?php else: ?>$request->files->get('<?= $field['name'] ?>');<?php endif; ?><?= "\n" ?>
2020
<?php endforeach; ?>
2121

2222
}

0 commit comments

Comments
 (0)