Skip to content

Commit

Permalink
fix new event sourcing version
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Apr 23, 2024
1 parent f0bf644 commit cb43be7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"patchlevel/event-sourcing-bundle": "^3.0.0-rc6",
"patchlevel/event-sourcing-bundle": "^3.0.0-rc12",
"symfony/asset": "^7.0",
"symfony/asset-mapper": "^7.0",
"symfony/config": "^5.4.31|^6.4.0|^7.0.0",
Expand Down
10 changes: 8 additions & 2 deletions src/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class EventController
public function __construct(
private readonly Environment $twig,
private readonly EventRegistry $eventRegistry,
private readonly ListenerProvider $listenerProvider,
private readonly ListenerProvider|null $listenerProvider,
private readonly iterable $subscribers,
private readonly SubscriberMetadataFactory $subscriberMetadataFactory,
)
Expand All @@ -46,8 +46,12 @@ public function indexAction(): Response
]));
}

private function listenerMethods(string $eventClass): array
private function listenerMethods(string $eventClass): array|null
{
if ($this->listenerProvider === null) {
return null;
}

return array_map(
static fn(ListenerDescriptor $listener) => $listener->name(),
$this->listenerProvider->listenersForEvent($eventClass),
Expand All @@ -58,6 +62,8 @@ private function subscribersMethods(string $eventClass): array
{
$result = [];

dump($this->subscribers);

foreach ($this->subscribers as $subscriber) {
$metadata = $this->subscriberMetadataFactory->metadata($subscriber::class);

Expand Down
12 changes: 7 additions & 5 deletions src/Controller/InspectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootMetadataFactory;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
use Patchlevel\EventSourcing\Snapshot\SnapshotStore;
use Patchlevel\EventSourcing\Store\Criteria;
use Patchlevel\EventSourcing\Store\Criteria\AggregateIdCriterion;
use Patchlevel\EventSourcing\Store\Criteria\AggregateNameCriterion;
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Store\Stream;
use Patchlevel\Hydrator\Hydrator;
Expand Down Expand Up @@ -82,8 +84,8 @@ public function showAction(Request $request, string $aggregateName, string $aggr
$aggregate = $this->aggregate($aggregateName, $aggregateId, $until);

$criteria = new Criteria(
aggregateName: $aggregateName,
aggregateId: $aggregateId,
new AggregateNameCriterion($aggregateName),
new AggregateIdCriterion($aggregateId),
);

$messages = $this->store->load(
Expand Down Expand Up @@ -138,8 +140,8 @@ public function showAction(Request $request, string $aggregateName, string $aggr
private function aggregate(string $aggregateName, string $aggregateId, int|null $until = null): AggregateRoot
{
$criteria = new Criteria(
aggregateName: $aggregateName,
aggregateId: $aggregateId,
new AggregateNameCriterion($aggregateName),
new AggregateIdCriterion($aggregateId),
);

$stream = null;
Expand Down
19 changes: 12 additions & 7 deletions src/Controller/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Patchlevel\EventSourcingAdminBundle\Controller;

use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
use Patchlevel\EventSourcing\Store\Criteria;
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Patchlevel\EventSourcing\Store\Criteria\CriteriaBuilder;
use Patchlevel\EventSourcing\Store\Store;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -49,12 +50,16 @@ public function showAction(Request $request): Response

private function criteria(Request $request): Criteria
{
$aggregateName = $request->query->get('aggregate');
$aggregateId = $request->query->get('aggregateId');
$criteriaBuilder = new CriteriaBuilder();

return new Criteria(
aggregateName: $aggregateName,
aggregateId: $aggregateId,
);
if ($request->query->get('aggregate')) {
$criteriaBuilder->aggregateName($request->query->get('aggregate'));
}

if ($request->query->get('aggregateId')) {
$criteriaBuilder->aggregateId($request->query->get('aggregateId'));
}

return $criteriaBuilder->build();
}
}
2 changes: 1 addition & 1 deletion src/Controller/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setupAction(string $id): Response
{
$criteria = new SubscriptionEngineCriteria([$id]);

$this->engine->setup($criteria);
$this->engine->setup($criteria, skipBooting: true);

return new RedirectResponse(
$this->router->generate('patchlevel_event_sourcing_admin_subscription_show'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function load(array $configs, ContainerBuilder $container): void
->setArguments([
new Reference('twig'),
new Reference(EventRegistry::class),
new Reference(ListenerProvider::class),
new TaggedIteratorArgument('event_sourcing.projector'),
new Reference(ListenerProvider::class, ContainerInterface::NULL_ON_INVALID_REFERENCE),
new TaggedIteratorArgument('event_sourcing.subscriber'),
new Reference(SubscriberMetadataFactory::class),
new Reference(TraceProjector::class, ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
Expand Down
4 changes: 3 additions & 1 deletion templates/event/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</dl>

<div class="px-4 py-6 bg-gray-50 text-gray-500 font-semibold">
Projectors ({{ event.subscribers|length }})
Subscribers ({{ event.subscribers|length }})
</div>

<ul>
Expand All @@ -75,6 +75,7 @@
{% endfor %}
</ul>

{% if event.listeners %}
<div class="px-4 py-6 bg-gray-50 text-gray-500 font-semibold">
Listeners ({{ event.listeners|length }})
</div>
Expand All @@ -86,6 +87,7 @@
<li class="px-4 py-6">no listeners</li>
{% endfor %}
</ul>
{% endif %}

{% endif %}
{% endfor %}
Expand Down

0 comments on commit cb43be7

Please sign in to comment.