Registry constructor expected ManagerRegistry found DocumentManager
mustanggb opened this issue · 5 comments
Implementing a repository as per the Service Repositories docs:
i.e.
// src/App/Repository/ProductRepository.php
namespace App\Repository;
use App\Document\Product;
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepository;
/**
* Remember to map this repository in the corresponding document's repositoryClass.
* For more information on this see the previous chapter.
*/
class ProductRepository extends ServiceDocumentRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Product::class);
}
}
Kicks out an issue with $registry
in parent::__construct($registry, Product::class);
of:
Expected type 'Doctrine\Persistence\ManagerRegistry'. Found 'Doctrine\ODM\MongoDB\DocumentManager'
@param \Doctrine\ODM\MongoDB\DocumentManager $registry
I had a dig around in ServiceRepositoryTrait
but wasn't able to figure out how to solve it.
For reference, I also tested with the ORM's ServiceEntityRepository
, but it did not experience the same problem.
@mustanggb any chance you could provide us a PR with a failing test case? At a glance there seems to be a misconfiguration on your end, as per the error the repository is expecting an instance of ManagerRegistry
while it's given a DocumentManager
instead.
Okay I think I found the source:
/**
* @extends ServiceDocumentRepository<Product>
*/
class ProductRepository extends ServiceDocumentRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Product::class);
}
}
I also tried @template-extends ServiceDocumentRepository<Product>
but it gives the same problem.
However changing to @extends ServiceDocumentRepository
"fixes" it?
Could this be related to some of these:
Ah so this is static analysis error! Whatever you're using seems to be taking PHPDoc from ODM's definition https://github.com/doctrine/mongodb-odm/blob/d3c8966b95059e9b572b3f873440b93ac7dd3907/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php#L61 instead of bundle's trait.