Skip to content

Commit a70732e

Browse files
Use properties instead of getters to read property/class names via reflection
1 parent bc61d7d commit a70732e

9 files changed

+21
-21
lines changed

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ public function initializeReflection($reflService)
11761176
$this->namespace = $reflService->getClassNamespace($this->name);
11771177

11781178
if ($this->reflClass) {
1179-
$this->name = $this->rootEntityName = $this->reflClass->getName();
1179+
$this->name = $this->rootEntityName = $this->reflClass->name;
11801180
}
11811181

11821182
$this->table['name'] = $this->namingStrategy->classToTableName($this->name);
@@ -3866,7 +3866,7 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c
38663866
{
38673867
$reflectionProperty = $reflService->getAccessibleProperty($class, $field);
38683868
if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) {
3869-
$declaringClass = $reflectionProperty->getDeclaringClass()->name;
3869+
$declaringClass = $reflectionProperty->class;
38703870
if ($declaringClass !== $class) {
38713871
$reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field);
38723872
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
365365
}
366366

367367
$mapping = [];
368-
$mapping['fieldName'] = $property->getName();
368+
$mapping['fieldName'] = $property->name;
369369

370370
// Evaluate @Cache annotation
371371
$cacheAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Cache::class);
@@ -398,7 +398,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
398398
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
399399
$columnAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Column::class);
400400
if ($columnAnnot) {
401-
$mapping = $this->columnToArray($property->getName(), $columnAnnot);
401+
$mapping = $this->columnToArray($property->name, $columnAnnot);
402402

403403
$idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class);
404404
if ($idAnnot) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
315315
}
316316

317317
$mapping = [];
318-
$mapping['fieldName'] = $property->getName();
318+
$mapping['fieldName'] = $property->name;
319319

320320
// Evaluate #[Cache] attribute
321321
$cacheAttribute = $this->reader->getPropertyAttribute($property, Mapping\Cache::class);
@@ -350,7 +350,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
350350
$embeddedAttribute = $this->reader->getPropertyAttribute($property, Mapping\Embedded::class);
351351

352352
if ($columnAttribute !== null) {
353-
$mapping = $this->columnToArray($property->getName(), $columnAttribute);
353+
$mapping = $this->columnToArray($property->name, $columnAttribute);
354354

355355
if ($this->reader->getPropertyAttribute($property, Mapping\Id::class)) {
356356
$mapping['id'] = true;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private function isRepeatedPropertyDeclaration(ReflectionProperty $property, Cla
3232
|| $metadata->isInheritedEmbeddedClass($property->name);
3333
}
3434

35-
$declaringClass = $property->getDeclaringClass()->getName();
35+
$declaringClass = $property->class;
3636

3737
if (
3838
isset($metadata->fieldMappings[$property->name]['declared'])

lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function getHierarchyClasses(string $className): array
7373

7474
$parentClass = $currentClass->getParentClass();
7575
if ($parentClass) {
76-
$parentClassName = $parentClass->getName();
76+
$parentClassName = $parentClass->name;
7777
}
7878
}
7979

@@ -111,14 +111,14 @@ private function isInstanceProperty(ReflectionProperty $reflectionProperty): boo
111111
private function getAccessibleProperty(ReflectionProperty $property): ?ReflectionProperty
112112
{
113113
return $this->reflectionService->getAccessibleProperty(
114-
$property->getDeclaringClass()->getName(),
115-
$property->getName()
114+
$property->class,
115+
$property->name
116116
);
117117
}
118118

119119
private function getLogicalName(ReflectionProperty $property): string
120120
{
121-
$propertyName = $property->getName();
121+
$propertyName = $property->name;
122122

123123
if ($property->isPublic()) {
124124
return $propertyName;
@@ -128,6 +128,6 @@ private function getLogicalName(ReflectionProperty $property): string
128128
return "\0*\0" . $propertyName;
129129
}
130130

131-
return "\0" . $property->getDeclaringClass()->getName() . "\0" . $propertyName;
131+
return "\0" . $property->class . "\0" . $propertyName;
132132
}
133133
}

lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(ReflectionProperty $parentProperty, ReflectionProper
3838
$this->childProperty = $childProperty;
3939
$this->embeddedClass = (string) $embeddedClass;
4040

41-
parent::__construct($childProperty->getDeclaringClass()->getName(), $childProperty->getName());
41+
parent::__construct($childProperty->class, $childProperty->name);
4242
}
4343

4444
/**

lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
2828
$this->enumType = $enumType;
2929

3030
parent::__construct(
31-
$originalReflectionProperty->getDeclaringClass()->getName(),
32-
$originalReflectionProperty->getName()
31+
$originalReflectionProperty->class,
32+
$originalReflectionProperty->name
3333
);
3434
}
3535

@@ -98,7 +98,7 @@ private function initializeEnumValue($object, $value): BackedEnum
9898
} catch (ValueError $e) {
9999
throw MappingException::invalidEnumValue(
100100
get_class($object),
101-
$this->originalReflectionProperty->getName(),
101+
$this->originalReflectionProperty->name,
102102
(string) $value,
103103
$enumType,
104104
$e

lib/Doctrine/ORM/Proxy/ProxyFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ private function generateSkippedProperties(ClassMetadata $class): string
335335

336336
while ($reflector) {
337337
foreach ($reflector->getProperties($filter) as $property) {
338-
$name = $property->getName();
338+
$name = $property->name;
339339

340340
if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) {
341341
continue;
342342
}
343343

344-
$prefix = $property->isPrivate() ? "\0" . $property->getDeclaringClass()->getName() . "\0" : ($property->isProtected() ? "\0*\0" : '');
344+
$prefix = $property->isPrivate() ? "\0" . $property->class . "\0" : ($property->isProtected() ? "\0*\0" : '');
345345

346346
$skippedProperties[$prefix . $name] = true;
347347
}
@@ -353,7 +353,7 @@ private function generateSkippedProperties(ClassMetadata $class): string
353353
uksort($skippedProperties, 'strnatcmp');
354354

355355
$code = VarExporter::export($skippedProperties);
356-
$code = str_replace(VarExporter::export($class->getName()), 'parent::class', $code);
356+
$code = str_replace(VarExporter::export($class->name), 'parent::class', $code);
357357
$code = str_replace("\n", "\n ", $code);
358358

359359
return $code;
@@ -376,7 +376,7 @@ private function generateSerializeImpl(ClassMetadata $class): string
376376
return $code . '$data = [];
377377
378378
foreach (parent::__sleep() as $name) {
379-
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->getName() . '\0$name"] ?? $k = null;
379+
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->name . '\0$name"] ?? $k = null;
380380
381381
if (null === $k) {
382382
trigger_error(sprintf(\'serialize(): "%s" returned as member variable from __sleep() but does not exist\', $name), \E_USER_NOTICE);

lib/Doctrine/ORM/Tools/EntityGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ protected function getClassToExtendName()
969969
{
970970
$refl = new ReflectionClass($this->getClassToExtend());
971971

972-
return '\\' . $refl->getName();
972+
return '\\' . $refl->name;
973973
}
974974

975975
/** @return string */

0 commit comments

Comments
 (0)