Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry constructor expected ManagerRegistry found DocumentManager #781

Closed
mustanggb opened this issue Oct 20, 2023 · 5 comments · Fixed by #782
Closed

Registry constructor expected ManagerRegistry found DocumentManager #781

mustanggb opened this issue Oct 20, 2023 · 5 comments · Fixed by #782

Comments

@mustanggb
Copy link
Contributor

mustanggb commented Oct 20, 2023

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.

@malarzm
Copy link
Member

malarzm commented Oct 23, 2023

@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.

@mustanggb
Copy link
Contributor Author

mustanggb commented Oct 24, 2023

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:

@malarzm
Copy link
Member

malarzm commented Oct 24, 2023

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.

@mustanggb
Copy link
Contributor Author

Thanks for the help, it seems this is due to a missing param: #782

@mustanggb
Copy link
Contributor Author

Fixed by 0a533e9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants