-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Make Annotations/Attribute mapping drivers report fields for the classes where they are declared #10455
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
Make Annotations/Attribute mapping drivers report fields for the classes where they are declared #10455
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,7 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl) | |
* | ||
* @return AnnotationDriver | ||
*/ | ||
public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true) | ||
public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true, bool $reportFieldsWhereDeclared = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, the plan is to deprecate this new argument in ORM 3.1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, or in 3.0? Not so sure what the release policy mandates/allows. To my understanding, in Symfony the „next .0“ equals „the last .x minus the compat layer“, so there are no additional features or deprecations. So, there is no room for new deprecations which will go into the next .1 release. But I don’t mind, if you think 3.0 makes more sense that’s fine for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3.1 sounds good to me 👍 |
||
{ | ||
Deprecation::trigger( | ||
'doctrine/orm', | ||
|
@@ -203,7 +203,8 @@ public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationRead | |
|
||
return new AnnotationDriver( | ||
$reader, | ||
(array) $paths | ||
(array) $paths, | ||
$reportFieldsWhereDeclared | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping\Driver; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use ReflectionProperty; | ||
|
||
/** @internal */ | ||
trait ReflectionBasedDriver | ||
mpdude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/** @var bool */ | ||
private $reportFieldsWhereDeclared = false; | ||
|
||
/** | ||
* Helps to deal with the case that reflection may report properties inherited from parent classes. | ||
* When we know about the fields already (inheritance has been anticipated in ClassMetadataFactory), | ||
* the driver must skip them. | ||
* | ||
* The declaring classes may mismatch when there are private properties: The same property name may be | ||
* reported multiple times, but since it is private, it is in fact multiple (different) properties in | ||
* different classes. In that case, report the property as an individual field. (ClassMetadataFactory will | ||
* probably fail in that case, though.) | ||
*/ | ||
private function isRepeatedPropertyDeclaration(ReflectionProperty $property, ClassMetadata $metadata): bool | ||
{ | ||
if (! $this->reportFieldsWhereDeclared) { | ||
return $metadata->isMappedSuperclass && ! $property->isPrivate() | ||
|| $metadata->isInheritedField($property->name) | ||
|| $metadata->isInheritedAssociation($property->name) | ||
|| $metadata->isInheritedEmbeddedClass($property->name); | ||
} | ||
|
||
$declaringClass = $property->getDeclaringClass()->getName(); | ||
|
||
if ( | ||
isset($metadata->fieldMappings[$property->name]['declared']) | ||
&& $metadata->fieldMappings[$property->name]['declared'] === $declaringClass | ||
) { | ||
return true; | ||
} | ||
|
||
if ( | ||
isset($metadata->associationMappings[$property->name]['declared']) | ||
&& $metadata->associationMappings[$property->name]['declared'] === $declaringClass | ||
) { | ||
return true; | ||
} | ||
|
||
return isset($metadata->embeddedClasses[$property->name]['declared']) | ||
&& $metadata->embeddedClasses[$property->name]['declared'] === $declaringClass; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.