Skip to content

Make Doctrine repository as service and autowire/use it anywhere #701

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

Merged
merged 1 commit into from
Nov 24, 2017
Merged

Make Doctrine repository as service and autowire/use it anywhere #701

merged 1 commit into from
Nov 24, 2017

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Nov 20, 2017

Living in the edge of the new awesome features like this, I'm proposing before doctrine-bundle 1.8 release, show/test this great feature that simplify our lives and to see how it works! and because soon, best practices should adopt this approach by default. (In fact maker-bundle will do it <3)

What do you think?

@@ -54,10 +55,9 @@ class BlogController extends AbstractController
* @Route("/", name="admin_post_index")
* @Method("GET")
*/
public function index(): Response
public function index(PostRepository $postRepository): Response
Copy link
Member

Choose a reason for hiding this comment

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

Maybe unrelated to this PR, but in other projects I see this practice: PostRepository $postRepository -> PostRepository $posts. Instead of $xxxRepository, they use the plural of $xxx as the variable name. E.g. UserRepository $users, ProductRepository $products, etc. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I like that and feels better! so done.


// Every template name also has two extensions that specify the format and
// engine for that template.
// See https://symfony.com/doc/current/templating.html#template-suffix
return $this->render('blog/index.'.$_format.'.twig', ['posts' => $posts]);
return $this->render('blog/index.'.$_format.'.twig', ['posts' => $latestPosts]);
Copy link
Member Author

@yceruto yceruto Nov 20, 2017

Choose a reason for hiding this comment

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

What about just ... ['posts' => $posts->findLatest($page)]?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure ... the line would be a bit long.

@yceruto
Copy link
Member Author

yceruto commented Nov 20, 2017

Updated commands too. Ready for me! :)

@yceruto
Copy link
Member Author

yceruto commented Nov 24, 2017

doctrine-bundle 1.8.0 is out! We have repositories as services as a native built-in feature! 🎉 🎉

@javiereguiluz
Copy link
Member

Merged! I looooove this. @yceruto thanks for working on this!

@javiereguiluz javiereguiluz merged commit ceac1df into symfony:master Nov 24, 2017
javiereguiluz added a commit that referenced this pull request Nov 24, 2017
…anywhere (yceruto)

This PR was merged into the master branch.

Discussion
----------

Make Doctrine repository as service and autowire/use it anywhere

Living in the edge of the [new awesome features like this](doctrine/DoctrineBundle#727), I'm proposing before doctrine-bundle 1.8 release, show/test this great feature that simplify our lives and to see how it works! and because soon, best practices should adopt this approach by default. (In fact [maker-bundle will do it](https://github.com/symfony/maker-bundle/blob/master/src/Resources/skeleton/doctrine/Repository.php.txt) <3)

What do you think?

Commits
-------

ceac1df Make repository as service and autowire/use it anywhere
@yceruto yceruto deleted the repository_as_service branch November 24, 2017 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants