From 90dc8b9f7b1e2e5acda3930c53b106e572939085 Mon Sep 17 00:00:00 2001 From: Sebastix Date: Tue, 5 Nov 2024 13:05:29 +0100 Subject: [PATCH] improve example snippets --- src/Examples/request-events-filtered-with-tags.php | 10 +++++++--- src/Examples/request-events-with-auth.php | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Examples/request-events-filtered-with-tags.php b/src/Examples/request-events-filtered-with-tags.php index 372f396..fbc5242 100644 --- a/src/Examples/request-events-filtered-with-tags.php +++ b/src/Examples/request-events-filtered-with-tags.php @@ -5,6 +5,8 @@ use swentel\nostr\Filter\Filter; use swentel\nostr\Message\RequestMessage; use swentel\nostr\Relay\Relay; +use swentel\nostr\RelayResponse\RelayResponse; +use swentel\nostr\RelayResponse\RelayResponseEvent; use swentel\nostr\Request\Request; use swentel\nostr\Subscription\Subscription; @@ -57,10 +59,12 @@ */ foreach ($response as $relayUrl => $relayResponses) { print 'Received ' . count($response[$relayUrl]) . ' message(s) received from relay ' . $relayUrl . PHP_EOL; - /** @var \swentel\nostr\RelayResponse\RelayResponseEvent $message */ + /** @var RelayResponse $relayResponse */ foreach ($relayResponses as $relayResponse) { - if (isset($relayResponse->event->content)) { - print $relayResponse->event->content . PHP_EOL; + if ($relayResponse instanceof RelayResponseEvent) { + if (isset($relayResponse->event->content)) { + print $relayResponse->event->content . PHP_EOL; + } } } } diff --git a/src/Examples/request-events-with-auth.php b/src/Examples/request-events-with-auth.php index 8da60ac..437e165 100644 --- a/src/Examples/request-events-with-auth.php +++ b/src/Examples/request-events-with-auth.php @@ -28,12 +28,12 @@ $request = new Request($relay, $requestMessage); $response = $request->send(); - foreach ($response as $relay => $messages) { + foreach ($response as $relay => $relayResponses) { print 'Received ' . count($response[$relay]) . ' message(s) received from relay ' . $relay . PHP_EOL; - foreach ($messages as $message) { - print $message->type . ': ' . $message->message . PHP_EOL; - if ($message instanceof RelayResponseEvent) { - $rawEvent = $message->event; + foreach ($relayResponses as $relayResponse) { + print 'Relay response ' . $relayResponse->type . ': ' . $relayResponse->message . PHP_EOL; + if ($relayResponse instanceof RelayResponseEvent) { + $rawEvent = $relayResponse->event; $event = new Event(); $event->setId($rawEvent->id); $event->setPublicKey($rawEvent->pubkey);