doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.76k stars 224 forks source link

Why ObjectManager instead of EntityManagerInterface? #429

Open aivchen opened 1 year ago

aivchen commented 1 year ago

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!

stof commented 1 year ago

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.

aivchen commented 1 year ago

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