I understand the benefit or repository pattern but I just can't understand in Symfony3 Doctrine there are Doctrine\ORM\EntityManager
and \Doctrine\ORM\EntityRepository
- What are the difference between the two?
Is repository should be injected to controller or entity manager?
Edit The correct question should be: What's the proper way to access a repository from a controller?
- Should a repository be injected to a controller as a service?
- Should a repository be injected to another service as a service?
Should entity manager contain any query at all?
Edit The correct question should be: should a service contain a query at all? Which @MateuszSip already explained, it could be done by injecting Entity ManagerShould a custom function like
getAvailableManagers
be put in repository or services? (Wheremanager
is a repository and there are some logic in determiningavailable manager
)- How about a more generic function like
findAllManager
, should it be in repository or entity manager?
Currently I'm using Symfony3. Thank you very much
Cheers,
Edit Talking to @MateuszSip (thanks mate), I decided to make my question clearer with an example below. Please note that below code are not representing real problem
controller
Class ManagementController
{
public function assignManager($projectType)
{
// Grabbing a service
$s = $this->get('mycompany_management_management_service')
$managers = $s->findAvailableManagers();
$managers = $s->checkCapability($managers, $projectType);
return $managers
}
}
repository
class ManagerRepository extends \Doctrine\ORM\EntityRepository
{
public function findAvailableManagers()
{
...
return $managers
}
public function checkCapability($managers, $type)
{
...
return $capableManagers
}
}
services
class ManagementService
{
... I am not sure what should be here.
}
->entityManager->getRepository
? – Mailable