Skip to content

Commit

Permalink
fix(Doctrine): Do not extend `Doctrine\Bundle\DoctrineBundle\Reposito…
Browse files Browse the repository at this point in the history
…ry\ServiceEntityRepository` anymore due to LazyServiceEntityRepository starting `doctrine/[email protected]`
  • Loading branch information
ambroisemaupate committed Aug 3, 2023
1 parent 851221c commit ec1687c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@
"composer/package-versions-deprecated": "1.11.99.3",
"doctrine/annotations": "^1.0",
"doctrine/collections": ">=1.6",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-bundle": "^2.8.1",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/migrations": "^3.1.1",
"doctrine/orm": "^2.14.1",
"doctrine/dbal": "<3.4.0",
"enshrined/svg-sanitize": "^0.15",
"gedmo/doctrine-extensions": "^3.10.0",
"guzzlehttp/guzzle": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-json": "*",
"api-platform/core": "~2.7.0",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-bundle": "^2.8.1",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.14.1",
"doctrine/dbal": "<3.4.0",
Expand Down
28 changes: 18 additions & 10 deletions lib/RoadizCoreBundle/src/Repository/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace RZ\Roadiz\CoreBundle\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
Expand All @@ -15,6 +16,7 @@
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use LogicException;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Doctrine\Event\QueryBuilder\QueryBuilderApplyEvent;
use RZ\Roadiz\CoreBundle\Doctrine\Event\QueryBuilder\QueryBuilderBuildEvent;
Expand All @@ -26,24 +28,30 @@

/**
* @template TEntityClass of object
* @extends ServiceEntityRepository<TEntityClass>
* @extends \Doctrine\ORM\EntityRepository<TEntityClass>
*/
abstract class EntityRepository extends ServiceEntityRepository
abstract class EntityRepository extends \Doctrine\ORM\EntityRepository implements ServiceEntityRepositoryInterface
{
protected EventDispatcherInterface $dispatcher;

/**
* @param ManagerRegistry $registry
* @param string $entityClass
* @param class-string<TEntityClass> $entityClass
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(
ManagerRegistry $registry,
string $entityClass,
EventDispatcherInterface $dispatcher
) {
parent::__construct($registry, $entityClass);
public function __construct(ManagerRegistry $registry, string $entityClass, EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$manager = $registry->getManagerForClass($entityClass);

if (!($manager instanceof EntityManagerInterface)) {
throw new LogicException(sprintf(
'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.',
$entityClass
));
}

parent::__construct($manager, $manager->getClassMetadata($entityClass));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizFontBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.0",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-bundle": "^2.8.1",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.14.1",
"jms/serializer": "^3.9.0",
Expand Down

0 comments on commit ec1687c

Please sign in to comment.