laravel-doctrine / orm

An integration library for Laravel and Doctrine ORM
MIT License
828 stars 178 forks source link

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

Closed RobQuistNL closed 1 month ago

RobQuistNL commented 1 year ago

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

eigan commented 1 year ago

It would be helpful to see the entire stacktrace

dpslwk commented 1 year ago

Lumen is no longer recommended for new project

RobQuistNL commented 1 year ago

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);
    }
//...
}