prooph / event-store-http-client

PHP 7.2 Event Store HTTP Client Implementation
BSD 3-Clause "New" or "Revised" License
25 stars 5 forks source link

Examples are not up to date? #52

Closed burzum closed 3 years ago

burzum commented 3 years ago

https://github.com/prooph/event-store-http-client/blob/master/examples/demo-subscribe-to-stream-from.php

Uncaught Error: Interface 'Prooph\EventStore\EventAppearedOnCatchupSubscription' not found

When I fix these, I'm getting a lot of these

Fatal error: Uncaught Error: Typed property Prooph\EventStoreHttpClient\Internal\EventStoreCatchUpSubscription::$subscription

which are easy to fix. I've got stuck at this point:

Fatal error: Uncaught Error: Interface 'Prooph\EventStore\EventAppearedOnSubscription' not found in \vendor\prooph\event-store-http-client\src\Internal\EventStoreCatchUpSubscription.php:167

I'm not sure what I need to change here to make it work again.

enumag commented 3 years ago

Ah the package is now using simple callbacks instead of new class() implements ... { public function __invoke(. We just forgot to update the examples.

burzum commented 3 years ago

@enumag correct, I've already changed this but I'm getting into the other issues I've mentioned above after that. Some typed properties are not initialized. This has been easy to fix as well in the package. But I'm stuck at

Fatal error: Uncaught Error: Interface 'Prooph\EventStore\EventAppearedOnSubscription' not found in \vendor\prooph\event-store-http-client\src\Internal\EventStoreCatchUpSubscription.php:167

I might spend a little more time on this later.

burzum commented 3 years ago

These changes seem to make it work:

diff --git "a/src/Internal/EventStoreCatchUpSubscription.php" "b/src/Internal/EventStoreCatchUpSubscription.php"
index 2e61263..c29020d 100644
--- "a/src/Internal/EventStoreCatchUpSubscription.php"
+++ "b/src/Internal/EventStoreCatchUpSubscription.php"
@@ -55,9 +55,9 @@ abstract class EventStoreCatchUpSubscription implements SyncEventStoreCatchUpSub
     private ?DropData $dropData;
     private bool $allowProcessing;
     private bool $isProcessing;
-    protected bool $shouldStop;
-    private bool $isDropped;
-    private bool $stopped;
+    protected bool $shouldStop = false;
+    private bool $isDropped = false;
+    private bool $stopped = false;

     /**
      * @internal
@@ -93,6 +93,7 @@ abstract class EventStoreCatchUpSubscription implements SyncEventStoreCatchUpSub
         $this->liveQueue = new SplQueue();
         $this->subscriptionName = $settings->subscriptionName() ?? '';
         $this->stopped = true;
+        $this->subscription = null;
     }

     public function isSubscribedToAll(): bool
@@ -163,37 +164,19 @@ abstract class EventStoreCatchUpSubscription implements SyncEventStoreCatchUpSub
     private function subscribeToStream(): void
     {
         if (! $this->shouldStop) {
-            $eventAppeared = new class(Closure::fromCallable([$this, 'enqueuePushedEvent'])) implements EventAppearedOnSubscription {
-                private $callback;
-
-                public function __construct(callable $callback)
-                {
-                    $this->callback = $callback;
-                }
-
-                public function __invoke(
+            $eventAppeared = function(
                     EventStoreSubscription $subscription,
                     ResolvedEvent $resolvedEvent
                 ): void {
                     ($this->callback)($subscription, $resolvedEvent);
-                }
-            };
+                };

-            $subscriptionDropped = new class(Closure::fromCallable([$this, 'serverSubscriptionDropped'])) implements SubscriptionDropped {
-                private $callback;
-
-                public function __construct(callable $callback)
-                {
-                    $this->callback = $callback;
-                }
-
-                public function __invoke(
+            $subscriptionDropped = function(
                     EventStoreSubscription $subscription,
                     SubscriptionDropReason $reason,
                     ?Throwable $exception = null
                 ): void {
                     ($this->callback)($reason, $exception);
-                }
             };

             $subscription = empty($this->streamId)
prolic commented 3 years ago

@burzum Looks good so far.

burzum commented 3 years ago

@prolic https://github.com/prooph/event-store-http-client/pull/53