Skip to content

Commit 8d9ab72

Browse files
authored
Merge pull request #10204 from greg0ire/rename-internal-methods
Rename internal methods
2 parents 2b7485a + 12f0674 commit 8d9ab72

File tree

5 files changed

+82
-61
lines changed

5 files changed

+82
-61
lines changed

UPGRADE.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Upgrade to 2.14
22

3+
## Deprecated `AttributeDriver::$entityAnnotationClasses`
4+
5+
If you need to change the behavior of `AttributeDriver::isTransient()`,
6+
override that method instead.
7+
38
## Deprecated incomplete schema updates
49

510
Using `orm:schema-tool:update` without passing the `--complete` flag is

lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php

+57-42
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\ORM\Mapping;
1010
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;
1111
use Doctrine\ORM\Mapping\ClassMetadata;
12+
use Doctrine\ORM\Mapping\MappingAttribute;
1213
use Doctrine\ORM\Mapping\MappingException;
1314
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
1415
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
@@ -30,15 +31,20 @@ class AttributeDriver extends CompatibilityAnnotationDriver
3031
{
3132
use ColocatedMappingDriver;
3233

33-
/** @var array<string,int> */
34-
// @phpcs:ignore
35-
protected $entityAnnotationClasses = [
34+
private const ENTITY_ATTRIBUTE_CLASSES = [
3635
Mapping\Entity::class => 1,
3736
Mapping\MappedSuperclass::class => 2,
3837
];
3938

4039
/**
41-
* The annotation reader.
40+
* @deprecated override isTransient() instead of overriding this property
41+
*
42+
* @var array<class-string<MappingAttribute>, int>
43+
*/
44+
protected $entityAnnotationClasses = self::ENTITY_ATTRIBUTE_CLASSES;
45+
46+
/**
47+
* The attribute reader.
4248
*
4349
* @internal this property will be private in 3.0
4450
*
@@ -58,6 +64,15 @@ public function __construct(array $paths)
5864

5965
$this->reader = new AttributeReader();
6066
$this->addPaths($paths);
67+
68+
if ($this->entityAnnotationClasses !== self::ENTITY_ATTRIBUTE_CLASSES) {
69+
Deprecation::trigger(
70+
'doctrine/orm',
71+
'https://github.com/doctrine/orm/pull/10204',
72+
'Changing the value of %s::$entityAnnotationClasses is deprecated and will have no effect in Doctrine ORM 3.0.',
73+
self::class
74+
);
75+
}
6176
}
6277

6378
/**
@@ -84,11 +99,11 @@ public function getReader()
8499
*/
85100
public function isTransient($className)
86101
{
87-
$classAnnotations = $this->reader->getClassAnnotations(new ReflectionClass($className));
102+
$classAttributes = $this->reader->getClassAttributes(new ReflectionClass($className));
88103

89-
foreach ($classAnnotations as $a) {
90-
$annot = $a instanceof RepeatableAttributeCollection ? $a[0] : $a;
91-
if (isset($this->entityAnnotationClasses[get_class($annot)])) {
104+
foreach ($classAttributes as $a) {
105+
$attr = $a instanceof RepeatableAttributeCollection ? $a[0] : $a;
106+
if (isset($this->entityAnnotationClasses[get_class($attr)])) {
92107
return false;
93108
}
94109
}
@@ -107,13 +122,13 @@ public function isTransient($className)
107122
public function loadMetadataForClass($className, PersistenceClassMetadata $metadata): void
108123
{
109124
$reflectionClass = $metadata->getReflectionClass()
110-
// this happens when running annotation driver in combination with
125+
// this happens when running attribute driver in combination with
111126
// static reflection services. This is not the nicest fix
112127
?? new ReflectionClass($metadata->name);
113128

114-
$classAttributes = $this->reader->getClassAnnotations($reflectionClass);
129+
$classAttributes = $this->reader->getClassAttributes($reflectionClass);
115130

116-
// Evaluate Entity annotation
131+
// Evaluate Entity attribute
117132
if (isset($classAttributes[Mapping\Entity::class])) {
118133
$entityAttribute = $classAttributes[Mapping\Entity::class];
119134
if ($entityAttribute->repositoryClass !== null) {
@@ -226,7 +241,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
226241

227242
$metadata->setPrimaryTable($primaryTable);
228243

229-
// Evaluate @Cache annotation
244+
// Evaluate #[Cache] attribute
230245
if (isset($classAttributes[Mapping\Cache::class])) {
231246
$cacheAttribute = $classAttributes[Mapping\Cache::class];
232247
$cacheMap = [
@@ -237,7 +252,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
237252
$metadata->enableCache($cacheMap);
238253
}
239254

240-
// Evaluate InheritanceType annotation
255+
// Evaluate InheritanceType attribute
241256
if (isset($classAttributes[Mapping\InheritanceType::class])) {
242257
$inheritanceTypeAttribute = $classAttributes[Mapping\InheritanceType::class];
243258

@@ -246,7 +261,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
246261
);
247262

248263
if ($metadata->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
249-
// Evaluate DiscriminatorColumn annotation
264+
// Evaluate DiscriminatorColumn attribute
250265
if (isset($classAttributes[Mapping\DiscriminatorColumn::class])) {
251266
$discrColumnAttribute = $classAttributes[Mapping\DiscriminatorColumn::class];
252267

@@ -262,15 +277,15 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
262277
$metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]);
263278
}
264279

265-
// Evaluate DiscriminatorMap annotation
280+
// Evaluate DiscriminatorMap attribute
266281
if (isset($classAttributes[Mapping\DiscriminatorMap::class])) {
267282
$discrMapAttribute = $classAttributes[Mapping\DiscriminatorMap::class];
268283
$metadata->setDiscriminatorMap($discrMapAttribute->value);
269284
}
270285
}
271286
}
272287

273-
// Evaluate DoctrineChangeTrackingPolicy annotation
288+
// Evaluate DoctrineChangeTrackingPolicy attribute
274289
if (isset($classAttributes[Mapping\ChangeTrackingPolicy::class])) {
275290
$changeTrackingAttribute = $classAttributes[Mapping\ChangeTrackingPolicy::class];
276291
$metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' . $changeTrackingAttribute->value));
@@ -293,8 +308,8 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
293308
$mapping = [];
294309
$mapping['fieldName'] = $property->getName();
295310

296-
// Evaluate @Cache annotation
297-
$cacheAttribute = $this->reader->getPropertyAnnotation($property, Mapping\Cache::class);
311+
// Evaluate #[Cache] attribute
312+
$cacheAttribute = $this->reader->getPropertyAttribute($property, Mapping\Cache::class);
298313
if ($cacheAttribute !== null) {
299314
assert($cacheAttribute instanceof Mapping\Cache);
300315

@@ -307,46 +322,46 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
307322
);
308323
}
309324

310-
// Check for JoinColumn/JoinColumns annotations
325+
// Check for JoinColumn/JoinColumns attributes
311326
$joinColumns = [];
312327

313-
$joinColumnAttributes = $this->reader->getPropertyAnnotationCollection($property, Mapping\JoinColumn::class);
328+
$joinColumnAttributes = $this->reader->getPropertyAttributeCollection($property, Mapping\JoinColumn::class);
314329

315330
foreach ($joinColumnAttributes as $joinColumnAttribute) {
316331
$joinColumns[] = $this->joinColumnToArray($joinColumnAttribute);
317332
}
318333

319334
// Field can only be attributed with one of:
320335
// Column, OneToOne, OneToMany, ManyToOne, ManyToMany, Embedded
321-
$columnAttribute = $this->reader->getPropertyAnnotation($property, Mapping\Column::class);
322-
$oneToOneAttribute = $this->reader->getPropertyAnnotation($property, Mapping\OneToOne::class);
323-
$oneToManyAttribute = $this->reader->getPropertyAnnotation($property, Mapping\OneToMany::class);
324-
$manyToOneAttribute = $this->reader->getPropertyAnnotation($property, Mapping\ManyToOne::class);
325-
$manyToManyAttribute = $this->reader->getPropertyAnnotation($property, Mapping\ManyToMany::class);
326-
$embeddedAttribute = $this->reader->getPropertyAnnotation($property, Mapping\Embedded::class);
336+
$columnAttribute = $this->reader->getPropertyAttribute($property, Mapping\Column::class);
337+
$oneToOneAttribute = $this->reader->getPropertyAttribute($property, Mapping\OneToOne::class);
338+
$oneToManyAttribute = $this->reader->getPropertyAttribute($property, Mapping\OneToMany::class);
339+
$manyToOneAttribute = $this->reader->getPropertyAttribute($property, Mapping\ManyToOne::class);
340+
$manyToManyAttribute = $this->reader->getPropertyAttribute($property, Mapping\ManyToMany::class);
341+
$embeddedAttribute = $this->reader->getPropertyAttribute($property, Mapping\Embedded::class);
327342

328343
if ($columnAttribute !== null) {
329344
$mapping = $this->columnToArray($property->getName(), $columnAttribute);
330345

331-
if ($this->reader->getPropertyAnnotation($property, Mapping\Id::class)) {
346+
if ($this->reader->getPropertyAttribute($property, Mapping\Id::class)) {
332347
$mapping['id'] = true;
333348
}
334349

335-
$generatedValueAttribute = $this->reader->getPropertyAnnotation($property, Mapping\GeneratedValue::class);
350+
$generatedValueAttribute = $this->reader->getPropertyAttribute($property, Mapping\GeneratedValue::class);
336351

337352
if ($generatedValueAttribute !== null) {
338353
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAttribute->strategy));
339354
}
340355

341-
if ($this->reader->getPropertyAnnotation($property, Mapping\Version::class)) {
356+
if ($this->reader->getPropertyAttribute($property, Mapping\Version::class)) {
342357
$metadata->setVersionMapping($mapping);
343358
}
344359

345360
$metadata->mapField($mapping);
346361

347362
// Check for SequenceGenerator/TableGenerator definition
348-
$seqGeneratorAttribute = $this->reader->getPropertyAnnotation($property, Mapping\SequenceGenerator::class);
349-
$customGeneratorAttribute = $this->reader->getPropertyAnnotation($property, Mapping\CustomIdGenerator::class);
363+
$seqGeneratorAttribute = $this->reader->getPropertyAttribute($property, Mapping\SequenceGenerator::class);
364+
$customGeneratorAttribute = $this->reader->getPropertyAttribute($property, Mapping\CustomIdGenerator::class);
350365

351366
if ($seqGeneratorAttribute !== null) {
352367
$metadata->setSequenceGeneratorDefinition(
@@ -364,7 +379,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
364379
);
365380
}
366381
} elseif ($oneToOneAttribute !== null) {
367-
if ($this->reader->getPropertyAnnotation($property, Mapping\Id::class)) {
382+
if ($this->reader->getPropertyAttribute($property, Mapping\Id::class)) {
368383
$mapping['id'] = true;
369384
}
370385

@@ -384,15 +399,15 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
384399
$mapping['orphanRemoval'] = $oneToManyAttribute->orphanRemoval;
385400
$mapping['fetch'] = $this->getFetchMode($className, $oneToManyAttribute->fetch);
386401

387-
$orderByAttribute = $this->reader->getPropertyAnnotation($property, Mapping\OrderBy::class);
402+
$orderByAttribute = $this->reader->getPropertyAttribute($property, Mapping\OrderBy::class);
388403

389404
if ($orderByAttribute !== null) {
390405
$mapping['orderBy'] = $orderByAttribute->value;
391406
}
392407

393408
$metadata->mapOneToMany($mapping);
394409
} elseif ($manyToOneAttribute !== null) {
395-
$idAttribute = $this->reader->getPropertyAnnotation($property, Mapping\Id::class);
410+
$idAttribute = $this->reader->getPropertyAttribute($property, Mapping\Id::class);
396411

397412
if ($idAttribute !== null) {
398413
$mapping['id'] = true;
@@ -406,7 +421,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
406421
$metadata->mapManyToOne($mapping);
407422
} elseif ($manyToManyAttribute !== null) {
408423
$joinTable = [];
409-
$joinTableAttribute = $this->reader->getPropertyAnnotation($property, Mapping\JoinTable::class);
424+
$joinTableAttribute = $this->reader->getPropertyAttribute($property, Mapping\JoinTable::class);
410425

411426
if ($joinTableAttribute !== null) {
412427
$joinTable = [
@@ -419,11 +434,11 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
419434
}
420435
}
421436

422-
foreach ($this->reader->getPropertyAnnotationCollection($property, Mapping\JoinColumn::class) as $joinColumn) {
437+
foreach ($this->reader->getPropertyAttributeCollection($property, Mapping\JoinColumn::class) as $joinColumn) {
423438
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
424439
}
425440

426-
foreach ($this->reader->getPropertyAnnotationCollection($property, Mapping\InverseJoinColumn::class) as $joinColumn) {
441+
foreach ($this->reader->getPropertyAttributeCollection($property, Mapping\InverseJoinColumn::class) as $joinColumn) {
427442
$joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
428443
}
429444

@@ -436,7 +451,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
436451
$mapping['orphanRemoval'] = $manyToManyAttribute->orphanRemoval;
437452
$mapping['fetch'] = $this->getFetchMode($className, $manyToManyAttribute->fetch);
438453

439-
$orderByAttribute = $this->reader->getPropertyAnnotation($property, Mapping\OrderBy::class);
454+
$orderByAttribute = $this->reader->getPropertyAttribute($property, Mapping\OrderBy::class);
440455

441456
if ($orderByAttribute !== null) {
442457
$mapping['orderBy'] = $orderByAttribute->value;
@@ -509,7 +524,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
509524
}
510525
}
511526

512-
// Evaluate AttributeOverrides annotation
527+
// Evaluate AttributeOverrides attribute
513528
if (isset($classAttributes[Mapping\AttributeOverrides::class])) {
514529
$attributeOverridesAnnot = $classAttributes[Mapping\AttributeOverrides::class];
515530

@@ -520,7 +535,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
520535
}
521536
}
522537

523-
// Evaluate EntityListeners annotation
538+
// Evaluate EntityListeners attribute
524539
if (isset($classAttributes[Mapping\EntityListeners::class])) {
525540
$entityListenersAttribute = $classAttributes[Mapping\EntityListeners::class];
526541

@@ -552,7 +567,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
552567
}
553568
}
554569

555-
// Evaluate @HasLifecycleCallbacks annotation
570+
// Evaluate #[HasLifecycleCallbacks] attribute
556571
if (isset($classAttributes[Mapping\HasLifecycleCallbacks::class])) {
557572
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
558573
assert($method instanceof ReflectionMethod);
@@ -604,7 +619,7 @@ private function getGeneratedMode(string $generatedMode): int
604619
private function getMethodCallbacks(ReflectionMethod $method): array
605620
{
606621
$callbacks = [];
607-
$attributes = $this->reader->getMethodAnnotations($method);
622+
$attributes = $this->reader->getMethodAttributes($method);
608623

609624
foreach ($attributes as $attribute) {
610625
if ($attribute instanceof Mapping\PrePersist) {

lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class AttributeReader
2828
*
2929
* @template T of Annotation
3030
*/
31-
public function getClassAnnotations(ReflectionClass $class): array
31+
public function getClassAttributes(ReflectionClass $class): array
3232
{
3333
return $this->convertToAttributeInstances($class->getAttributes());
3434
}
@@ -38,7 +38,7 @@ public function getClassAnnotations(ReflectionClass $class): array
3838
*
3939
* @template T of Annotation
4040
*/
41-
public function getMethodAnnotations(ReflectionMethod $method): array
41+
public function getMethodAttributes(ReflectionMethod $method): array
4242
{
4343
return $this->convertToAttributeInstances($method->getAttributes());
4444
}
@@ -48,7 +48,7 @@ public function getMethodAnnotations(ReflectionMethod $method): array
4848
*
4949
* @template T of Annotation
5050
*/
51-
public function getPropertyAnnotations(ReflectionProperty $property): array
51+
public function getPropertyAttributes(ReflectionProperty $property): array
5252
{
5353
return $this->convertToAttributeInstances($property->getAttributes());
5454
}
@@ -60,16 +60,16 @@ public function getPropertyAnnotations(ReflectionProperty $property): array
6060
*
6161
* @template T of Annotation
6262
*/
63-
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
63+
public function getPropertyAttribute(ReflectionProperty $property, $annotationName)
6464
{
6565
if ($this->isRepeatable($annotationName)) {
6666
throw new LogicException(sprintf(
67-
'The attribute "%s" is repeatable. Call getPropertyAnnotationCollection() instead.',
67+
'The attribute "%s" is repeatable. Call getPropertyAttributeCollection() instead.',
6868
$annotationName
6969
));
7070
}
7171

72-
return $this->getPropertyAnnotations($property)[$annotationName]
72+
return $this->getPropertyAttributes($property)[$annotationName]
7373
?? ($this->isRepeatable($annotationName) ? new RepeatableAttributeCollection() : null);
7474
}
7575

@@ -80,18 +80,18 @@ public function getPropertyAnnotation(ReflectionProperty $property, $annotationN
8080
*
8181
* @template T of Annotation
8282
*/
83-
public function getPropertyAnnotationCollection(
83+
public function getPropertyAttributeCollection(
8484
ReflectionProperty $property,
8585
string $annotationName
8686
): RepeatableAttributeCollection {
8787
if (! $this->isRepeatable($annotationName)) {
8888
throw new LogicException(sprintf(
89-
'The attribute "%s" is not repeatable. Call getPropertyAnnotation() instead.',
89+
'The attribute "%s" is not repeatable. Call getPropertyAttribute() instead.',
9090
$annotationName
9191
));
9292
}
9393

94-
return $this->getPropertyAnnotations($property)[$annotationName] ?? new RepeatableAttributeCollection();
94+
return $this->getPropertyAttributes($property)[$annotationName] ?? new RepeatableAttributeCollection();
9595
}
9696

9797
/**
@@ -108,7 +108,7 @@ private function convertToAttributeInstances(array $attributes): array
108108
foreach ($attributes as $attribute) {
109109
$attributeName = $attribute->getName();
110110
assert(is_string($attributeName));
111-
// Make sure we only get Doctrine Annotations
111+
// Make sure we only get Doctrine Attributes
112112
if (! is_subclass_of($attributeName, Annotation::class)) {
113113
continue;
114114
}

psalm.xml

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<DeprecatedProperty>
9393
<errorLevel type="suppress">
9494
<referencedProperty name="Doctrine\ORM\Cache\Region\DefaultRegion::$cache"/>
95+
<referencedProperty name="Doctrine\ORM\Mapping\Driver\AttributeDriver::$entityAnnotationClasses"/>
9596
</errorLevel>
9697
</DeprecatedProperty>
9798
<DocblockTypeContradiction>

0 commit comments

Comments
 (0)