What’s the difference between Doctrine\Common\Persistence\ObjectManager and Doctrine\ORM\EntityManager when using it in a custom form type?
I can get the respository using both $this->em->getRepository() and $this->om->getRepository().
class MyFormType extends \Symfony\Component\Form\AbstractType
{
/**
* @var Doctrine\ORM\EntityManager
*/
protected $em;
public function __construct(Doctrine\ORM\EntityManager $em)
{
$this->em = $em;
}
}
Instead of:
class MyFormType extends \Symfony\Component\Form\AbstractType
{
/**
* @var Doctrine\Common\Persistence\ObjectManager
*/
protected $om;
public function __construct(Doctrine\Common\Persistence\ObjectManager $om)
{
$this->om = $om;
}
}
ObjectManageris an interface andEntityManageris its ORM implementation. It’s not the only implementation; for example,DocumentManagerfrom MongoDB ODM implements it as well.ObjectManagerprovides only the common subset of all its implementations.If you want your form type to work with any
ObjectManagerimplementation, then use it. This way you could switch from ORM to ODM and your type would still work the same. But if you need something specific that onlyEntityManagerprovides and aren’t planning to switch to ODM, use it instead.