PHP code example of becklyn / eventor-symfony

1. Go to this page and download the library: Download becklyn/eventor-symfony library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

becklyn / eventor-symfony example snippets


class Message
{
    public function __construct(
        private readonly string $id,
        private readonly string $body,
    ) {}

    public function id(): string
    {
        return $this->id;
    }

    public function body(): string
    {
        return $this->body;
    }
}

class PublishExample
{
    public function __construct(
        private readonly Publisher $publisher,
    ) {
        $this->publisher->publish("topic", new Message(
            id: "0",
            body: "Hello World",
        ));
    }
}

class DaprSubscriptionController extends AbstractController
{
    public function __construct(
        private readonly DaprSubscriptionRegistry $subscriptionRegistry,
    ) {
        new On(
            fn (Message $msg) => echo($msg),
            $this->$subscriber,
            "topic",
        );
    }

    #[Route('/dapr/subscribe', methods: [Request::METHOD_GET])]
    public function handleSubscribe() : Response
    {
        return $this->subscriptionRegistry->handleSubscribe();
    }

    #[Route('/dapr/pubsubname/topic', methods: [Request::METHOD_POST])]
    public function handleTopic(Request $request): Response
    {
        return $this->subscriptionRegistry->handleTopic($request);
    }
}
env
DAPR_HOST=http://localhost:3500 # Default: (null)
DAPR_PUBSUB=pubsubname # Default: (null)