data-fixtures
data-fixtures copied to clipboard
Why ObjectManager instead of EntityManagerInterface?
ReferenceRepository
depends on ObjectManager
interface:
https://github.com/doctrine/data-fixtures/blob/4892c74dd04a3ec7404b9586272d722325905c58/src/ReferenceRepository.php#L67
But futher in code getUnitOfWork
method is called:
https://github.com/doctrine/data-fixtures/blob/4892c74dd04a3ec7404b9586272d722325905c58/src/ReferenceRepository.php#L127
\Doctrine\Persistence\ObjectManager
interface doesn't contain this method. But \Doctrine\ORM\EntityManagerInterface
contains.
Could you tell me, why there is a dependency on ObjectManager
instead of EntityManagerInterface
?
Thanks!
Because doctrine/data-fixtures is not specific to the ORM. The code supports multiple Doctrine O*M
projects.
But it is true that the ReferenceRepository does not work with any implementation of Doctrine\Persistence\ObjectManager
, only with implementations in those projects.
Ok, got it, thanks.
Then is my doc-annotation correct in this case?
/**
* Currently used object manager
*
* @var \Doctrine\ORM\EntityManagerInterface|\Doctrine\ODM\MongoDB\DocumentManager|\Doctrine\ODM\PHPCR\DocumentManagerInterface
*/
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}