Skip to content
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
22 changes: 11 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,27 @@ jobs:
php-version:
- '8.0'
symfony-version:
- '4.4.*'
- '5.3.*'
- '5.4.*'
- '5.4.x-dev'
- '6.0.x-dev'
dependency-versions: ['highest']
allow-dev-deps-in-apps: ['0']
include:
# testing lowest PHP version with LTS
- php-version: '7.1.3'
symfony-version: '4.4.*'
# not important - does not affect each app's dependencies
dependency-versions: 'highest'
# testing lowest php version with highest 5.x stable
- php-version: '7.2.5'
symfony-version: '5.3.*'
symfony-version: '5.4.*'
dependency-versions: 'lowest'
# testing lowest php version with highest 5.x stable
- php-version: '7.2.5'
symfony-version: '5.4.*'
dependency-versions: 'highest'
# testing bleeding edge PHP with highest 5.x stable
- php-version: '8.1'
symfony-version: '5.3.*'
symfony-version: '5.4.*'
dependency-versions: 'highest'
- php-version: '8.1'
symfony-version: '6.1.*-dev'
dependency-versions: 'highest'
# temporarily needed until some packages support php 8.1
allow-dev-deps-in-apps: '1'

steps:
Expand All @@ -136,7 +136,7 @@ jobs:
with:
coverage: "none"
php-version: ${{ matrix.php-version }}
tools: composer:2.2
tools: composer:v2

- name: "Add PHPUnit matcher"
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=7.1.3",
"doctrine/inflector": "^1.2|^2.0",
"php": ">=7.2.5",
"doctrine/inflector": "^2.0",
"nikic/php-parser": "^4.11",
"symfony/config": "^4.4|^5.0|^6.0",
"symfony/console": "^4.4|^5.0|^6.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"symfony/config": "^5.4.7|^6.0",
"symfony/console": "^5.4.7|^6.0",
"symfony/dependency-injection": "^5.4.7|^6.0",
"symfony/deprecation-contracts": "^2.2|^3",
"symfony/filesystem": "^4.4|^5.0|^6.0",
"symfony/finder": "^4.4|^5.0|^6.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/http-kernel": "^4.4|^5.0|^6.0"
"symfony/filesystem": "^5.4.7|^6.0",
"symfony/finder": "^5.4.7|^6.0",
"symfony/framework-bundle": "^5.4.7|^6.0",
"symfony/http-kernel": "^5.4.7|^6.0"
},
"require-dev": {
"composer/semver": "^3.0",
"doctrine/doctrine-bundle": "^1.12.3|^2.0",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/orm": "^2.3",
"symfony/http-client": "^4.4|^5.0|^6.0",
"symfony/phpunit-bridge": "^4.4|^5.0|^6.0",
"symfony/http-client": "^5.4.7|^6.0",
"symfony/phpunit-bridge": "^5.4.7|^6.0",
"symfony/polyfill-php80": "^1.16.0",
"symfony/process": "^4.4|^5.0|^6.0",
"symfony/security-core": "^4.4|^5.0|^6.0",
"symfony/yaml": "^4.4|^5.0|^6.0",
"symfony/process": "^5.4.7|^6.0",
"symfony/security-core": "^5.4.7|^6.0",
"symfony/yaml": "^5.4.7|^6.0",
"twig/twig": "^2.0|^3.0"
},
"config": {
Expand Down
45 changes: 17 additions & 28 deletions src/Doctrine/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@

namespace Symfony\Bundle\MakerBundle\Doctrine;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyPersistenceMappingException;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
use Doctrine\ORM\Mapping\NamingStrategy;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
Expand All @@ -44,10 +41,6 @@ final class DoctrineHelper
*/
private $entityNamespace;
private $phpCompatUtil;

/**
* @var ManagerRegistry
*/
private $registry;

/**
Expand All @@ -57,10 +50,7 @@ final class DoctrineHelper

private $attributeMappingSupport;

/**
* @var ManagerRegistry|LegacyManagerRegistry
*/
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, ManagerRegistry $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
{
$this->entityNamespace = trim($entityNamespace, '\\');
$this->phpCompatUtil = $phpCompatUtil;
Expand All @@ -69,10 +59,7 @@ public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUti
$this->mappingDriversByPrefix = $annotatedPrefixes;
}

/**
* @return LegacyManagerRegistry|ManagerRegistry
*/
public function getRegistry()
public function getRegistry(): ManagerRegistry
{
// this should never happen: we will have checked for the
// DoctrineBundle dependency before calling this
Expand Down Expand Up @@ -173,17 +160,21 @@ public function getEntitiesForAutocomplete(): array
}

/**
* @return array|ClassMetadata|LegacyClassMetadata
* @return array|ClassMetadata
*/
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
{
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
$classNames->setAccessible(true);

// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) {
foreach ($prefixes as [$prefix, $annotationDriver]) {
if (null !== $annotationDriver) {
if ($annotationDriver instanceof AnnotationDriver) {
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
} else {
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames');
}

$classNames->setAccessible(true);
$classNames->setValue($annotationDriver, null);
}
}
Expand All @@ -198,11 +189,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
if ($disconnected) {
try {
$loaded = $cmf->getAllMetadata();
} catch (ORMMappingException $e) {
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
} catch (LegacyPersistenceMappingException $e) {
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
} catch (PersistenceMappingException $e) {
} catch (ORMMappingException|PersistenceMappingException $e) {
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
}

Expand All @@ -221,6 +208,10 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
if ($this->isInstanceOf($driver, AnnotationDriver::class)) {
$classNames->setValue($driver, null);
}

if ($this->isInstanceOf($driver, AttributeDriver::class)) {
$classNames->setValue($driver, null);
}
}
}
}
Expand Down Expand Up @@ -270,9 +261,7 @@ private function isInstanceOf($object, string $class): bool
return false;
}

$legacyClass = str_replace('Doctrine\\Persistence\\', 'Doctrine\\Common\\Persistence\\', $class);

return $object instanceof $class || $object instanceof $legacyClass;
return $object instanceof $class;
}

public function getPotentialTableName(string $className): string
Expand Down
5 changes: 1 addition & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ public function generateTemplate(string $targetPath, string $templateName, array

public static function getControllerBaseClass(): ClassNameDetails
{
// @legacy Support for Controller::class can be dropped when FrameworkBundle minimum supported version is >=4.1
$class = method_exists(AbstractController::class, 'getParameter') ? AbstractController::class : Controller::class;

return new ClassNameDetails($class, '\\');
return new ClassNameDetails(AbstractController::class, '\\');
}
}
30 changes: 4 additions & 26 deletions src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\MakerBundle\Maker;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
use Doctrine\Inflector\InflectorFactory;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -51,10 +50,7 @@ public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $fo
{
$this->doctrineHelper = $doctrineHelper;
$this->formTypeRenderer = $formTypeRenderer;

if (class_exists(InflectorFactory::class)) {
$this->inflector = InflectorFactory::create()->build();
}
$this->inflector = InflectorFactory::create()->build();
}

public static function getCommandName(): string
Expand Down Expand Up @@ -124,7 +120,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$repositoryVars = [
'repository_full_class_name' => $repositoryClassDetails->getFullName(),
'repository_class_name' => $repositoryClassDetails->getShortName(),
'repository_var' => lcfirst($this->singularize($repositoryClassDetails->getShortName())),
'repository_var' => lcfirst($this->inflector->singularize($repositoryClassDetails->getShortName())),
];
}

Expand All @@ -144,8 +140,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
++$iter;
} while (class_exists($formClassDetails->getFullName()));

$entityVarPlural = lcfirst($this->pluralize($entityClassDetails->getShortName()));
$entityVarSingular = lcfirst($this->singularize($entityClassDetails->getShortName()));
$entityVarPlural = lcfirst($this->inflector->pluralize($entityClassDetails->getShortName()));
$entityVarSingular = lcfirst($this->inflector->singularize($entityClassDetails->getShortName()));

$entityTwigVarPlural = Str::asTwigVariable($entityVarPlural);
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);
Expand Down Expand Up @@ -273,22 +269,4 @@ public function configureDependencies(DependencyBuilder $dependencies)
'annotations'
);
}

private function pluralize(string $word): string
{
if (null !== $this->inflector) {
return $this->inflector->pluralize($word);
}

return LegacyInflector::pluralize($word);
}

private function singularize(string $word): string
{
if (null !== $this->inflector) {
return $this->inflector->singularize($word);
}

return LegacyInflector::singularize($word);
}
}
2 changes: 1 addition & 1 deletion src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ private function doesEntityUseAnnotationMapping(string $className): bool

private function doesEntityUseAttributeMapping(string $className): bool
{
if (\PHP_VERSION < 80000) {
if (\PHP_MAJOR_VERSION < 8) {
return false;
}

Expand Down
13 changes: 2 additions & 11 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\MakerBundle;

use Doctrine\Common\Inflector\Inflector as LegacyInflector;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Symfony\Component\DependencyInjection\Container;
Expand Down Expand Up @@ -220,20 +219,12 @@ public static function asHumanWords(string $variableName): string

private static function pluralize(string $word): string
{
if (class_exists(Inflector::class)) {
return static::getInflector()->pluralize($word);
}

return LegacyInflector::pluralize($word);
return static::getInflector()->pluralize($word);
}

private static function singularize(string $word): string
{
if (class_exists(Inflector::class)) {
return static::getInflector()->singularize($word);
}

return LegacyInflector::singularize($word);
return static::getInflector()->singularize($word);
}

private static function getInflector(): Inflector
Expand Down
19 changes: 5 additions & 14 deletions src/Test/MakerTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,11 @@ public function removeFromFile(string $filename, string $find, bool $allowNotFou

public function configureDatabase(bool $createSchema = true): void
{
// @legacy Drop conditional when Symfony 4.4 is no longer supported.
if (50000 > $this->environment->getSymfonyVersionInApp()) {
$this->replaceInFile(
'.env',
'postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8',
getenv('TEST_DATABASE_DSN')
);
} else {
$this->replaceInFile(
'.env',
'postgresql://symfony:[email protected]:5432/app?serverVersion=13&charset=utf8',
getenv('TEST_DATABASE_DSN')
);
}
$this->replaceInFile(
'.env',
'postgresql://symfony:[email protected]:5432/app?serverVersion=13&charset=utf8',
getenv('TEST_DATABASE_DSN')
);

// Flex includes a recipe to suffix the dbname w/ "_test" - lets keep
// things simple for these tests and not do that.
Expand Down