Skip to content

make:entity improved: interactive field created & entity update support #104

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 60 commits into from
Mar 17, 2018
Merged
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
e52e33e
Adding an enhanced make:entity command
weaverryan Dec 31, 2017
cd4f517
Fixing possible non-existent directory in tests
weaverryan Feb 8, 2018
dbe11a5
hack to fix tests temporarily
weaverryan Feb 8, 2018
ed15a2b
temp debugging code for failing test on CI
weaverryan Feb 8, 2018
4bde1dc
With --overwrite, put updated methods in same location as original
weaverryan Feb 8, 2018
6c914fa
Removing debugging code, committing missing file to fix tests
weaverryan Feb 8, 2018
c79b73c
Fixes thanks to Stof!
weaverryan Feb 8, 2018
663afee
test needs database
weaverryan Feb 8, 2018
2fd2e0c
Making the user message a little nicer
weaverryan Feb 8, 2018
c3ccf5f
Ask the user if they want the inverse side of a relation
weaverryan Feb 8, 2018
dc7973d
Fixing tests + one missing return
weaverryan Feb 9, 2018
a822400
adding missing headers
weaverryan Feb 9, 2018
d65d772
Fixing some tests
weaverryan Feb 9, 2018
1f57317
minor tweaks
weaverryan Feb 9, 2018
0f2d52d
Removing unnecessary service locator: just let the registry be null
weaverryan Feb 9, 2018
cf9e08a
making decimal/scale more clear
weaverryan Feb 9, 2018
ab03675
fixing missing return type
weaverryan Feb 9, 2018
922563a
clarifying note
weaverryan Feb 9, 2018
5395788
Not setting the owning side (from inverse) on OneToOne
weaverryan Feb 9, 2018
f370b52
fixing tests
weaverryan Feb 9, 2018
d34ff45
also run phpcs on updated files
weaverryan Feb 10, 2018
5bc34bd
removing unused use
weaverryan Feb 10, 2018
a34a1a2
Fixing "composer require orm orm" bug
weaverryan Feb 20, 2018
4afbc0e
removing dup functions after merge
weaverryan Feb 21, 2018
b8856c0
Code changes to sync with upstream updates
weaverryan Feb 21, 2018
e8e5689
fix arg name
weaverryan Feb 21, 2018
8d400e7
Fixing bug with getting property of classes just created
weaverryan Feb 26, 2018
656c199
Fixing 2 merge bugs: entities could not be updated & mix up of entity vs
weaverryan Feb 26, 2018
e535f0d
Adding an error if you try to generate a class that does not use
weaverryan Feb 26, 2018
05480da
Fixing bug where new classes were never actually written in regenerator
weaverryan Feb 26, 2018
866e534
Extracting logic into AutoloaderUtil
weaverryan Feb 26, 2018
9c40654
added missing service
weaverryan Feb 26, 2018
fb74302
Fixing typo for class name
weaverryan Feb 26, 2018
1650301
Fixing missing method
weaverryan Feb 26, 2018
38e6a0e
Fixing missing return on --regenerate
weaverryan Feb 26, 2018
f9fa0db
adding missing success message
weaverryan Feb 26, 2018
20df636
Fixing a few Windows bugs
weaverryan Feb 26, 2018
abbe8d9
Fixing windows bug where C:/ slash may already be normalized
weaverryan Feb 26, 2018
8c37893
Making appveyor use sqlite for simplicity
weaverryan Feb 26, 2018
35ef3ae
removing duplicate sqlite extension for appveyor
weaverryan Feb 26, 2018
fd088ac
temporarily debugging Windows errors
weaverryan Feb 27, 2018
89d5708
trying to fix windows tests with long paths that cause errors :/
weaverryan Feb 27, 2018
f022f5f
Fixed window path bug while looking for the vendor/ dir
weaverryan Feb 27, 2018
b3647d7
attempting to split tests to combat windows testing issue
weaverryan Feb 27, 2018
92aeff5
playing with appveyor
weaverryan Feb 27, 2018
328e486
fixing windows bug
weaverryan Feb 27, 2018
9c5a786
phpcs
weaverryan Feb 28, 2018
9261cd1
Adding the "length" question for the string type
weaverryan Feb 28, 2018
8634a91
cs
weaverryan Feb 28, 2018
613abef
Adding an option (true by default) for fluent setter methods
weaverryan Feb 28, 2018
7bcc966
Disabling replaceNodes to avoid possible AST accidental changes
weaverryan Feb 28, 2018
b0fed52
updating to stable nickic/php-parser 4.0 release!
weaverryan Mar 1, 2018
259141d
removing comment - it does not add much value & is hard to keep in the
weaverryan Mar 11, 2018
e54988c
Fixing issue where sometimes nullable is not defined on a join column
weaverryan Mar 11, 2018
3b65fb6
Merge branch 'master' into make-entity-improved
weaverryan Mar 14, 2018
2a72ee3
Fixing cs
weaverryan Mar 14, 2018
7d3042c
Fixing bug where the name was always interactive
weaverryan Mar 16, 2018
2f0e0f3
adding support for associative arrays in annotations
weaverryan Mar 17, 2018
01f6a3c
Fixing a bug where a repository would not be generated under certain
weaverryan Mar 17, 2018
16596b1
updating tests for removed comment
weaverryan Mar 17, 2018
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
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
composer.lock
phpunit.xml
vendor/
tests/tmp/*
.php_cs.cache
/composer.lock
/phpunit.xml
/vendor/
/tests/tmp/*
/.php_cs.cache
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ git:
depth: 1

php:
- 7.0
- 7.1
- 7.2

Expand Down
7 changes: 6 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cache:
init:
- SET PATH=c:\php;%PATH%

environment:
TEST_DATABASE_DSN: sqlite:///c:\projects\maker-bundle\tests\tmp\app.db

install:
- mkdir c:\php && cd c:\php
- appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php-7.1.3-Win32-VC14-x86.zip
Expand Down Expand Up @@ -47,4 +50,6 @@ install:
- ./vendor/bin/simple-phpunit install

test_script:
- ./vendor/bin/simple-phpunit
- ./vendor/bin/simple-phpunit --group=functional_group1
- ./vendor/bin/simple-phpunit --group=functional_group2
- ./vendor/bin/simple-phpunit --exclude-group=functional_group1,functional_group2
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
}
],
"require": {
"php": "^7.0.8",
"php": "^7.1.3",
"doctrine/inflector": "^1.2",
"nikic/php-parser": "^4.0",
"symfony/config": "^3.4|^4.0",
"symfony/console": "^3.4|^4.0",
"symfony/dependency-injection": "^3.4|^4.0",
"symfony/filesystem": "^3.4|^4.0",
"symfony/finder": "^3.4|^4.0",
"symfony/framework-bundle": "^3.4|^4.0",
"symfony/http-kernel": "^3.4|^4.0"
},
"require-dev": {
"allocine/twigcs": "^3.0",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/orm": "^2.6",
"friendsofphp/php-cs-fixer": "^2.8",
"symfony/phpunit-bridge": "^3.4|^4.0",
"symfony/process": "^3.4|^4.0"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<php>
<ini name="error_reporting" value="-1" />
<env name="TEST_DATABASE_DSN" value="mysql://root:@127.0.0.1:3306/test_maker" />
</php>

<testsuites>
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function getRequiredDependencyNames(array $dependencies)
$packages[] = $package['name'];
}

return $packages;
return array_unique($packages);
}

private function calculateMissingDependencies(array $dependencies)
Expand All @@ -134,6 +134,6 @@ private function calculateMissingDependencies(array $dependencies)
return [];
}

return array_merge($missingPackages, $missingOptionalPackages);
return array_unique(array_merge($missingPackages, $missingOptionalPackages));
}
}
34 changes: 34 additions & 0 deletions src/Doctrine/BaseCollectionRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

use Symfony\Bundle\MakerBundle\Str;

/**
* @internal
*/
abstract class BaseCollectionRelation extends BaseRelation
{
abstract public function getOrphanRemoval(): bool;

abstract public function getTargetSetterMethodName(): string;

public function getAdderMethodName(): string
{
return 'add'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}

public function getRemoverMethodName(): string
{
return 'remove'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getPropertyName()));
}
}
73 changes: 73 additions & 0 deletions src/Doctrine/BaseRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

/**
* @internal
*/
abstract class BaseRelation
{
private $propertyName;
private $targetClassName;
private $targetPropertyName;
private $mapInverseRelation = true;

abstract public function isOwning(): bool;

public function getPropertyName()
{
return $this->propertyName;
}

public function setPropertyName($propertyName)
{
$this->propertyName = $propertyName;

return $this;
}

public function getTargetClassName()
{
return $this->targetClassName;
}

public function setTargetClassName($targetClassName)
{
$this->targetClassName = $targetClassName;

return $this;
}

public function getTargetPropertyName()
{
return $this->targetPropertyName;
}

public function setTargetPropertyName(?string $targetPropertyName)
{
$this->targetPropertyName = $targetPropertyName;

return $this;
}

public function getMapInverseRelation(): bool
{
return $this->mapInverseRelation;
}

public function setMapInverseRelation(bool $mapInverseRelation)
{
$this->mapInverseRelation = $mapInverseRelation;

return $this;
}
}
32 changes: 32 additions & 0 deletions src/Doctrine/BaseSingleRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Doctrine;

/**
* @internal
*/
abstract class BaseSingleRelation extends BaseRelation
{
private $isNullable;

public function isNullable(): bool
{
return $this->isNullable;
}

public function setIsNullable($isNullable)
{
$this->isNullable = $isNullable;

return $this;
}
}
34 changes: 28 additions & 6 deletions src/Doctrine/DoctrineMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
namespace Symfony\Bundle\MakerBundle\Doctrine;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;

Expand Down Expand Up @@ -55,12 +58,7 @@ public function getMetadataForNamespace($namespace)
return $metadata;
}

/**
* @param string $entity
*
* @return ClassMetadata|null
*/
public function getMetadataForClass(string $entity)
public function getMetadataForClass(string $entity): ?ClassMetadata
{
foreach ($this->registry->getManagers() as $em) {
$cmf = new DisconnectedClassMetadataFactory();
Expand All @@ -74,6 +72,30 @@ public function getMetadataForClass(string $entity)
return null;
}

public function getMappingDriverForClass(string $className): ?MappingDriver
{
/** @var EntityManagerInterface $em */
$em = $this->registry->getManagerForClass($className);

if (null === $em) {
throw new \InvalidArgumentException(sprintf('Cannot find the entity manager for class "%s"', $className));
}

$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();

if (!$metadataDriver instanceof MappingDriverChain) {
return $metadataDriver;
}

foreach ($metadataDriver->getDrivers() as $namespace => $driver) {
if (0 === strpos($className, $namespace)) {
return $driver;
}
}

return $metadataDriver->getDefaultDriver();
}

/**
* @return array
*/
Expand Down
Loading