Skip to content

make:crud | Improvements #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cache:
directories:
- $HOME/.composer/cache/files
- .phpunit
- vendor

env:
global:
Expand All @@ -24,7 +25,7 @@ before_install:
- phpenv config-rm xdebug.ini

install:
- composer install
- composer update --no-suggest
- ./vendor/bin/simple-phpunit install

script:
Expand Down
14 changes: 14 additions & 0 deletions src/GeneratorTwigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ public function getEntityFieldPrintCode($entity, $field): string
$printCode = $entity.'.'.str_replace('_', '', $twigField);

switch ($field['type']) {
case 'datetimetz_immutable':
case 'datetimetz':
$printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s T\') : \'\'';
break;
case 'datetime_immutable':
case 'datetime':
$printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s\') : \'\'';
break;
case 'dateinterval':
$printCode .= ' ? '.$printCode.'.format(\'%y year(s), %m month(s), %d day(s)\') : \'\'';
break;
case 'date_immutable':
case 'date':
$printCode .= ' ? '.$printCode.'|date(\'Y-m-d\') : \'\'';
break;
case 'time_immutable':
case 'time':
$printCode .= ' ? '.$printCode.'|date(\'H:i:s\') : \'\'';
break;
case 'json':
case 'json_array':
$printCode .= ' ? '.$printCode.'|json_encode : \'\'';
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! From looking at the docs, it seems like the value in this field will always be an array or null. Which case were you covering with the is iterable?

And, because the array can be an associative array, the |join won't look quite right in those cases. We could use dump() WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it again. I thought there could be string value.

dump() is a good idea, but will it work without debug package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It believe that it DOES work without debug - it reverts to var_dump(). We can add a json field to our entity in the functional test to be sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you know what? Let's use |json_encode. That will print nicely, and make it very obvious that this is a JSON field. And, it will definitely work :).

@sadikoff if you agree, can you make that change? Also, if you rebase from the latest master, the tests should be closer to passing.

case 'array':
$printCode .= ' ? '.$printCode.'|join(\', \') : \'\'';
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
}

$controllerClassDetails = $generator->createClassNameDetails(
$entityClassDetails->getRelativeNameWithoutSuffix(),
$entityClassDetails->getRelativeNameWithoutSuffix().'Controller',
'Controller\\',
'Controller'
);

$iter = 0;
do {
$formClassDetails = $generator->createClassNameDetails(
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: ''),
$entityClassDetails->getRelativeNameWithoutSuffix().($iter ?: '').'Type',
'Form\\',
'Type'
);
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/skeleton/crud/controller/Controller.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class <?= $class_name ?> extends <?= $parent_class_name; ?><?= "\n" ?>
{
/**
* @Route("/", name="<?= $route_name ?>_index", methods="GET")
* @Route("/", name="<?= $route_name ?>_index", methods={"GET"})
*/
<?php if (isset($repository_full_class_name)): ?>
public function index(<?= $repository_class_name ?> $<?= $repository_var ?>): Response
Expand All @@ -37,7 +37,7 @@ public function index(): Response
<?php endif ?>

/**
* @Route("/new", name="<?= $route_name ?>_new", methods="GET|POST")
* @Route("/new", name="<?= $route_name ?>_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
Expand All @@ -60,15 +60,15 @@ public function new(Request $request): Response
}

/**
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_show", methods="GET")
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_show", methods={"GET"})
*/
public function show(<?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
{
return $this->render('<?= $route_name ?>/show.html.twig', ['<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>]);
}

/**
* @Route("/{<?= $entity_identifier ?>}/edit", name="<?= $route_name ?>_edit", methods="GET|POST")
* @Route("/{<?= $entity_identifier ?>}/edit", name="<?= $route_name ?>_edit", methods={"GET","POST"})
*/
public function edit(Request $request, <?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
{
Expand All @@ -88,7 +88,7 @@ public function edit(Request $request, <?= $entity_class_name ?> $<?= $entity_va
}

/**
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_delete", methods="DELETE")
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_delete", methods={"DELETE"})
*/
public function delete(Request $request, <?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
{
Expand Down