Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:57:37+00:00 2026-05-24T22:57:37+00:00

I have about 10 entities: \App\Entity\User, \App\Entity\ Group, … For each of them has

  • 0

I have about 10 entities: \App\Entity\User, \App\Entity\ Group, …

For each of them has its own repository: \App\Repository\UserRepository, … In each of a dozen methods.

In Doctrine for access method:

$userRepository = $em->getRepository('App\Entity\User');

However, it is not convenient, because lost code completion.

Question: how to organize work with repositories, without increasing the static connection code?
Should I use a static method get?

class UserRepository extends EntityRepository
{
     /**
      * @static
      * @return \App\Repository\UserRepository
      */
     public static function get ()
     {
         $em = \Registry::getInstance()->get('em');
         return $em->getRepository('App\Entity\User');
     }
}

I watched as implemented to work with the doctrine of the symphony, but there is the same problem with code completion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:57:39+00:00Added an answer on May 24, 2026 at 10:57 pm

    I don’t think there’s any entirely clean solutions to this.

    Your options basically boil down to two:

    • Static getters as you show. Problem: hard to unit test, hides dependencies to things like the Registry class, requires manually adding them
    • Using some kind of a factory with getters. Problem: requires manually adding the factory methods

    I don’t really think it’s such a big deal. Repositories don’t have that many methods in them usually anyway, so it’s not that hard to remember (or check)

    However, one thing you could also try is this:

    /* @var My\Repository\FooRepository */
    $repo = $em->getRepository('My\Repository\FooRepository');
    

    This should activate completion for $repo in most IDE’s. It still involves some extra typing tho.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 20 check boxes. When the user selects these and then uses
We have about 7 app servers running .NET windows services that ping a single
I have a model library (namespace Test.App.Model.EF ) with the Entity Framework implementation in
I have a strange problem in my Core Data app. I have three entities
I'm creating an app that has the feature of adding two profiles/accounts. Each profile
We are writing this paper about database access in a web app and have
I have a core data model defined as follows: A User has many events.
I'm developing software using the Google App Engine. I have some considerations about the
I have a core data database which has (for now) 2 entities Product and
I have about 10 drop down list controls that get populated. Instead of copying/pasting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.