Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DoctrineBridge] Inject the entity manager instead of the class metadata factory in DoctrineExtractor#27829

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@dunglas
Copy link
Member

@dunglasdunglas commentedJul 3, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRsymfony/symfony-docs#10311

As explained by@stof in#27735 (comment), injecting theClassMetadataFactory directly can lead to issues when resetting the EntityManager.

This PR deprecates this usage and encourages to inject the entity manager directly.

4.2.0
-----

* deprecated injection`ClassMetadataFactory` in`DoctrineExtractor`,

Choose a reason for hiding this comment

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

injecting

-----

* deprecated injection`ClassMetadataFactory` in`DoctrineExtractor`,
and instance of`EntityManagerInterface` must be injected instead

Choose a reason for hiding this comment

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

s/and/an
s/must/should (friendlier)


publicfunction__construct(ClassMetadataFactory$classMetadataFactory)
/**
* @param EntityManagerInterface|ClassMetadataFactory $entityManager

Choose a reason for hiding this comment

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

should document only the not-deprecated type

if ($entityManagerinstanceof EntityManagerInterface) {
$this->entityManager =$entityManager;
}else {
@trigger_error(sprintf('Injecting an instance of "%s" in "%s" is deprecated since version 4.2 and will not be possible anymore in 5.0. Inject an instance of "%s" instead.', ClassMetadataFactory::class,__CLASS__, EntityManagerInterface::class),E_USER_DEPRECATED);

Choose a reason for hiding this comment

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

Injecting an instance of "%s" in "%s" is deprecated since Symfony 4.2, inject an instance of "%s" instead.

@dunglasdunglasforce-pushed thepinfo-deprecate-inject-metadata-factory branch fromce4511b to968d75aCompareJuly 3, 2018 20:08
$this->classMetadataFactory =$classMetadataFactory;
if ($entityManagerinstanceof EntityManagerInterface) {
$this->entityManager =$entityManager;
}else {
Copy link
Member

Choose a reason for hiding this comment

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

elseif ($entityManager instanceof ClassMetadataFactory) and then we should add anelse block that throws anInvalidArgumentException for everything else

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We don't check for invalid types when documented in the DockBlock, do we?

Copy link
Member

Choose a reason for hiding this comment

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

For other places where we deprecated arguments and removed the type hint we added them.

dunglas and Koc reacted with thumbs up emoji
@xabbuh
Copy link
Member

How will this behave when you have more than one entity manager configured? Right now the entity manager just forwards the call so there is no difference. But is this assumption future proof?

@dunglas
Copy link
MemberAuthor

There is a different metadata factory for every entity manager, so I don't think it can be an issue.

xabbuh reacted with thumbs up emoji

{
try {
$metadata =$this->classMetadataFactory->getMetadataFor($class);
$metadata =$this->entityManager ?$this->entityManager->getClassMetadata($class) :$this->classMetadataFactory->getMetadataFor($class);
Copy link
Contributor

Choose a reason for hiding this comment

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

what about extracting private method for that?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It doesn't worth it: it will introduce a performance penalty and anyway it will be dropped in Symfony 5.

@chalasr
Copy link
Member

UPGRADE files need to be updated

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

Can you a note in the UPGRADE file?

@dunglasdunglasforce-pushed thepinfo-deprecate-inject-metadata-factory branch from968d75a to9e05506CompareJuly 13, 2018 11:57
class DoctrineExtractorimplements PropertyListExtractorInterface, PropertyTypeExtractorInterface
{
private$entityManager;
private$classMetadataFactory;
Copy link
Contributor

@ro0NLro0NLJul 13, 2018
edited
Loading

Choose a reason for hiding this comment

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

should this one have a@deprecated tag?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so, it's a private property anyway

ro0NL and dunglas reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

It might help at time to clean up deprecated features from the next major branch.
With some well placed@deprecated flags for each deprecated feature, cleaning an entire component can be way easier (justgreping) and free of leftovers (each one leading to "drop dead code" PRs, you know).

Copy link
Contributor

Choose a reason for hiding this comment

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

that, and the fact it hints to not use the property anymore

@fabpotfabpotforce-pushed thepinfo-deprecate-inject-metadata-factory branch from262906b to3aab4a1CompareJuly 13, 2018 20:22
@fabpot
Copy link
Member

Thank you@dunglas.

@fabpotfabpot merged commit3aab4a1 intosymfony:masterJul 13, 2018
fabpot added a commit that referenced this pull requestJul 13, 2018
…the class metadata factory in DoctrineExtractor (dunglas)This PR was squashed before being merged into the 4.2-dev branch (closes#27829).Discussion----------[DoctrineBridge] Inject the entity manager instead of the class metadata factory in DoctrineExtractor| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  |no <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | yes <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | n/aAs explained by@stof in#27735 (comment), injecting the `ClassMetadataFactory` directly can lead to issues when resetting the EntityManager.This PR deprecates this usage and encourages to inject the entity manager directly.Commits-------3aab4a1 [DoctrineBridge] Inject the entity manager instead of the class metadata factory in DoctrineExtractor
@dunglasdunglas deleted the pinfo-deprecate-inject-metadata-factory branchSeptember 10, 2018 14:55
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestSep 11, 2018
…class metadata factory (dunglas, javiereguiluz)This PR was merged into the master branch.Discussion----------[PropertyInfo] Inject the entity manager instead of the class metadata factorysymfony/symfony#27829Commits-------44df1a7 Added the missing versionadded directive1f87e0c [PropertyInfo] Inject the entity manager instead of the class metadata factory
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@xabbuhxabbuhxabbuh left review comments

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@chalasrchalasrchalasr approved these changes

+2 more reviewers

@KocKocKoc left review comments

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

9 participants

@dunglas@xabbuh@chalasr@fabpot@javiereguiluz@Koc@nicolas-grekas@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp