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.
I don’t think there’s any entirely clean solutions to this.
Your options basically boil down to two:
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:
This should activate completion for
$repoin most IDE’s. It still involves some extra typing tho.