Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Clock/FrozenClockFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcingBundle\Clock;

use DateTimeImmutable;
use Patchlevel\EventSourcing\Clock\FrozenClock;

/** @internal */
final class FrozenClockFactory
{
public static function create(string $dateTimeString): FrozenClock
{
return new FrozenClock(new DateTimeImmutable($dateTimeString));
}
}
10 changes: 6 additions & 4 deletions src/DependencyInjection/PatchlevelEventSourcingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Patchlevel\EventSourcingBundle\DependencyInjection;

use DateInterval;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
Expand Down Expand Up @@ -117,6 +115,7 @@
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberAccessorRepository;
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper;
use Patchlevel\EventSourcingBundle\Attribute\AsListener;
use Patchlevel\EventSourcingBundle\Clock\FrozenClockFactory;
use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand;
use Patchlevel\EventSourcingBundle\CommandBus\SymfonyCommandBus;
use Patchlevel\EventSourcingBundle\DataCollector\EventSourcingCollector;
Expand All @@ -126,6 +125,7 @@
use Patchlevel\EventSourcingBundle\QueryBus\SymfonyQueryBus;
use Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener;
use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener;
use Patchlevel\EventSourcingBundle\Subscription\Engine\GapResolverMessageLoaderFactory;
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
use Patchlevel\EventSourcingBundle\Subscription\StaticInMemorySubscriptionStoreFactory;
use Patchlevel\EventSourcingBundle\ValueResolver\AggregateRootIdValueResolver;
Expand Down Expand Up @@ -354,11 +354,12 @@ private function configureMessageLoader(array $config, ContainerBuilder $contain
}

$container->register(GapResolverStoreMessageLoader::class)
->setFactory([GapResolverMessageLoaderFactory::class, 'create'])
->setArguments([
new Reference(Store::class),
new Reference('event_sourcing.clock'),
$config['subscription']['gap_detection']['retries_in_ms'],
new DateInterval($config['subscription']['gap_detection']['detection_window']),
$config['subscription']['gap_detection']['detection_window'],
]);

$container->setAlias(MessageLoader::class, GapResolverStoreMessageLoader::class);
Expand Down Expand Up @@ -1068,7 +1069,8 @@ private function configureClock(array $config, ContainerBuilder $container): voi
{
if ($config['clock']['freeze'] !== null) {
$container->register(FrozenClock::class)
->setArguments([new DateTimeImmutable($config['clock']['freeze'])]);
->setFactory([FrozenClockFactory::class, 'create'])
->setArguments([$config['clock']['freeze']]);

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

Expand Down
29 changes: 29 additions & 0 deletions src/Subscription/Engine/GapResolverMessageLoaderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcingBundle\Subscription\Engine;

use DateInterval;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
use Psr\Clock\ClockInterface;

/** @internal */
final class GapResolverMessageLoaderFactory
{
/** @param list<int> $retriesInMs in milliseconds */
public static function create(
Store $store,
ClockInterface $clock,
array $retriesInMs,
string|null $detectionWindow,
): GapResolverStoreMessageLoader {
return new GapResolverStoreMessageLoader(
$store,
$clock,
$retriesInMs,
$detectionWindow !== null ? new DateInterval($detectionWindow) : null,
);
}
}
3 changes: 3 additions & 0 deletions tests/Unit/PatchlevelEventSourcingBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\Messenger\MessageBusInterface;
Expand Down Expand Up @@ -1585,5 +1586,7 @@ private function compileContainer(ContainerBuilder $container, array $config): v
$compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass());

$container->compile();

(new XmlDumper($container))->dump();
}
}
Loading