Skip to content

Instantly share code, notes, and snippets.

@dgafka
Created March 14, 2022 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgafka/541e2ed1c3f1a1782b490cabb2073a12 to your computer and use it in GitHub Desktop.
Save dgafka/541e2ed1c3f1a1782b490cabb2073a12 to your computer and use it in GitHub Desktop.
scheduling-in-php-07.php
<?php
#[Asynchronous("invoicing")]
class InvoiceGenerator
{
#[EventHandler(endpointId: "prepareInvoicing")]
public function prepareInvoicing(UserWasRegistered $event, CommandBus $commandBus): void
{
echo "User was registered, setting up first invoice generation\n";
$commandBus->send(new GenerateInvoice($event->personId), metadata: ["deliveryDelay" => 3000]);
}
#[CommandHandler(endpointId: "generateInvoice")]
public function generateInvoice(GenerateInvoice $generateInvoice, EventBus $eventBus): void
{
echo "Invoice generated for user\n";
$eventBus->publish(new InvoiceWasGenerated($generateInvoice->personId));
}
#[EventHandler(endpointId: "generateNextInvoice")]
public function generateNextInvoice(InvoiceWasGenerated $event, CommandBus $commandBus): void
{
echo "Waiting to generate new invoice\n";
$commandBus->send(new GenerateInvoice($event->personId), metadata: ["deliveryDelay" => 3000]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment