Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use properties instead of getters to read property/class names via reflection #10848

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ public function initializeReflection($reflService)
$this->namespace = $reflService->getClassNamespace($this->name);

if ($this->reflClass) {
$this->name = $this->rootEntityName = $this->reflClass->getName();
$this->name = $this->rootEntityName = $this->reflClass->name;
}

$this->table['name'] = $this->namingStrategy->classToTableName($this->name);
Expand Down Expand Up @@ -3866,7 +3866,7 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c
{
$reflectionProperty = $reflService->getAccessibleProperty($class, $field);
if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) {
$declaringClass = $reflectionProperty->getDeclaringClass()->name;
$declaringClass = $reflectionProperty->class;
if ($declaringClass !== $class) {
$reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
}

$mapping = [];
$mapping['fieldName'] = $property->getName();
$mapping['fieldName'] = $property->name;

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

$idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class);
if ($idAnnot) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
}

$mapping = [];
$mapping['fieldName'] = $property->getName();
$mapping['fieldName'] = $property->name;

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

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

if ($this->reader->getPropertyAttribute($property, Mapping\Id::class)) {
$mapping['id'] = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/Driver/ReflectionBasedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private function isRepeatedPropertyDeclaration(ReflectionProperty $property, Cla
|| $metadata->isInheritedEmbeddedClass($property->name);
}

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

if (
isset($metadata->fieldMappings[$property->name]['declared'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getHierarchyClasses(string $className): array

$parentClass = $currentClass->getParentClass();
if ($parentClass) {
$parentClassName = $parentClass->getName();
$parentClassName = $parentClass->name;
}
}

Expand Down Expand Up @@ -111,14 +111,14 @@ private function isInstanceProperty(ReflectionProperty $reflectionProperty): boo
private function getAccessibleProperty(ReflectionProperty $property): ?ReflectionProperty
{
return $this->reflectionService->getAccessibleProperty(
$property->getDeclaringClass()->getName(),
$property->getName()
$property->class,
$property->name
);
}

private function getLogicalName(ReflectionProperty $property): string
{
$propertyName = $property->getName();
$propertyName = $property->name;

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

return "\0" . $property->getDeclaringClass()->getName() . "\0" . $propertyName;
return "\0" . $property->class . "\0" . $propertyName;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(ReflectionProperty $parentProperty, ReflectionProper
$this->childProperty = $childProperty;
$this->embeddedClass = (string) $embeddedClass;

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

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
$this->enumType = $enumType;

parent::__construct(
$originalReflectionProperty->getDeclaringClass()->getName(),
$originalReflectionProperty->getName()
$originalReflectionProperty->class,
$originalReflectionProperty->name
);
}

Expand Down Expand Up @@ -98,7 +98,7 @@
} catch (ValueError $e) {
throw MappingException::invalidEnumValue(
get_class($object),
$this->originalReflectionProperty->getName(),
$this->originalReflectionProperty->name,

Check warning on line 101 in lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php#L101

Added line #L101 was not covered by tests
(string) $value,
$enumType,
$e
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@

while ($reflector) {
foreach ($reflector->getProperties($filter) as $property) {
$name = $property->getName();
$name = $property->name;

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

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

$skippedProperties[$prefix . $name] = true;
}
Expand Down Expand Up @@ -376,7 +376,7 @@
return $code . '$data = [];

foreach (parent::__sleep() as $name) {
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->getName() . '\0$name"] ?? $k = null;
$value = $properties[$k = $name] ?? $properties[$k = "\0*\0$name"] ?? $properties[$k = "\0' . $reflector->name . '\0$name"] ?? $k = null;

Check warning on line 379 in lib/Doctrine/ORM/Proxy/ProxyFactory.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Proxy/ProxyFactory.php#L379

Added line #L379 was not covered by tests

if (null === $k) {
trigger_error(sprintf(\'serialize(): "%s" returned as member variable from __sleep() but does not exist\', $name), \E_USER_NOTICE);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ protected function getClassToExtendName()
{
$refl = new ReflectionClass($this->getClassToExtend());

return '\\' . $refl->getName();
return '\\' . $refl->name;
}

/** @return string */
Expand Down