Skip to content

[DTO] Add new make:dto command #303

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

Open
wants to merge 60 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f935c55
Add new make:dto command
ckrack Oct 24, 2018
11aa0a4
Cleanup code
ckrack Oct 24, 2018
239302c
Prevent errors with non-entities
ckrack Oct 25, 2018
97d0ce1
Rephrase question and update meaning for getter/setter generation
ckrack Oct 25, 2018
59a9742
Fix variable name
ckrack Oct 25, 2018
0be8795
Change namespace
ckrack Oct 25, 2018
90e816d
Make success message more helpful
ckrack Oct 25, 2018
0a4deb5
Make help look like the actual prompt
ckrack Oct 25, 2018
34a3ad3
Deal with the spaces
ckrack Oct 25, 2018
02a95e7
Run php-cs-fixer
ckrack Oct 25, 2018
ff12314
Remove blank line
ckrack Oct 26, 2018
b97a047
Fix omitting getters
ckrack Oct 26, 2018
7328305
Update classname and filename
ckrack Oct 29, 2018
a1e0fab
Make Id-omitting mandatory
ckrack Oct 29, 2018
71ed757
Remove unnecessary comment
ckrack Oct 29, 2018
c0effd5
Add testsuite
ckrack Oct 29, 2018
2630a78
Fix PHP 7.0 compatibility
ckrack Oct 29, 2018
85f6646
Require PHP 7.1
ckrack Oct 29, 2018
2218c3b
Separate tests for DTO
ckrack Oct 29, 2018
b0fedd1
Fix spaces
ckrack Oct 29, 2018
ff2c90e
Cleanup comments and use PHP_EOL
ckrack Nov 1, 2018
14df70e
Update help text
ckrack Nov 4, 2018
97d7176
Throw exception instead of using io-error
ckrack Nov 4, 2018
f5b0c08
Rename property
ckrack Nov 4, 2018
a44b27f
Improve Exception
ckrack Nov 5, 2018
f49b5d5
Rename skeleton file
ckrack Nov 5, 2018
7269a30
Add missing use statement for RuntimeCommandException
ckrack Nov 5, 2018
aed765a
Use existing method to check for entity
ckrack Nov 5, 2018
9489309
Remove dead codeblock
ckrack Nov 6, 2018
c209033
Remove useless check
ckrack Nov 6, 2018
afffbfd
Move codeblock closer to where it's used
ckrack Nov 6, 2018
c36abf9
Fix comments
ckrack Nov 6, 2018
fd2f7f2
Restructure tests
ckrack Nov 6, 2018
6728035
Add composite id test
ckrack Nov 6, 2018
e72dd71
Add mappedsuperclass test
ckrack Nov 6, 2018
3e595a3
Add test for missing getters/setters
ckrack Nov 6, 2018
5fe16ed
Fix indentation
ckrack Nov 7, 2018
3a55a5a
Use null comparison instead of instanceof
ckrack Nov 7, 2018
b3d7512
Use existing method to filter identifiers
ckrack Nov 7, 2018
e18aefd
Use more robust method to convert constraints to annotations
ckrack Nov 7, 2018
a98a2ab
Update missing-getters-test to require a warning message
ckrack Nov 7, 2018
d381a73
Prevent using missing getters/setters of an entity
ckrack Nov 7, 2018
b35f0cb
Fix coding style
ckrack Nov 7, 2018
44f5080
Reverse comparison
ckrack Nov 7, 2018
e87ebad
Improve command message
ckrack Nov 7, 2018
4888dbd
Add test for warning when using yaml/xml validation definitions
ckrack Nov 8, 2018
ac7a37e
Fix test for generated DTO
ckrack Nov 8, 2018
4e5877d
Use validator to compare annotation validations
ckrack Nov 8, 2018
f9a29e5
php-cs-fix
ckrack Nov 8, 2018
3b66220
Remove validator dependency
ckrack Nov 9, 2018
3a9f828
Change namespace of generated DTO
ckrack Nov 9, 2018
0e0c831
Reverse question for getter/setter generation
ckrack Dec 3, 2018
868628c
Improve comment
ckrack Dec 3, 2018
b479226
style: rename bound-class to entity
ckrack Jun 20, 2020
258726a
style: early return
ckrack Jun 20, 2020
ef1ed3f
Remove PHP 7.1 requirement & run php-cs-fixer
ckrack Jun 22, 2020
5369512
style: fix codestyle
ckrack Jun 22, 2020
3bb3f23
feat: allow choosing of three dto styles
ckrack Jul 2, 2020
42a6264
feat: create named constructor fromEntity
ckrack Jul 2, 2020
249ea83
chore: fix whitespaces
ckrack Jul 2, 2020
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
2 changes: 1 addition & 1 deletion src/Command/MakerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->maker->configureDependencies($dependencies, $input);

if (!$dependencies->isPhpVersionSatisfied()) {
throw new RuntimeCommandException('The make:entity command requires that you use PHP 7.1 or higher.');
throw new RuntimeCommandException(sprintf('The %s command requires that you use PHP 7.1 or higher.', $this->maker->getCommandName()));
}

if ($missingPackagesMessage = $dependencies->getMissingPackagesMessage($this->getName())) {
Expand Down
464 changes: 464 additions & 0 deletions src/Maker/MakeDto.php

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/Resources/config/makers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<services>
<defaults public="false" />

<service id="maker.maker.make_dto" class="Symfony\Bundle\MakerBundle\Maker\MakeDto">
<argument type="service" id="maker.doctrine_helper" />
<argument type="service" id="maker.file_manager" />
<argument type="service" id="validator" on-invalid="null" />
<tag name="maker.command" />
</service>

<service id="maker.maker.make_authenticator" class="Symfony\Bundle\MakerBundle\Maker\MakeAuthenticator">
<argument type="service" id="maker.file_manager" />
<argument type="service" id="maker.security_config_updater" />
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/help/MakeDto.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The <info>%command.name%</info> command generates a new data transfer object class.

<info>php %command.full_name% DtoClassName TargetEntityClassName</info>

If the argument is missing, the command will ask for the classname and entity interactively.
11 changes: 11 additions & 0 deletions src/Resources/skeleton/dto/ImmutableGettersDto.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?= '<?php'.PHP_EOL ?>

namespace <?= $namespace ?>;

/**
* Data transfer object for <?= $entity_class_name ?>.
*/
class <?= $class_name ?>

{
}
34 changes: 34 additions & 0 deletions src/Resources/skeleton/dto/MutableGettersSettersDto.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?= '<?php'.PHP_EOL ?>
<?php use Symfony\Bundle\MakerBundle\Str;

?>

namespace <?= $namespace ?>;

<?php if (isset($entity_full_class_name)): ?>
use <?= $entity_full_class_name ?>;
<?php endif ?>

/**
* Data transfer object for <?= $entity_class_name ?>.
*/
class <?= $class_name ?>

{
/**
* Create DTO, optionally extracting data from a model.
*/
public function __construct(<?= $entity_class_name ?> $<?= lcfirst($entity_class_name) ?> = null)
{
if ($<?= lcfirst($entity_class_name) ?>) {
<?php foreach ($fields as $propertyName => $mapping): ?>
<?php if (false === $mapping['hasGetter']): ?>
// @todo implement getter on the Entity
//$this->set<?= Str::asCamelCase($propertyName) ?>($<?= lcfirst($entity_class_name) ?>->get<?= Str::asCamelCase($propertyName) ?>());
<?php else : ?>
$this->set<?= Str::asCamelCase($propertyName) ?>($<?= lcfirst($entity_class_name) ?>->get<?= Str::asCamelCase($propertyName) ?>());
<?php endif; ?>
<?php endforeach; ?>
}
}
}
34 changes: 34 additions & 0 deletions src/Resources/skeleton/dto/MutablePublicDto.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?= '<?php'.PHP_EOL ?>
<?php use Symfony\Bundle\MakerBundle\Str;

?>

namespace <?= $namespace ?>;

<?php if (isset($entity_full_class_name)): ?>
use <?= $entity_full_class_name ?>;
<?php endif ?>

/**
* Data transfer object for <?= $entity_class_name ?>.
*/
class <?= $class_name ?>

{
/**
* Create DTO, optionally extracting data from a model.
*/
public function __construct(<?= $entity_class_name ?> $<?= lcfirst($entity_class_name) ?> = null)
{
if ($<?= lcfirst($entity_class_name) ?>) {
<?php foreach ($fields as $propertyName => $mapping): ?>
<?php if (false === $mapping['hasGetter']): ?>
// @todo implement getter on the Entity
//$this-><?= $propertyName ?> = $<?= lcfirst($entity_class_name) ?>->get<?= Str::asCamelCase($propertyName) ?>();
<?php else : ?>
$this-><?= $propertyName ?> = $<?= lcfirst($entity_class_name) ?>->get<?= Str::asCamelCase($propertyName) ?>();
<?php endif; ?>
<?php endforeach; ?>
}
}
}
Loading