data-fixtures icon indicating copy to clipboard operation
data-fixtures copied to clipboard

Why ObjectManager instead of EntityManagerInterface?

Open aivchen opened this issue 2 years ago • 2 comments

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!

aivchen avatar Feb 17 '23 20:02 aivchen

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.

stof avatar Feb 17 '23 20:02 stof

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;
    }

aivchen avatar Feb 17 '23 20:02 aivchen