From a1a12696dbf09f93b90d8c6edde793ee88fe8627 Mon Sep 17 00:00:00 2001 From: Thomas Beaujean Date: Fri, 2 May 2025 11:59:55 +0200 Subject: [PATCH] Fix __construct for extended repositories --- src/Configuration/Configurator.php | 6 ++++++ src/Generator/RepositoryGenerator.php | 3 +++ src/Generator/TemplateService.php | 2 ++ .../views/Generator/TopRepositoryTemplate.html.twig | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/src/Configuration/Configurator.php b/src/Configuration/Configurator.php index a9e6ce6..f330ac7 100644 --- a/src/Configuration/Configurator.php +++ b/src/Configuration/Configurator.php @@ -36,4 +36,10 @@ public function getExtendRepository(string $entityName): string return $extendRepository; } + + public function isExtendeRepository( + string $repository, + ): bool { + return static::DEFAULT_REPOSITORY_EXTEND !== $repository; + } } diff --git a/src/Generator/RepositoryGenerator.php b/src/Generator/RepositoryGenerator.php index 27acb04..174713c 100644 --- a/src/Generator/RepositoryGenerator.php +++ b/src/Generator/RepositoryGenerator.php @@ -74,8 +74,11 @@ private function generateRepository(array $allMetadata, string $bundleName, Clas $idType = $idField['type']; } $extendClass = $this->configurator->getExtendRepository($entityClasspath); + $isExtendedClass = $this->configurator->isExtendeRepository($extendClass); + $renderedTemplate = $this->templateService->renderTopClass( $extendClass, + $isExtendedClass, $entityNamespace, $entityClasspath, $entityClassname, diff --git a/src/Generator/TemplateService.php b/src/Generator/TemplateService.php index 5391dea..d338688 100644 --- a/src/Generator/TemplateService.php +++ b/src/Generator/TemplateService.php @@ -19,6 +19,7 @@ public function __construct( public function renderTopClass( string $extendClass, + bool $isExtendedClass, string $namespace, string $entityClasspath, string $entityClassname, @@ -32,6 +33,7 @@ public function renderTopClass( 'entityClasspath' => $entityClasspath, 'entityClassname' => $entityClassname, 'extendClass' => $extendClass, + 'isExtendedClass' => $isExtendedClass, 'bundleName' => $bundleName, 'entityDql' => $entityDql, 'idType' => $idType, diff --git a/src/Resources/views/Generator/TopRepositoryTemplate.html.twig b/src/Resources/views/Generator/TopRepositoryTemplate.html.twig index dee29a4..2a576df 100644 --- a/src/Resources/views/Generator/TopRepositoryTemplate.html.twig +++ b/src/Resources/views/Generator/TopRepositoryTemplate.html.twig @@ -32,7 +32,11 @@ class {{ entityClassname }}Base extends {{ extendClass }} implements FilterByInt ManagerRegistry $registry, string $entity = \{{ entityClasspath }}::class, ) { +{% if isExtendedClass %} + parent::__construct($appCache, $registry, $entity); +{% else %} parent::__construct($registry, $entity); +{% endif %} } public static function getName(): string