-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Mapped entity listeners are now processed by metadata exporters #6593
Mapped entity listeners are now processed by metadata exporters #6593
Conversation
$lines[] = sprintf( | ||
'$metadata->addEntityListener(\'%s\', \'%s\', \'%s\');', | ||
$event, | ||
$entityListener['class'], |
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.
Where is this code tested? Can't seem to find it. Also, use var_export()
instead of single quotes around a %s
$entityListenerXml->addAttribute('class', $entityListener['class']); | ||
$entityListenersXmlMap[$entityListener['class']] = $entityListenerXml; | ||
} else { | ||
$entityListenerXml = $entityListenersXmlMap[$entityListener['class']]; |
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.
Use an early return. Swap the negation on the if
to get rid of the else
overall
* | ||
* @return array | ||
*/ | ||
private function processEntityListeners(ClassMetadataInfo $metadata, $array) |
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.
You can now add return hints (we're on PHP 7.1 ;-) )
* | ||
* @return string | ||
*/ | ||
protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata) |
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.
Return type
* @param ClassMetadataInfo $metadata | ||
* @param array &$lines | ||
*/ | ||
private function processEntityListeners(ClassMetadataInfo $metadata, &$lines) |
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.
Can you remove the by-ref usage, and instead use array_merge()
in the caller?
* | ||
* @return array | ||
*/ | ||
private function processEntityListenerConfig($array, $entityListenerConfig, $event) |
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.
Return type
* | ||
* @param ClassMetadata $class | ||
*/ | ||
public function testEntityListenersGetExported($class) |
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.
: void
@@ -371,6 +373,26 @@ public function testCascadeAllCollapsed() | |||
} | |||
} | |||
|
|||
/** | |||
* @depends testExportedMetadataCanBeReadBackIn |
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.
Do you really want to use @depends
here?
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.
That's how all other export tests are structured, so I just adhered to the structure within the test case.
$this->assertNotEmpty($class->entityListeners); | ||
$this->assertCount(2, $class->entityListeners[Events::prePersist]); | ||
$this->assertCount(2, $class->entityListeners[Events::postPersist]); | ||
$this->assertEquals(UserListener::class, $class->entityListeners[Events::prePersist][0]['class']); |
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.
Ah, this is the test that I was missing.
@@ -5,6 +5,11 @@ | |||
/** | |||
* @Entity | |||
* @HasLifecycleCallbacks | |||
* @EntityListeners({ | |||
* Doctrine\Tests\ORM\Tools\Export\UserListener::class, |
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.
These should probably be prefixed with \
to avoid import collisions
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.
There is a weird issue with this, the resulting string is "\Doctrine\Tests\ORM\Tools\Export\UserListener"
, although ::class
notation normally results in class names without root namespace:
<?php
echo \SimpleXMLElement::class;
// SimpleXMLElement
Using the ::class
notation that way works as intended.
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.
@tPl0ch gotcha, seems weird, but it's probably a doctrine/annotations bug.
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.
Moved to doctrine/annotations#141
@tPl0ch see failures on https://travis-ci.org/doctrine/doctrine2/jobs/260960064#L594 |
b3d4e8c
to
83497d0
Compare
@Ocramius I think I have fixed the issues regarding the nullable return types. I totally forgot that a method that has no return statement now actually is |
83497d0
to
d485c18
Compare
The current implementation of the exporters are not taking the entity listeners into account. I have added test cases for most of the edge cases I could think of and implemented the Exporter handling. This PR originates from doctrine#5864, I was overwhelmed by the amount of conflicts I had to resolve so I started anew on a clean master HEAD. Squashed commits: - Code review aftermath - Add even more return type declarations - Added `return null` to methods declared with nullable return types - Removed unneeded docblocks when types are self-explanatory
d485c18
to
b7ae5b4
Compare
@@ -46,7 +46,7 @@ class AnnotationExporter extends AbstractExporter | |||
*/ | |||
public function exportClassMetadata(ClassMetadataInfo $metadata): string | |||
{ | |||
if ( ! $this->_entityGenerator) { | |||
if (!$this->_entityGenerator) { |
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.
Eh, we use if ( ! $withTheSpace
This reverts commit ec3eed6.
@Ocramius should be fine now (hopefully)... |
…pe changes That's still to be considered a BC break, since child classes are broken if incompatible. Sorry @tPl0ch :-(
@tPl0ch manually merged via 76e2155 Sorry for the method hints - I had to revert them, since those classes are open for inheritance, so the additional hints are a BC break. See https://3v4l.org/kSIhN for the specifics. |
Also, thanks for enduring the review hell we generally fire in contributors' direction :-) |
@Ocramius is there a |
There is, but we don't apply CS changes yet due to the amount of open PRs that would conflict for no good reason |
… On 16 Aug 2017 9:10 PM, "Thomas Ploch" ***@***.***> wrote:
@Ocramius <https://github.com/ocramius> is there a phpcs standards
configuration file for Doctrine so that all that CS issues can be caught
during development?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6593 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakDnXSzCZ5F10qVpA0dtIVkMNhAJiks5sYz61gaJpZM4OphCN>
.
|
The current implementation of the exporters are not taking the entity
listeners into account. I have added test cases for most of the edge
cases I could think of and implemented the Exporter handling.
This PR originates from #5864,
I was overwhelmed by the amount of conflicts I had to resolve so I
started anew on a clean master HEAD.