-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRepositoryCompilerPass.php
More file actions
32 lines (26 loc) · 1.33 KB
/
RepositoryCompilerPass.php
File metadata and controls
32 lines (26 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
declare(strict_types=1);
namespace Patchlevel\EventSourcingBundle\DependencyInjection;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Repository\RepositoryManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
/** @internal */
final class RepositoryCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
foreach ($container->getParameter('event_sourcing.aggregates') as $aggregateName => $aggregateClass) {
$aggregateRepositoryName = $aggregateName . 'Repository';
$aggregateRepositoryId = 'event_sourcing.' . $aggregateName . '.repository';
$definition = new Definition(Repository::class);
$definition->setPublic(false);
$definition->setFactory([new Reference(RepositoryManager::class), 'get']);
$definition->setArgument(0, $aggregateClass);
$container->setDefinition($aggregateRepositoryId, $definition);
$container->registerAliasForArgument($aggregateRepositoryId, Repository::class, $aggregateRepositoryName)->setPublic(false);
}
}
}