Core: Using Symfony\Bridge\Doctrine\ManagerRegistry instead of Doctrine\Common\Persistence\ManagerRegistry

Created on 25 Aug 2020  路  14Comments  路  Source: api-platform/core

API Platform version(s) affected: 2.5.6

Description

When I try to make a request to the server, an error occurs:

Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given

The problem is that starting with version 2.9 of the doctrine/common library, the following code has been removed:
https://github.com/doctrine/common/tree/2.8/lib/Doctrine/Common/Persistence

https://github.com/api-platform/core/blob/38d69e6fdeaa6d6d32d43b7467454acb17d11315/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml#L113-L118

How to reproduce

Add the following dependencies to composer.json:

{
  "require": {
    "doctrine/orm": "^2.7"
  }
}

Possible Solution

Use the following class from Symfony\Bridge\Doctrine\ManagerRegistry as argument type instead of Doctrine\Common\Persistence\ManagerRegistry

Most helpful comment

@BenPilliez I was able to install it by adding, in the project composer.json:
"conflict": {
...
"doctrine/common": ">=3.0",
"doctrine/persistence": "<1.3"
}

Like suggested in ticket #3684
I had to remove composer.lock and do composer install again

All 14 comments

A release to fix it in the Doctrine bundle has been made 3 hours ago: https://github.com/doctrine/DoctrineBundle/releases/tag/2.1.2.

A release to fix it in the Doctrine bundle has been made 3 hours ago: https://github.com/doctrine/DoctrineBundle/releases/tag/2.1.2.

The problem is not with the configuration. From the error in the issue description, you can see that the correct service comes to the constructor.

Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given

The problem is that the type hints in the code refer to a class that doesn't exist.

https://github.com/api-platform/core/blob/38d69e6fdeaa6d6d32d43b7467454acb17d11315/src/Bridge/Doctrine/Orm/Metadata/Property/DoctrineOrmPropertyMetadataFactory.php#L18-L35

use Doctrine\Common\Persistence\ManagerRegistry;

Please see the fix in the Doctrine bundle, the typehint is OK: https://github.com/doctrine/DoctrineBundle/pull/1202/files.

I see.

This <service id="Doctrine\Common\Persistence\ManagerRegistry" alias="doctrine" public="false" /> is alias to Doctrine\Bundle\DoctrineBundle\Registry. This does not solve the problem with the missing class referenced by the code.

i updated the library version and and cleared the cache.
doctrine/doctrine-bundle: 2.1.2

The error is still present.

Seems this interface needs to be implemented instead: https://github.com/doctrine/persistence/blob/2.0.x/lib/Doctrine/Persistence/ManagerRegistry.php
It will need to be changed in API Platform and a new release needs to be done.
@dunglas could you take a look at it?

This is happening all over our part of the Internet. Here is the fix in SensioFrameworkExtraBundle: https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/691 and the fix for MakerBundle https://github.com/symfony/maker-bundle/pull/667

As I understand it, DoctrineBundle 2.1.1 now allows doctrine/common 3.0, which no longer comes with the old, legacy class alias support for Doctrine\Common\Persistence\ManagerRegistry. So it's not that a service changed or an alias become unavailable, the change is on a deeper, PHP level: DoctrineBundle now allows a version of other dependencies that no longer come with the legacy class aliases. My understand may be incomplete, this stuff makes my head spin a bit :p.

See #3684

So how can we install API platform please?

@BenPilliez I was able to install it by adding, in the project composer.json:
"conflict": {
...
"doctrine/common": ">=3.0",
"doctrine/persistence": "<1.3"
}

Like suggested in ticket #3684
I had to remove composer.lock and do composer install again

OK thanks you 馃槉. I will test this tomorrow

thanks @treeleaf ! it works.

Thank's a lot @treeleaf :D

Thanks everybody!
For me, the most acceptable way is:

  1. Adding to composer.json
    json "conflict": { "doctrine/common": ">=3.0", "doctrine/persistence": "<1.3" }
  2. Execute
    bash composer remove doctrine/*
  3. Execute
    bash composer require "doctrine/orm:^2.7"

Replace Doctrine\Common\Persistence\ManagerRegistry with Doctrine\Persistence\ManagerRegistry

Was this page helpful?
0 / 5 - 0 ratings