Skip to content

Commit 09f9cbf

Browse files
committed
feature #1126 drop annotation support with entities (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- drop annotation support with entities Commits ------- e70cc83 drop annotation support with entities
2 parents 580fed5 + e70cc83 commit 09f9cbf

Some content is hidden

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

49 files changed

+393
-786
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"sort-packages": true
4343
},
4444
"conflict": {
45-
"doctrine/orm": "<2.10"
45+
"doctrine/orm": "<2.10",
46+
"doctrine/doctrine-bundle": "<2.4",
47+
"symfony/doctrine-bridge": "<5.4"
4648
},
4749
"autoload": {
4850
"psr-4": { "Symfony\\Bundle\\MakerBundle\\": "src/" }

src/DependencyInjection/CompilerPass/DoctrineAttributesCheckPass.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/DependencyInjection/CompilerPass/SetDoctrineAnnotatedPrefixesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process(ContainerBuilder $container): void
6363
}
6464

6565
if (null !== $annotatedPrefixes) {
66-
$container->getDefinition('maker.doctrine_helper')->setArgument(4, $annotatedPrefixes);
66+
$container->getDefinition('maker.doctrine_helper')->setArgument(2, $annotatedPrefixes);
6767
}
6868
}
6969
}

src/Doctrine/BaseCollectionRelation.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
abstract class BaseCollectionRelation extends BaseRelation
2020
{
21-
abstract public function getOrphanRemoval(): bool;
22-
2321
abstract public function getTargetSetterMethodName(): string;
2422

2523
public function getAdderMethodName(): string

src/Doctrine/BaseRelation.php

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,88 +16,51 @@
1616
*/
1717
abstract class BaseRelation
1818
{
19-
private $propertyName;
20-
private $targetClassName;
21-
private $targetPropertyName;
22-
private $customReturnType;
23-
private $isSelfReferencing = false;
24-
private $mapInverseRelation = true;
25-
private $avoidSetter = false;
26-
27-
abstract public function isOwning(): bool;
19+
public function __construct(
20+
private string $propertyName,
21+
private string $targetClassName,
22+
private ?string $targetPropertyName = null,
23+
private bool $isSelfReferencing = false,
24+
private bool $mapInverseRelation = true,
25+
private bool $avoidSetter = false,
26+
private bool $isCustomReturnTypeNullable = false,
27+
private ?string $customReturnType = null,
28+
private bool $isOwning = false,
29+
private bool $orphanRemoval = false,
30+
private bool $isNullable = false,
31+
) {
32+
}
2833

2934
public function getPropertyName(): string
3035
{
3136
return $this->propertyName;
3237
}
3338

34-
public function setPropertyName(string $propertyName): self
35-
{
36-
$this->propertyName = $propertyName;
37-
38-
return $this;
39-
}
40-
4139
public function getTargetClassName(): string
4240
{
4341
return $this->targetClassName;
4442
}
4543

46-
public function setTargetClassName(string $targetClassName): self
47-
{
48-
$this->targetClassName = $targetClassName;
49-
50-
return $this;
51-
}
52-
5344
public function getTargetPropertyName(): ?string
5445
{
5546
return $this->targetPropertyName;
5647
}
5748

58-
public function setTargetPropertyName(?string $targetPropertyName): self
59-
{
60-
$this->targetPropertyName = $targetPropertyName;
61-
62-
return $this;
63-
}
64-
6549
public function isSelfReferencing(): bool
6650
{
6751
return $this->isSelfReferencing;
6852
}
6953

70-
public function setIsSelfReferencing(bool $isSelfReferencing): self
71-
{
72-
$this->isSelfReferencing = $isSelfReferencing;
73-
74-
return $this;
75-
}
76-
7754
public function getMapInverseRelation(): bool
7855
{
7956
return $this->mapInverseRelation;
8057
}
8158

82-
public function setMapInverseRelation(bool $mapInverseRelation): self
83-
{
84-
$this->mapInverseRelation = $mapInverseRelation;
85-
86-
return $this;
87-
}
88-
8959
public function shouldAvoidSetter(): bool
9060
{
9161
return $this->avoidSetter;
9262
}
9363

94-
public function avoidSetter(bool $avoidSetter = true): self
95-
{
96-
$this->avoidSetter = $avoidSetter;
97-
98-
return $this;
99-
}
100-
10164
public function getCustomReturnType(): ?string
10265
{
10366
return $this->customReturnType;
@@ -108,11 +71,18 @@ public function isCustomReturnTypeNullable(): bool
10871
return $this->isCustomReturnTypeNullable;
10972
}
11073

111-
public function setCustomReturnType(string $customReturnType, bool $isNullable)
74+
public function isOwning(): bool
11275
{
113-
$this->customReturnType = $customReturnType;
114-
$this->isCustomReturnTypeNullable = $isNullable;
76+
return $this->isOwning;
77+
}
11578

116-
return $this;
79+
public function getOrphanRemoval(): bool
80+
{
81+
return $this->orphanRemoval;
82+
}
83+
84+
public function isNullable(): bool
85+
{
86+
return $this->isNullable;
11787
}
11888
}

src/Doctrine/BaseSingleRelation.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Doctrine/DoctrineHelper.php

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\ORM\EntityManagerInterface;
16-
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
1716
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
1817
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
1918
use Doctrine\ORM\Mapping\NamingStrategy;
@@ -25,7 +24,6 @@
2524
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
2625
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
2726
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
28-
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
2927

3028
/**
3129
* @author Fabien Potencier <[email protected]>
@@ -36,27 +34,12 @@
3634
*/
3735
final class DoctrineHelper
3836
{
39-
/**
40-
* @var string
41-
*/
42-
private $entityNamespace;
43-
private $phpCompatUtil;
44-
private $registry;
45-
46-
/**
47-
* @var array|null
48-
*/
49-
private $mappingDriversByPrefix;
50-
51-
private $attributeMappingSupport;
52-
53-
public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, ManagerRegistry $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
54-
{
37+
public function __construct(
38+
private string $entityNamespace,
39+
private ?ManagerRegistry $registry = null,
40+
private ?array $mappingDriversByPrefix = null,
41+
) {
5542
$this->entityNamespace = trim($entityNamespace, '\\');
56-
$this->phpCompatUtil = $phpCompatUtil;
57-
$this->registry = $registry;
58-
$this->attributeMappingSupport = $attributeMappingSupport;
59-
$this->mappingDriversByPrefix = $annotatedPrefixes;
6043
}
6144

6245
public function getRegistry(): ManagerRegistry
@@ -114,7 +97,7 @@ public function doesClassUseDriver(string $className, string $driverClass): bool
11497
}
11598

11699
foreach ($metadataDriver->getDrivers() as $namespace => $driver) {
117-
if (0 === strpos($className, $namespace)) {
100+
if (str_starts_with($className, $namespace)) {
118101
return $this->isInstanceOf($driver, $driverClass);
119102
}
120103
}
@@ -125,27 +108,22 @@ public function doesClassUseDriver(string $className, string $driverClass): bool
125108
$managerName = array_search($em, $this->getRegistry()->getManagers(), true);
126109

127110
foreach ($this->mappingDriversByPrefix[$managerName] as [$prefix, $prefixDriver]) {
128-
if (0 === strpos($className, $prefix)) {
111+
if (str_starts_with($className, $prefix)) {
129112
return $this->isInstanceOf($prefixDriver, $driverClass);
130113
}
131114
}
132115

133116
return false;
134117
}
135118

136-
public function isClassAnnotated(string $className): bool
137-
{
138-
return $this->doesClassUseDriver($className, AnnotationDriver::class);
139-
}
140-
141119
public function doesClassUsesAttributes(string $className): bool
142120
{
143121
return $this->doesClassUseDriver($className, AttributeDriver::class);
144122
}
145123

146124
public function isDoctrineSupportingAttributes(): bool
147125
{
148-
return $this->isDoctrineInstalled() && $this->attributeMappingSupport;
126+
return $this->isDoctrineInstalled();
149127
}
150128

151129
public function getEntitiesForAutocomplete(): array
@@ -168,18 +146,14 @@ public function getEntitiesForAutocomplete(): array
168146

169147
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false): array|ClassMetadata
170148
{
171-
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
149+
// Invalidating the cached AttributeDriver::$classNames to find new Entity classes
172150
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) {
173-
foreach ($prefixes as [$prefix, $annotationDriver]) {
174-
if (null !== $annotationDriver) {
175-
if ($annotationDriver instanceof AnnotationDriver) {
176-
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
177-
} else {
178-
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames');
179-
}
151+
foreach ($prefixes as [$prefix, $attributeDriver]) {
152+
if ($attributeDriver instanceof AttributeDriver) {
153+
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames');
180154

181155
$classNames->setAccessible(true);
182-
$classNames->setValue($annotationDriver, null);
156+
$classNames->setValue($attributeDriver, null);
183157
}
184158
}
185159
}
@@ -205,14 +179,11 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
205179
}
206180

207181
if (null === $this->mappingDriversByPrefix) {
208-
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
182+
// Invalidating the cached AttributeDriver::$classNames to find new Entity classes
209183
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
184+
210185
if ($this->isInstanceOf($metadataDriver, MappingDriverChain::class)) {
211186
foreach ($metadataDriver->getDrivers() as $driver) {
212-
if ($this->isInstanceOf($driver, AnnotationDriver::class)) {
213-
$classNames->setValue($driver, null);
214-
}
215-
216187
if ($this->isInstanceOf($driver, AttributeDriver::class)) {
217188
$classNames->setValue($driver, null);
218189
}
@@ -229,7 +200,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
229200
return $m;
230201
}
231202

232-
if (0 === strpos($m->getName(), $classOrNamespace)) {
203+
if (str_starts_with($m->getName(), $classOrNamespace)) {
233204
$metadata[$m->getName()] = $m;
234205
}
235206
}

src/Doctrine/EntityClassGenerator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $
7070
'broadcast' => $broadcast,
7171
'should_escape_table_name' => $this->doctrineHelper->isKeyword($tableName),
7272
'table_name' => $tableName,
73-
'doctrine_use_attributes' => $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($entityClassDetails->getFullName()),
7473
]
7574
);
7675

0 commit comments

Comments
 (0)