Skip to content

Commit d8de109

Browse files
committed
Add factories for classes with value objects as dependencies so that the symfony container can be dumped
1 parent 87db491 commit d8de109

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

src/Clock/FrozenClockFactory.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcingBundle\Clock;
6+
7+
use DateTimeImmutable;
8+
use Patchlevel\EventSourcing\Clock\FrozenClock;
9+
10+
/** @internal */
11+
final class FrozenClockFactory
12+
{
13+
public static function create(string $dateTimeString): FrozenClock
14+
{
15+
return new FrozenClock(new DateTimeImmutable($dateTimeString));
16+
}
17+
}

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberAccessorRepository;
118118
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper;
119119
use Patchlevel\EventSourcingBundle\Attribute\AsListener;
120+
use Patchlevel\EventSourcingBundle\Clock\FrozenClockFactory;
120121
use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand;
121122
use Patchlevel\EventSourcingBundle\CommandBus\SymfonyCommandBus;
122123
use Patchlevel\EventSourcingBundle\DataCollector\EventSourcingCollector;
@@ -126,6 +127,7 @@
126127
use Patchlevel\EventSourcingBundle\QueryBus\SymfonyQueryBus;
127128
use Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener;
128129
use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener;
130+
use Patchlevel\EventSourcingBundle\Subscription\Engine\GapResolverMessageLoaderFactory;
129131
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
130132
use Patchlevel\EventSourcingBundle\Subscription\StaticInMemorySubscriptionStoreFactory;
131133
use Patchlevel\EventSourcingBundle\ValueResolver\AggregateRootIdValueResolver;
@@ -354,11 +356,12 @@ private function configureMessageLoader(array $config, ContainerBuilder $contain
354356
}
355357

356358
$container->register(GapResolverStoreMessageLoader::class)
359+
->setFactory([GapResolverMessageLoaderFactory::class, 'create'])
357360
->setArguments([
358361
new Reference(Store::class),
359362
new Reference('event_sourcing.clock'),
360363
$config['subscription']['gap_detection']['retries_in_ms'],
361-
new DateInterval($config['subscription']['gap_detection']['detection_window']),
364+
$config['subscription']['gap_detection']['detection_window'],
362365
]);
363366

364367
$container->setAlias(MessageLoader::class, GapResolverStoreMessageLoader::class);
@@ -1068,7 +1071,8 @@ private function configureClock(array $config, ContainerBuilder $container): voi
10681071
{
10691072
if ($config['clock']['freeze'] !== null) {
10701073
$container->register(FrozenClock::class)
1071-
->setArguments([new DateTimeImmutable($config['clock']['freeze'])]);
1074+
->setFactory([FrozenClockFactory::class, 'create'])
1075+
->setArguments([$config['clock']['freeze']]);
10721076

10731077
$container->setAlias('event_sourcing.clock', FrozenClock::class);
10741078

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcingBundle\Subscription\Engine;
6+
7+
use DateInterval;
8+
use Patchlevel\EventSourcing\Store\Store;
9+
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
10+
use Psr\Clock\ClockInterface;
11+
12+
/** @internal */
13+
final class GapResolverMessageLoaderFactory
14+
{
15+
public static function create(
16+
Store $store,
17+
ClockInterface $clock,
18+
array $retriesInMs,
19+
string|null $detectionWindow
20+
) {
21+
return new GapResolverStoreMessageLoader(
22+
$store,
23+
$clock,
24+
$retriesInMs,
25+
$detectionWindow !== null ? new DateInterval($detectionWindow) : null
26+
);
27+
}
28+
}

tests/Unit/PatchlevelEventSourcingBundleTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
use Symfony\Component\DependencyInjection\ChildDefinition;
116116
use Symfony\Component\DependencyInjection\ContainerBuilder;
117117
use Symfony\Component\DependencyInjection\Definition;
118+
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
118119
use Symfony\Component\DependencyInjection\Reference;
119120
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
120121
use Symfony\Component\Messenger\MessageBusInterface;
@@ -1585,5 +1586,7 @@ private function compileContainer(ContainerBuilder $container, array $config): v
15851586
$compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass());
15861587

15871588
$container->compile();
1589+
1590+
(new XmlDumper($container))->dump();
15881591
}
15891592
}

0 commit comments

Comments
 (0)