Skip to content

Commit c374dbf

Browse files
authored
Merge pull request #290 from patchlevel/3.14.x-merge-up-into-4.0.x
Upmerge 3.14.1 into 4.0.x
2 parents 9ff06ef + 9f771c6 commit c374dbf

4 files changed

Lines changed: 55 additions & 4 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Patchlevel\EventSourcingBundle\DependencyInjection;
66

7-
use DateInterval;
8-
use DateTimeImmutable;
97
use Doctrine\DBAL\Connection;
108
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
119
use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
@@ -123,6 +121,7 @@
123121
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberAccessorRepository;
124122
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper;
125123
use Patchlevel\EventSourcingBundle\Attribute\AsListener;
124+
use Patchlevel\EventSourcingBundle\Clock\FrozenClockFactory;
126125
use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand;
127126
use Patchlevel\EventSourcingBundle\CommandBus\SymfonyCommandBus;
128127
use Patchlevel\EventSourcingBundle\DataCollector\EventSourcingCollector;
@@ -132,6 +131,7 @@
132131
use Patchlevel\EventSourcingBundle\QueryBus\SymfonyQueryBus;
133132
use Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener;
134133
use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener;
134+
use Patchlevel\EventSourcingBundle\Subscription\Engine\GapResolverMessageLoaderFactory;
135135
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
136136
use Patchlevel\EventSourcingBundle\Subscription\StaticInMemorySubscriptionStoreFactory;
137137
use Patchlevel\EventSourcingBundle\ValueResolver\IdentifierValueResolver;
@@ -364,11 +364,12 @@ private function configureMessageLoader(array $config, ContainerBuilder $contain
364364
}
365365

366366
$container->register(GapResolverStoreMessageLoader::class)
367+
->setFactory([GapResolverMessageLoaderFactory::class, 'create'])
367368
->setArguments([
368369
new Reference(Store::class),
369370
new Reference('event_sourcing.clock'),
370371
$config['subscription']['gap_detection']['retries_in_ms'],
371-
new DateInterval($config['subscription']['gap_detection']['detection_window']),
372+
$config['subscription']['gap_detection']['detection_window'],
372373
]);
373374

374375
$container->setAlias(MessageLoader::class, GapResolverStoreMessageLoader::class);
@@ -1081,7 +1082,8 @@ private function configureClock(array $config, ContainerBuilder $container): voi
10811082
{
10821083
if ($config['clock']['freeze'] !== null) {
10831084
$container->register(FrozenClock::class)
1084-
->setArguments([new DateTimeImmutable($config['clock']['freeze'])]);
1085+
->setFactory([FrozenClockFactory::class, 'create'])
1086+
->setArguments([$config['clock']['freeze']]);
10851087

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
/** @param list<int> $retriesInMs in milliseconds */
16+
public static function create(
17+
Store $store,
18+
ClockInterface $clock,
19+
array $retriesInMs,
20+
string|null $detectionWindow,
21+
): GapResolverStoreMessageLoader {
22+
return new GapResolverStoreMessageLoader(
23+
$store,
24+
$clock,
25+
$retriesInMs,
26+
$detectionWindow !== null ? new DateInterval($detectionWindow) : null,
27+
);
28+
}
29+
}

tests/Unit/PatchlevelEventSourcingBundleTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
use Symfony\Component\DependencyInjection\ChildDefinition;
118118
use Symfony\Component\DependencyInjection\ContainerBuilder;
119119
use Symfony\Component\DependencyInjection\Definition;
120+
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
120121
use Symfony\Component\DependencyInjection\Reference;
121122
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
122123
use Symfony\Component\Messenger\MessageBusInterface;
@@ -1587,5 +1588,7 @@ private function compileContainer(ContainerBuilder $container, array $config): v
15871588
$compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass());
15881589

15891590
$container->compile();
1591+
1592+
(new XmlDumper($container))->dump();
15901593
}
15911594
}

0 commit comments

Comments
 (0)