Skip to content

Commit 5e93711

Browse files
committed
feature #1098 drop symfony 4.4 support bump minimum Symfony version to 5.4.7 (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- drop symfony 4.4 support bump minimum Symfony version to 5.4.7 - MakerBundle Now supports Symfony >= `5.4.7` - Minimum PHP Version >= `7.2.5` - Removes legacy internal code - Reduces some Doctrine complexity (Leaves the door open to continue this effort in future PR's) - Fixes #1090 Commits ------- fc02150 drop symfony 4.4 support bump minimum Symfony version to 5.4.7
2 parents f2b99ba + fc02150 commit 5e93711

File tree

8 files changed

+56
-110
lines changed

8 files changed

+56
-110
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,27 @@ jobs:
9292
php-version:
9393
- '8.0'
9494
symfony-version:
95-
- '4.4.*'
96-
- '5.3.*'
95+
- '5.4.*'
9796
- '5.4.x-dev'
9897
- '6.0.x-dev'
9998
dependency-versions: ['highest']
10099
allow-dev-deps-in-apps: ['0']
101100
include:
102101
# testing lowest PHP version with LTS
103-
- php-version: '7.1.3'
104-
symfony-version: '4.4.*'
105-
# not important - does not affect each app's dependencies
106-
dependency-versions: 'highest'
107-
# testing lowest php version with highest 5.x stable
108102
- php-version: '7.2.5'
109-
symfony-version: '5.3.*'
103+
symfony-version: '5.4.*'
110104
dependency-versions: 'lowest'
105+
# testing lowest php version with highest 5.x stable
106+
- php-version: '7.2.5'
107+
symfony-version: '5.4.*'
108+
dependency-versions: 'highest'
111109
# testing bleeding edge PHP with highest 5.x stable
112110
- php-version: '8.1'
113-
symfony-version: '5.3.*'
111+
symfony-version: '5.4.*'
112+
dependency-versions: 'highest'
113+
- php-version: '8.1'
114+
symfony-version: '6.1.*-dev'
114115
dependency-versions: 'highest'
115-
# temporarily needed until some packages support php 8.1
116116
allow-dev-deps-in-apps: '1'
117117

118118
steps:
@@ -136,7 +136,7 @@ jobs:
136136
with:
137137
coverage: "none"
138138
php-version: ${{ matrix.php-version }}
139-
tools: composer:2.2
139+
tools: composer:v2
140140

141141
- name: "Add PHPUnit matcher"
142142
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

composer.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
],
1414
"minimum-stability": "dev",
1515
"require": {
16-
"php": ">=7.1.3",
17-
"doctrine/inflector": "^1.2|^2.0",
16+
"php": ">=7.2.5",
17+
"doctrine/inflector": "^2.0",
1818
"nikic/php-parser": "^4.11",
19-
"symfony/config": "^4.4|^5.0|^6.0",
20-
"symfony/console": "^4.4|^5.0|^6.0",
21-
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
19+
"symfony/config": "^5.4.7|^6.0",
20+
"symfony/console": "^5.4.7|^6.0",
21+
"symfony/dependency-injection": "^5.4.7|^6.0",
2222
"symfony/deprecation-contracts": "^2.2|^3",
23-
"symfony/filesystem": "^4.4|^5.0|^6.0",
24-
"symfony/finder": "^4.4|^5.0|^6.0",
25-
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
26-
"symfony/http-kernel": "^4.4|^5.0|^6.0"
23+
"symfony/filesystem": "^5.4.7|^6.0",
24+
"symfony/finder": "^5.4.7|^6.0",
25+
"symfony/framework-bundle": "^5.4.7|^6.0",
26+
"symfony/http-kernel": "^5.4.7|^6.0"
2727
},
2828
"require-dev": {
2929
"composer/semver": "^3.0",
30-
"doctrine/doctrine-bundle": "^1.12.3|^2.0",
30+
"doctrine/doctrine-bundle": "^2.4",
3131
"doctrine/orm": "^2.3",
32-
"symfony/http-client": "^4.4|^5.0|^6.0",
33-
"symfony/phpunit-bridge": "^4.4|^5.0|^6.0",
32+
"symfony/http-client": "^5.4.7|^6.0",
33+
"symfony/phpunit-bridge": "^5.4.7|^6.0",
3434
"symfony/polyfill-php80": "^1.16.0",
35-
"symfony/process": "^4.4|^5.0|^6.0",
36-
"symfony/security-core": "^4.4|^5.0|^6.0",
37-
"symfony/yaml": "^4.4|^5.0|^6.0",
35+
"symfony/process": "^5.4.7|^6.0",
36+
"symfony/security-core": "^5.4.7|^6.0",
37+
"symfony/yaml": "^5.4.7|^6.0",
3838
"twig/twig": "^2.0|^3.0"
3939
},
4040
"config": {

src/Doctrine/DoctrineHelper.php

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15-
use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
16-
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyPersistenceMappingException;
1714
use Doctrine\DBAL\Connection;
1815
use Doctrine\ORM\EntityManagerInterface;
16+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
1917
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
2018
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
2119
use Doctrine\ORM\Mapping\NamingStrategy;
2220
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
2321
use Doctrine\Persistence\ManagerRegistry;
2422
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
2523
use Doctrine\Persistence\Mapping\ClassMetadata;
26-
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver;
2724
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
2825
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
2926
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
@@ -44,10 +41,6 @@ final class DoctrineHelper
4441
*/
4542
private $entityNamespace;
4643
private $phpCompatUtil;
47-
48-
/**
49-
* @var ManagerRegistry
50-
*/
5144
private $registry;
5245

5346
/**
@@ -57,10 +50,7 @@ final class DoctrineHelper
5750

5851
private $attributeMappingSupport;
5952

60-
/**
61-
* @var ManagerRegistry|LegacyManagerRegistry
62-
*/
63-
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
53+
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, ManagerRegistry $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
6454
{
6555
$this->entityNamespace = trim($entityNamespace, '\\');
6656
$this->phpCompatUtil = $phpCompatUtil;
@@ -69,10 +59,7 @@ public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUti
6959
$this->mappingDriversByPrefix = $annotatedPrefixes;
7060
}
7161

72-
/**
73-
* @return LegacyManagerRegistry|ManagerRegistry
74-
*/
75-
public function getRegistry()
62+
public function getRegistry(): ManagerRegistry
7663
{
7764
// this should never happen: we will have checked for the
7865
// DoctrineBundle dependency before calling this
@@ -173,17 +160,21 @@ public function getEntitiesForAutocomplete(): array
173160
}
174161

175162
/**
176-
* @return array|ClassMetadata|LegacyClassMetadata
163+
* @return array|ClassMetadata
177164
*/
178165
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
179166
{
180-
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
181-
$classNames->setAccessible(true);
182-
183167
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
184168
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) {
185169
foreach ($prefixes as [$prefix, $annotationDriver]) {
186170
if (null !== $annotationDriver) {
171+
if ($annotationDriver instanceof AnnotationDriver) {
172+
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
173+
} else {
174+
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames');
175+
}
176+
177+
$classNames->setAccessible(true);
187178
$classNames->setValue($annotationDriver, null);
188179
}
189180
}
@@ -198,11 +189,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
198189
if ($disconnected) {
199190
try {
200191
$loaded = $cmf->getAllMetadata();
201-
} catch (ORMMappingException $e) {
202-
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
203-
} catch (LegacyPersistenceMappingException $e) {
204-
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
205-
} catch (PersistenceMappingException $e) {
192+
} catch (ORMMappingException|PersistenceMappingException $e) {
206193
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
207194
}
208195

@@ -221,6 +208,10 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
221208
if ($this->isInstanceOf($driver, AnnotationDriver::class)) {
222209
$classNames->setValue($driver, null);
223210
}
211+
212+
if ($this->isInstanceOf($driver, AttributeDriver::class)) {
213+
$classNames->setValue($driver, null);
214+
}
224215
}
225216
}
226217
}
@@ -270,9 +261,7 @@ private function isInstanceOf($object, string $class): bool
270261
return false;
271262
}
272263

273-
$legacyClass = str_replace('Doctrine\\Persistence\\', 'Doctrine\\Common\\Persistence\\', $class);
274-
275-
return $object instanceof $class || $object instanceof $legacyClass;
264+
return $object instanceof $class;
276265
}
277266

278267
public function getPotentialTableName(string $className): string

src/Generator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ public function generateTemplate(string $targetPath, string $templateName, array
248248

249249
public static function getControllerBaseClass(): ClassNameDetails
250250
{
251-
// @legacy Support for Controller::class can be dropped when FrameworkBundle minimum supported version is >=4.1
252-
$class = method_exists(AbstractController::class, 'getParameter') ? AbstractController::class : Controller::class;
253-
254-
return new ClassNameDetails($class, '\\');
251+
return new ClassNameDetails(AbstractController::class, '\\');
255252
}
256253
}

src/Maker/MakeCrud.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
15-
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
1615
use Doctrine\Inflector\InflectorFactory;
1716
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
1817
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -51,10 +50,7 @@ public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $fo
5150
{
5251
$this->doctrineHelper = $doctrineHelper;
5352
$this->formTypeRenderer = $formTypeRenderer;
54-
55-
if (class_exists(InflectorFactory::class)) {
56-
$this->inflector = InflectorFactory::create()->build();
57-
}
53+
$this->inflector = InflectorFactory::create()->build();
5854
}
5955

6056
public static function getCommandName(): string
@@ -124,7 +120,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
124120
$repositoryVars = [
125121
'repository_full_class_name' => $repositoryClassDetails->getFullName(),
126122
'repository_class_name' => $repositoryClassDetails->getShortName(),
127-
'repository_var' => lcfirst($this->singularize($repositoryClassDetails->getShortName())),
123+
'repository_var' => lcfirst($this->inflector->singularize($repositoryClassDetails->getShortName())),
128124
];
129125
}
130126

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

147-
$entityVarPlural = lcfirst($this->pluralize($entityClassDetails->getShortName()));
148-
$entityVarSingular = lcfirst($this->singularize($entityClassDetails->getShortName()));
143+
$entityVarPlural = lcfirst($this->inflector->pluralize($entityClassDetails->getShortName()));
144+
$entityVarSingular = lcfirst($this->inflector->singularize($entityClassDetails->getShortName()));
149145

150146
$entityTwigVarPlural = Str::asTwigVariable($entityVarPlural);
151147
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);
@@ -273,22 +269,4 @@ public function configureDependencies(DependencyBuilder $dependencies)
273269
'annotations'
274270
);
275271
}
276-
277-
private function pluralize(string $word): string
278-
{
279-
if (null !== $this->inflector) {
280-
return $this->inflector->pluralize($word);
281-
}
282-
283-
return LegacyInflector::pluralize($word);
284-
}
285-
286-
private function singularize(string $word): string
287-
{
288-
if (null !== $this->inflector) {
289-
return $this->inflector->singularize($word);
290-
}
291-
292-
return LegacyInflector::singularize($word);
293-
}
294272
}

src/Maker/MakeEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ private function doesEntityUseAnnotationMapping(string $className): bool
859859

860860
private function doesEntityUseAttributeMapping(string $className): bool
861861
{
862-
if (\PHP_VERSION < 80000) {
862+
if (\PHP_MAJOR_VERSION < 8) {
863863
return false;
864864
}
865865

src/Str.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\MakerBundle;
1313

14-
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
1514
use Doctrine\Inflector\Inflector;
1615
use Doctrine\Inflector\InflectorFactory;
1716
use Symfony\Component\DependencyInjection\Container;
@@ -220,20 +219,12 @@ public static function asHumanWords(string $variableName): string
220219

221220
private static function pluralize(string $word): string
222221
{
223-
if (class_exists(Inflector::class)) {
224-
return static::getInflector()->pluralize($word);
225-
}
226-
227-
return LegacyInflector::pluralize($word);
222+
return static::getInflector()->pluralize($word);
228223
}
229224

230225
private static function singularize(string $word): string
231226
{
232-
if (class_exists(Inflector::class)) {
233-
return static::getInflector()->singularize($word);
234-
}
235-
236-
return LegacyInflector::singularize($word);
227+
return static::getInflector()->singularize($word);
237228
}
238229

239230
private static function getInflector(): Inflector

src/Test/MakerTestRunner.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,11 @@ public function removeFromFile(string $filename, string $find, bool $allowNotFou
170170

171171
public function configureDatabase(bool $createSchema = true): void
172172
{
173-
// @legacy Drop conditional when Symfony 4.4 is no longer supported.
174-
if (50000 > $this->environment->getSymfonyVersionInApp()) {
175-
$this->replaceInFile(
176-
'.env',
177-
'postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8',
178-
getenv('TEST_DATABASE_DSN')
179-
);
180-
} else {
181-
$this->replaceInFile(
182-
'.env',
183-
'postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8',
184-
getenv('TEST_DATABASE_DSN')
185-
);
186-
}
173+
$this->replaceInFile(
174+
'.env',
175+
'postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8',
176+
getenv('TEST_DATABASE_DSN')
177+
);
187178

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

0 commit comments

Comments
 (0)