laravel-doctrine / orm

A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Home Page:http://laraveldoctrine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Unresolvable dependency resolving [Parameter #0 [ <required> $entityName ]] in class Doctrine\ORM\Mapping\ClassMetadata

RobQuistNL opened this issue · comments

Package version, Laravel version

Lumen v8.3.4

Expected behaviour

The ClassMetadata class gets instantiated properly

Actual behaviour

It looks like the DI tries to fill $entityName in this constructor;
https://github.com/doctrine/orm/blob/2.14.x/lib/Doctrine/ORM/Mapping/ClassMetadata.php#L24-L27

Steps to reproduce the behaviour

Install Lumen
Follow the steps defined here; http://www.laraveldoctrine.org/docs/1.8/orm/lumen

It would be helpful to see the entire stacktrace

Lumen is no longer recommended for new project

I know Lumen is not recommended (heck, I'd not even recommend laravel), but we had to work with it.

I managed to initially fix it by manually binding all repository classes as a singleton, but that was messy - eventually simply installing doctrine/doctrine-bundle solved the issue.

My repositories now no longer extend Doctrine\ORM\EntityRepository but the Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository from the bundle, and then we have a simple constructor in the repository;

use App\Models\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Illuminate\Pagination\LengthAwarePaginator;
use LaravelDoctrine\ORM\Pagination\PaginatesFromParams;

class UserRepository extends ServiceEntityRepository
{
    use PaginatesFromParams;

    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, User::class);
    }
//...
}