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

FEATURE: Add support for embedded ValueObjects #426

Merged
merged 9 commits into from Aug 30, 2016

Conversation

albe
Copy link
Member

@albe albe commented Aug 17, 2016

This change adds support for embedded ValueObjects by using the Embeddable features
of Doctrine ORM 2.5.

All ValueObjects can be made embedded by setting the annotation option
embedded=true.

Depends on FLOW-260
FLOW-257 #close

@mention-bot
Copy link

@albe, thanks for your PR! By analyzing the annotation information on this pull request, we identified @kdambekalns, @afoeder and @skurfuerst to be potential reviewers

@albe albe force-pushed the embedded_valueobjects branch 3 times, most recently from 0375d33 to d48df4c Compare August 21, 2016 00:36
@albe albe changed the base branch from master to 3.3 August 21, 2016 00:36
@albe
Copy link
Member Author

albe commented Aug 21, 2016

Regarding the work-around commit, see also #439

This changeset adds support for embedded ValueObjects by using the Embeddable features
of Doctrine ORM 2.5.
All ValueObjects can be made embedded by setting the annotation option
"embedded=true".

Depends on FLOW-260
FLOW-257 #close
Also, embedded Value Objects are not to be considered transient for the
AnnotationDriver at all.
@albe
Copy link
Member Author

albe commented Aug 21, 2016

Why that breaks the Embeddables now is beyond me atm. Will investigate, so hopefully we can deliver this feature soon after the 3.3 release

@albe
Copy link
Member Author

albe commented Aug 24, 2016

Ok, found the issue, will push once GH allows me to.

@albe
Copy link
Member Author

albe commented Aug 25, 2016

Ok, this is ready for final review IMO

@Akii
Copy link
Contributor

Akii commented Aug 25, 2016

Making Value Objects great again. (=

@kdambekalns
Copy link
Member

So, hm. A feature for a released branch… I guess it's worth it, since it delivers one of the key features from ORM 2.5. Judging from the ❤️ reaction @kitsunet agrees?

@kitsunet
Copy link
Member

Yes, @albe and me agreed on this beforehand ;)

@@ -732,7 +737,13 @@ protected function evaluatePropertyAnnotations(ClassMetadataInfo $metadata)
break;
default:
if (strpos($propertyMetaData['type'], '\\') !== false) {
if ($this->reflectionService->isClassAnnotatedWith($propertyMetaData['type'], Flow\ValueObject::class)) {
if ($valueObjectAnnotation = $this->reflectionService->getClassAnnotation($propertyMetaData['type'], Flow\ValueObject::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really happy with this block, first please no value assignment in if statements, absolute no go for me. Second, why the continue 2? I see only one foreach here and also none of the other cases/ifs has a continue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll have to recheck, but it didn't work out first time when I simply "continue;"'d, so I just quickly tried the "continue 2;" - might have been some caching weirdness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But can't we work around it in any way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just checked again, I get following error during warmup:

Failure while evaluating property annotations for class "TYPO3\Flow\Tests\Functi
onal\Persistence\Fixtures\TestEntity": Property "embeddedValueObject" in "TYPO3\
Flow\Tests\Functional\Persistence\Fixtures\TestEntity" was already declared, but
 it must be declared only once
Type: Doctrine\ORM\Mapping\MappingException
  Code: 1382003497
  File:
...Data\Temporary\Testing\Cache\Code\Flow_Object_Classes\TYPO3_Flow_Persistence_Doctrine_Mapping_Driver_FlowAnnotationDriver.php
  Line: 414

maybe you can verify.

Copy link
Member Author

@albe albe Aug 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ok, now I get it too - the "2" is necessary to also skip out of the switch statement - it basically functions as a "break & continue;"

PS: Regarding the assignment inside if, I'm with you - that was a takeover of the rest of the coding style from the AnnotationDriver which again was taken over from Doctrine. I'm fine with changing our own additions at least.

@kitsunet
Copy link
Member

Left a comment...

@kitsunet kitsunet merged commit c50009c into neos:3.3 Aug 30, 2016
@albe albe deleted the embedded_valueobjects branch August 30, 2016 09:46
@albe
Copy link
Member Author

albe commented Aug 30, 2016

Woohoo :)

The design/architectural answer is: because a value object might just
be more fitting your problem at hand.
The technical answer is: because value objects are immutable and
therefore avoid aliasing ([#aliasing]) problems, which are common cause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest "are a common cause"

@albe
Copy link
Member Author

albe commented Aug 31, 2016

Ah indeed, I'll push a follow up to fix that typo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants