pvsaintpe / ltree-bundle

10 stars 5 forks source link

Bundle breaks existing repositories #1

Open neoantox opened 5 years ago

neoantox commented 5 years ago

I have repository that extends ServiceEntityRepository (generated by maker bundle)

<?php

namespace App\Repository;

use App\Entity\ShortUrl;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method ShortUrl|null find($id, $lockMode = null, $lockVersion = null)
 * @method ShortUrl|null findOneBy(array $criteria, array $orderBy = null)
 * @method ShortUrl[]    findAll()
 * @method ShortUrl[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class ShortUrlRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, ShortUrl::class);
    }
}

When using this bundle I get an error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to App\Repository\ShortUrlRepository::__construct() must implement interface Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\ORM\EntityManager given, called in /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php on line 94 in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php:17
Stack trace:
#0 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(94): App\Repository\ShortUrlRepository->__construct(Object(Doctrine\ORM\EntityManager), Object(Doctrine\ORM\Mapping\ClassMetadata))
#1 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(69): LTree\Repository\RepositoryFactory->createRepository(Object(Doctrine\ORM\EntityManager), 'App\\Entity\\Shor...')
#2 /Users/arudnikov/Projects/ctv-api/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(713): LTree\Repository\Re in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php on line 17

The error happens, because this bundle replaces default repository factory with ltree_bundle.repository_factory

pvsaintpe commented 5 years ago

I have repository that extends ServiceEntityRepository (generated by maker bundle)

<?php

namespace App\Repository;

use App\Entity\ShortUrl;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method ShortUrl|null find($id, $lockMode = null, $lockVersion = null)
 * @method ShortUrl|null findOneBy(array $criteria, array $orderBy = null)
 * @method ShortUrl[]    findAll()
 * @method ShortUrl[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class ShortUrlRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, ShortUrl::class);
    }
}

When using this bundle I get an error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to App\Repository\ShortUrlRepository::__construct() must implement interface Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\ORM\EntityManager given, called in /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php on line 94 in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php:17
Stack trace:
#0 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(94): App\Repository\ShortUrlRepository->__construct(Object(Doctrine\ORM\EntityManager), Object(Doctrine\ORM\Mapping\ClassMetadata))
#1 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(69): LTree\Repository\RepositoryFactory->createRepository(Object(Doctrine\ORM\EntityManager), 'App\\Entity\\Shor...')
#2 /Users/arudnikov/Projects/ctv-api/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(713): LTree\Repository\Re in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php on line 17

The error happens, because this bundle replaces default repository factory with ltree_bundle.repository_factory

Спасибо за вашу обратную связь, я посмотрю сегодня вечером вашу проблему и ошибку и отпишусь в ближайшее время.

Если у вас есть PullRequest и решение проблемы прошу прислать его мне.

pvsaintpe commented 5 years ago

@neoantox,

Can I take a look at the code of your project in Symfony? It seems to me that for such situations I did a trait, instead of vertical inheritance from my LTreeEntityRepository.

Perhaps together we would solve your problem more quickly, contact me: pvsaintpe@icloud.com.