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

Example of the Doctrine doc with types as the first-class citizen#7876

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

Closed
weaverryan wants to merge3 commits intosymfony:masterfromweaverryan:doctrine-types-update
Closed

Example of the Doctrine doc with types as the first-class citizen#7876

weaverryan wants to merge3 commits intosymfony:masterfromweaverryan:doctrine-types-update

Conversation

@weaverryan
Copy link
Member

This updates the doctrine chapter in the new "types-first" philosophy - i.e. using type-hinting and autowiring to fetch services (rather than service ids). Of course, we must still show both (the type hint and the service id), but probably only the first time in a chapter. Afterwards, we should show the type.

This is the first "normal" chapter to get this update. Thoughts?

Thanks!

@weaverryanweaverryan added this to the3.3 milestoneMay 5, 2017
doctrine.rst Outdated
// you canalso receivethe$em as an argument
public function editAction(EntityManagerInterface $em)
// you canusetheregistry to fetch other em's, if you have mutiple
public function editAction(ManagerRegistry $registry)
Copy link
Member

Choose a reason for hiding this comment

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

A question newcomers (and not only them) may ask: why sometimes I need to inject an interface (EntityManagerInterface) and sometimes just a class (ManagerRegistry).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Bah, that's Doctrine's fault.ManagerRegistry IS an interface... I think they've only more recently started to use the Interface suffix.

Btw, I'm hoping the newdebug:container --types option will help this out - since that valid type-hints

Copy link
Member

@ycerutoyceruto left a comment

Choose a reason for hiding this comment

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

Great! 👍 Just minor (optional) dx comments :)

{
$product = $this->getDoctrine()
->getRepository('AppBundle:Product')
$product = $em->getRepository('AppBundle:Product')
Copy link
Member

Choose a reason for hiding this comment

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

[DX] What about to promote theProduct::class usage?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes, we should start doing this :). But it's gotta be in a different PR, because it needs to be applied to 3.1 and higher

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Opened#7892 to keep track of this :)

yceruto reacted with thumbs up emoji
$product = $this->getDoctrine()
->getRepository('AppBundle:Product')
$product = $em->getRepository('AppBundle:Product')
->find($productId);
Copy link
Member

Choose a reason for hiding this comment

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

[DX]$em->find(Product::class, $productId)? at the end it does the same, so less coding :)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Ah, it's cool ... but then you haven't taught the user about the repository. So, I like the slightly longer, but "simpler" approach - tell them that you need the repo 100% of the time :)

doctrine.rst Outdated
// you canalso receivethe$em as an argument
public function editAction(EntityManagerInterface $em)
// you canusetheregistry to fetch other em's, if you have mutiple
public function editAction(ManagerRegistry $registry)
Copy link
Member

Choose a reason for hiding this comment

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

$doctrine?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

@GuilhemNGuilhemN left a comment

Choose a reason for hiding this comment

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

awesome 👍


// ...
public function createAction()
public function createAction(EntityManagerInterface $em)
Copy link
Contributor

Choose a reason for hiding this comment

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

missing use statement :)

@GuilhemN
Copy link
Contributor

GuilhemN commentedMay 6, 2017
edited
Loading

I'm wondering, should we assert everywhere that folders registered in the standard edition do not need to be registered again in the docs?

doctrine.rst Outdated

// you canalso receivethe$em as an argument
public function editAction(EntityManagerInterface $em)
// you canusetheregistry to fetch other em's, if you have mutiple
Copy link
Member

Choose a reason for hiding this comment

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

you can use the registry to fetch other em's, if you have mutiple

-->

if you have multiple entity managers, use the registry to fetch them

@weaverryan
Copy link
MemberAuthor

I'm wondering, should we assert everywhere that folders registered in the standard edition do not need to be registered again in the docs?

@GuilhemN Let's have that discussion on a different PR - like#7883, or another that I'll hopefully open today (this PR just doesn't have any good examples of that as far as I can see). But I'm totally wondering about that. Unless... we can getsymfony/symfony-standard#1070 merged... then it won't matter (and this is one of the reasons I want that feature!)

@weaverryanweaverryan deleted the doctrine-types-update branchMay 10, 2017 09:51
{
// ...
$em = $doctrine->getManager();
$em2 = $doctrine->getManager('other_connection')
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 sure if it is common to get the manager for a particular connection. Don't you rather want to get the entity manager that manages a particular entity (i.e. you will want to usegetManagerForClass() instead)?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@xabbuhxabbuhxabbuh left review comments

+2 more reviewers

@ycerutoycerutoyceruto left review comments

@GuilhemNGuilhemNGuilhemN approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

5 participants

@weaverryan@GuilhemN@javiereguiluz@xabbuh@yceruto

[8]ページ先頭

©2009-2025 Movatter.jp