-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Decouple AttributeDriver from AnnotationDriver #2502
Conversation
73611f3
to
e4a1eaa
Compare
e4a1eaa
to
21ed3f8
Compare
21ed3f8
to
4b90cfb
Compare
642e80c
to
94e8a96
Compare
I've created #2596 on top of this PR to test the attribute driver |
); | ||
} | ||
|
||
$this->reader = $reader ?? new AttributeReader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we have a type check on $reader
being an AttributeReader
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean? the constructor is receiving a ?Reader
(which is deprecated), if no argument is passed it will be an AttributeReader
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about throwing an exception in case somebody would pass a AnnotationReader
by accident :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahm, the thing is that passing any Reader
(including AnnotationReader
) would work, I haven't changed that to maintain BC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But wouldn't the driver do nothing with anything else than an AttributeReader
? Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these methods: https://github.com/doctrine/mongodb-odm/pull/2502/files#diff-ac3d9c518c39d96ef76766a33e63f5115a72783ae78bc99bb4b70405a04e718eR389-R416:
/** @return object[] */
private function getClassAttributes(ReflectionClass $class): array
{
if ($this->reader instanceof AttributeReader) {
return $this->reader->getClassAttributes($class);
}
return $this->reader->getClassAnnotations($class);
}
/** @return object[] */
private function getMethodAttributes(ReflectionMethod $method): array
{
if ($this->reader instanceof AttributeReader) {
return $this->reader->getMethodAttributes($method);
}
return $this->reader->getMethodAnnotations($method);
}
/** @return object[] */
private function getPropertyAttributes(ReflectionProperty $property): array
{
if ($this->reader instanceof AttributeReader) {
return $this->reader->getPropertyAttributes($property);
}
return $this->reader->getPropertyAnnotations($property);
}
to maintain BC in case someone is passing a Reader
object
return true; | ||
} | ||
|
||
public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\ClassMetadata $metadata): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's rather unfortunate to have the code duplicated :/ Is there any other option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I know 😞, what I was thinking is after we do this, we can make doctrine/annotations
optional and then we can also deprecate AnnotationDriver
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could have a trait with shared code? Or would it be possible to have AnnotationDriver extend AttributeDriver? My biggest concern is that we're far from removing AnnotationDriver as we've never talked 3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only other option I can think of is to reverse the inheritance and have AnnotationDriver
extend AttributeDriver
, which again would remove the code duplication.
While we've never talked about ORM 3.0, I don't think it should be a "big thing" again. Instead, it should be released at the same time as a minor release, dropping all deprecated paths from that minor release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we've never talked about ORM 3.0, I don't think it should be a "big thing" again. Instead, it should be released at the same time as a minor release, dropping all deprecated paths from that minor release.
I'd be fine with this approach, it works well for Symfony 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but something else came up #2502 (comment)
@@ -173,7 +176,9 @@ public static function provideClassCanBeMappedByOneAbstractDocument(): ?Generato | |||
* @ODM\Document() | |||
* @ODM\EmbeddedDocument | |||
*/ | |||
new class () { | |||
new #[ODM\Document] | |||
#[ODM\EmbeddedDocument] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh boy this is ugly 🙈 Not the point of this PR obviously, just pointing out ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is! I've aligned the attributes, not sure if there is something else we can do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either :D but most probably it's not worth discussing in CS repo and if we can have it at least aligned it's OK :)
94e8a96
to
4696eff
Compare
|
||
/** | ||
* The AnnotationDriver reads the mapping metadata from docblock annotations. | ||
*/ | ||
class AnnotationDriver extends CompatibilityAnnotationDriver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be BC break, that class exists to have compatibility with doctrine/persistence
2 and 3
We can drop support of version 2 or leave it like this (AnnotationDriver
would stop extending Doctrine\Persistence\Mapping\Driver\AnnotationDriver
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've decided in doctrine/DoctrineMongoDBBundle#824 to drop support for doctrine/persistence
v2 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's deal with that in #2603
1512d16
to
d083cc5
Compare
thanks for the reviews! |
Sorry I didn't manage to get back in time. Anyway, happy new year folks! |
* 2.7.x: Bump ramsey/composer-install from 2 to 3 Bump actions/upload-artifact from 3 to 4 (#2601) Bump actions/cache from 3 to 4 (#2609) Transaction support (#2586) make doctrine/annotations dependency optional Decouple AttributeDriver from AnnotationDriver (#2502) Require doctrine/persistence 3 (#2603) Bump doctrine/.github from 3.1.0 to 4.0.0 Remove BC break issue type
Summary
This is a start so we can discuss what to do to decouple
AttributeDriver
from annotations, there are some BC breaks involved, so we need to see if this should be done in2.5
or wait for3.0
.The first one is that
AttributeDriver
no longer extendsAnnotationDriver
, I think this one is fine to do it in2.5
(this is what this PR does at the moment).But if we want to totally remove the dependency from
AttributeDriver
we should probably modify the constructor to remove the?Reader $reader = null
parameter, that would mean that the$reader
property would always be of typeAttributeReader
(which would be also modified to not implement theReader
interface).So, should we go all the way in? or postpone it for
3.0
?