Skip to content

Commit 0d7df4c

Browse files
committed
Use parent for SubscriberAttributeDefinitionRepository
1 parent 52956e8 commit 0d7df4c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

config/services/repositories.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ services:
6060
arguments:
6161
- PhpList\Core\Domain\Subscription\Model\SubscriberAttributeValue
6262
PhpList\Core\Domain\Subscription\Repository\SubscriberAttributeDefinitionRepository:
63+
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
6364
arguments:
64-
$entityManager: '@doctrine.orm.entity_manager'
65-
$dynamicListAttrRepository: '@PhpList\Core\Domain\Subscription\Repository\DynamicListAttrRepository'
65+
- PhpList\Core\Domain\Subscription\Model\SubscriberAttributeDefinition
66+
calls:
67+
- [ setDynamicListAttrRepository, [ '@PhpList\Core\Domain\Subscription\Repository\DynamicListAttrRepository' ] ]
6668
PhpList\Core\Domain\Subscription\Repository\SubscriptionRepository:
6769
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
6870
arguments:

src/Domain/Subscription/Repository/SubscriberAttributeDefinitionRepository.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpList\Core\Domain\Subscription\Repository;
66

7-
use Doctrine\ORM\EntityManagerInterface;
87
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
98
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
109
use 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

Comments
 (0)