From fc021501f2542fbd7de5bb06f790d81387978eca Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 21 Apr 2022 14:28:50 -0400 Subject: [PATCH] drop symfony 4.4 support bump minimum Symfony version to 5.4.7 --- .github/workflows/ci.yaml | 22 ++++++++-------- composer.json | 30 +++++++++++----------- src/Doctrine/DoctrineHelper.php | 45 +++++++++++++-------------------- src/Generator.php | 5 +--- src/Maker/MakeCrud.php | 30 +++------------------- src/Maker/MakeEntity.php | 2 +- src/Str.php | 13 ++-------- src/Test/MakerTestRunner.php | 19 ++++---------- 8 files changed, 56 insertions(+), 110 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 02d65ebe5..dfb42ded7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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" diff --git a/composer.json b/composer.json index 54e851bd2..a3662a6e6 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Doctrine/DoctrineHelper.php b/src/Doctrine/DoctrineHelper.php index 8c05db245..10039af5a 100644 --- a/src/Doctrine/DoctrineHelper.php +++ b/src/Doctrine/DoctrineHelper.php @@ -11,11 +11,9 @@ 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; @@ -23,7 +21,6 @@ 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; @@ -44,10 +41,6 @@ final class DoctrineHelper */ private $entityNamespace; private $phpCompatUtil; - - /** - * @var ManagerRegistry - */ private $registry; /** @@ -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; @@ -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 @@ -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); } } @@ -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() : []; } @@ -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); + } } } } @@ -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 diff --git a/src/Generator.php b/src/Generator.php index 133a3de1d..3814c039b 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -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, '\\'); } } diff --git a/src/Maker/MakeCrud.php b/src/Maker/MakeCrud.php index a1e2418d4..e01676bcd 100644 --- a/src/Maker/MakeCrud.php +++ b/src/Maker/MakeCrud.php @@ -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; @@ -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 @@ -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())), ]; } @@ -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); @@ -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); - } } diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 917013d4d..a1732e79e 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -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; } diff --git a/src/Str.php b/src/Str.php index 7e1d52557..b64585403 100644 --- a/src/Str.php +++ b/src/Str.php @@ -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; @@ -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 diff --git a/src/Test/MakerTestRunner.php b/src/Test/MakerTestRunner.php index bde446d3e..17287013d 100644 --- a/src/Test/MakerTestRunner.php +++ b/src/Test/MakerTestRunner.php @@ -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:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8', - getenv('TEST_DATABASE_DSN') - ); - } else { - $this->replaceInFile( - '.env', - 'postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8', - getenv('TEST_DATABASE_DSN') - ); - } + $this->replaceInFile( + '.env', + 'postgresql://symfony:ChangeMe@127.0.0.1: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.