44
55namespace PhpList \Core \Domain \Subscription \Repository ;
66
7- use Doctrine \ORM \EntityManagerInterface ;
87use PhpList \Core \Domain \Common \Repository \AbstractRepository ;
98use PhpList \Core \Domain \Common \Repository \CursorPaginationTrait ;
109use PhpList \Core \Domain \Common \Repository \Interfaces \PaginatableRepositoryInterface ;
@@ -14,14 +13,11 @@ class SubscriberAttributeDefinitionRepository extends AbstractRepository impleme
1413{
1514 use CursorPaginationTrait;
1615
17- public function __construct (
18- EntityManagerInterface $ entityManager ,
19- private readonly DynamicListAttrRepository $ dynamicListAttrRepository ,
20- ) {
21- parent ::__construct (
22- $ entityManager ,
23- $ entityManager ->getClassMetadata (SubscriberAttributeDefinition::class)
24- );
16+ private ?DynamicListAttrRepository $ dynamicListAttrRepository = null ;
17+
18+ public function setDynamicListAttrRepository (DynamicListAttrRepository $ dynamicListAttrRepository ): void
19+ {
20+ $ this ->dynamicListAttrRepository = $ dynamicListAttrRepository ;
2521 }
2622
2723 /**
@@ -30,6 +26,9 @@ public function __construct(
3026 */
3127 private function hydrateOptionsForAll (array $ defs ): array
3228 {
29+ if ($ this ->dynamicListAttrRepository === null ) {
30+ return $ defs ;
31+ }
3332 foreach ($ defs as $ def ) {
3433 $ this ->hydrateOptions ($ def );
3534 }
@@ -38,6 +37,9 @@ private function hydrateOptionsForAll(array $defs): array
3837
3938 private function hydrateOptions (SubscriberAttributeDefinition $ def ): void
4039 {
40+ if ($ this ->dynamicListAttrRepository === null ) {
41+ return ;
42+ }
4143 $ table = $ def ->getTableName ();
4244 if ($ table ) {
4345 $ options = $ this ->dynamicListAttrRepository ->getAll ($ table );
@@ -60,7 +62,11 @@ public function getAfterId(int $lastId, int $limit): array
6062
6163 public function findOneByName (string $ name ): ?SubscriberAttributeDefinition
6264 {
63- return $ this ->findOneBy (['name ' => $ name ]);
65+ $ def = $ this ->findOneBy (['name ' => $ name ]);
66+ if ($ def instanceof SubscriberAttributeDefinition) {
67+ $ this ->hydrateOptions ($ def );
68+ }
69+ return $ def ;
6470 }
6571
6672 public function existsByTableName (string $ tableName ): bool
0 commit comments