Skip to content

Commit 0dfc1d5

Browse files
committed
Adding an enhanced make:entity command
This is now interactive, supports: * Adding scalar fields * Adding relations * Can update an existing entity * synchronizes owning side of entity relations * respects phpcs in generated code * --regenerate flag to add getters/setters for existing properties This also improves the testing system yet again to be much more powerful.
1 parent a481d54 commit 0dfc1d5

File tree

116 files changed

+7054
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+7054
-58
lines changed

.php_cs.dist

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ return PhpCsFixer\Config::create()
77
->setRules(array(
88
'@Symfony' => true,
99
'@Symfony:risky' => true,
10-
'array_syntax' => array('syntax' => 'short'),
10+
'array_syntax' => ['syntax' => 'short'],
1111
'protected_to_private' => false,
1212
'semicolon_after_instruction' => false,
13+
'header_comment' => [
14+
'header' => <<<EOF
15+
This file is part of the Symfony package.
16+
17+
(c) Fabien Potencier <fabien@symfony.com>
18+
19+
For the full copyright and license information, please view the LICENSE
20+
file that was distributed with this source code.
21+
EOF
22+
]
1323
))
1424
->setRiskyAllowed(true)
1525
->setFinder(

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ git:
77
depth: 1
88

99
php:
10-
- 7.0
1110
- 7.1
1211
- 7.2
1312

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^7.0.8",
15+
"php": "^7.1.3",
16+
"doctrine/inflector": "^1.2",
17+
"nikic/php-parser": "4.0.0alpha3",
1618
"symfony/config": "^3.4|^4.0",
1719
"symfony/console": "^3.4|^4.0",
1820
"symfony/dependency-injection": "^3.4|^4.0",
1921
"symfony/filesystem": "^3.4|^4.0",
22+
"symfony/finder": "^3.4|^4.0",
2023
"symfony/framework-bundle": "^3.4|^4.0",
2124
"symfony/http-kernel": "^3.4|^4.0"
2225
},
2326
"require-dev": {
27+
"doctrine/doctrine-bundle": "^1.8",
28+
"doctrine/orm": "^2.6",
2429
"friendsofphp/php-cs-fixer": "^2.8",
2530
"symfony/phpunit-bridge": "^3.4|^4.0",
2631
"symfony/process": "^3.4|^4.0"

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
>
1010
<php>
1111
<ini name="error_reporting" value="-1" />
12+
<env name="TEST_DATABASE_DSN" value="mysql://root:@127.0.0.1:3306/test_maker" />
1213
</php>
1314

1415
<testsuites>

src/DependencyBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,21 @@ public function getMissingDependencies(): array
5353

5454
return array_merge($missingPackages, $missingOptionalPackages);
5555
}
56+
57+
/**
58+
* @internal
59+
*/
60+
public function getAllRequiredDependencies(): array
61+
{
62+
$dependencies = [];
63+
foreach ($this->dependencies as $class => $package) {
64+
if (!$package['required']) {
65+
continue;
66+
}
67+
68+
$dependencies[] = $package['name'];
69+
}
70+
71+
return $dependencies;
72+
}
5673
}

src/DependencyInjection/CompilerPass/MakeCommandRegistrationPass.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass;
413

514
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Doctrine;
13+
14+
use Symfony\Bundle\MakerBundle\Str;
15+
16+
/**
17+
* @internal
18+
*/
19+
abstract class BaseCollectionRelation extends BaseRelation
20+
{
21+
abstract public function getOrphanRemoval(): bool;
22+
23+
abstract public function getTargetSetterMethodName(): string;
24+
25+
public function getAdderMethodName(): string
26+
{
27+
return 'add'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
28+
}
29+
30+
public function getRemoverMethodName(): string
31+
{
32+
return 'remove'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
33+
}
34+
}

src/Doctrine/BaseRelation.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Doctrine;
13+
14+
/**
15+
* @internal
16+
*/
17+
abstract class BaseRelation
18+
{
19+
private $propertyName;
20+
private $targetClassName;
21+
private $targetPropertyName;
22+
private $mapInverseRelation = true;
23+
24+
abstract public function isOwning(): bool;
25+
26+
public function getPropertyName()
27+
{
28+
return $this->propertyName;
29+
}
30+
31+
public function setPropertyName($propertyName)
32+
{
33+
$this->propertyName = $propertyName;
34+
35+
return $this;
36+
}
37+
38+
public function getTargetClassName()
39+
{
40+
return $this->targetClassName;
41+
}
42+
43+
public function setTargetClassName($targetClassName)
44+
{
45+
$this->targetClassName = $targetClassName;
46+
47+
return $this;
48+
}
49+
50+
public function getTargetPropertyName()
51+
{
52+
return $this->targetPropertyName;
53+
}
54+
55+
public function setTargetPropertyName(?string $targetPropertyName)
56+
{
57+
$this->targetPropertyName = $targetPropertyName;
58+
59+
return $this;
60+
}
61+
62+
public function getMapInverseRelation(): bool
63+
{
64+
return $this->mapInverseRelation;
65+
}
66+
67+
public function setMapInverseRelation(bool $mapInverseRelation)
68+
{
69+
$this->mapInverseRelation = $mapInverseRelation;
70+
71+
return $this;
72+
}
73+
}

src/Doctrine/BaseSingleRelation.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Doctrine;
13+
14+
/**
15+
* @internal
16+
*/
17+
abstract class BaseSingleRelation extends BaseRelation
18+
{
19+
private $isNullable;
20+
21+
public function isNullable(): bool
22+
{
23+
return $this->isNullable;
24+
}
25+
26+
public function setIsNullable($isNullable)
27+
{
28+
$this->isNullable = $isNullable;
29+
30+
return $this;
31+
}
32+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Doctrine;
13+
14+
use Doctrine\Common\Persistence\ManagerRegistry;
15+
use Doctrine\ORM\Mapping\ClassMetadata;
16+
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
17+
18+
/**
19+
* Simpler version of DoctrineBundle's DisconnectedMetadataFactory, to
20+
* avoid PSR-4 issues.
21+
*
22+
* @author Fabien Potencier <fabien@symfony.com>
23+
* @author Ryan Weaver <ryan@knpuniversity.com>
24+
*/
25+
final class DoctrineMetadataFactory
26+
{
27+
private $registry;
28+
29+
/**
30+
* Constructor.
31+
*
32+
* @param ManagerRegistry $registry A ManagerRegistry instance
33+
*/
34+
public function __construct(ManagerRegistry $registry)
35+
{
36+
$this->registry = $registry;
37+
}
38+
39+
/**
40+
* @param string $namespace
41+
*
42+
* @return array|ClassMetadata[]
43+
*/
44+
public function getMetadataForNamespace($namespace)
45+
{
46+
$metadata = [];
47+
foreach ($this->getAllMetadata() as $m) {
48+
if (0 === strpos($m->name, $namespace)) {
49+
$metadata[] = $m;
50+
}
51+
}
52+
53+
return $metadata;
54+
}
55+
56+
public function getMetadataForClass(string $entity): ?ClassMetadata
57+
{
58+
foreach ($this->registry->getManagers() as $em) {
59+
$cmf = new DisconnectedClassMetadataFactory();
60+
$cmf->setEntityManager($em);
61+
62+
if (!$cmf->isTransient($entity)) {
63+
return $cmf->getMetadataFor($entity);
64+
}
65+
}
66+
67+
return null;
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
private function getAllMetadata()
74+
{
75+
$metadata = [];
76+
foreach ($this->registry->getManagers() as $em) {
77+
$cmf = new DisconnectedClassMetadataFactory();
78+
$cmf->setEntityManager($em);
79+
foreach ($cmf->getAllMetadata() as $m) {
80+
$metadata[] = $m;
81+
}
82+
}
83+
84+
return $metadata;
85+
}
86+
}

0 commit comments

Comments
 (0)