Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Aug 4, 2024
1 parent bb08c97 commit 27806dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Here's a snippet on how to set it up and dispatch a message:
use App\Message\MyMessage;
use OpenSolid\Bus\Handler\MessageHandlersLocator;
use OpenSolid\Bus\Middleware\HandlingMiddleware;
use OpenSolid\Bus\NativeBus;
use OpenSolid\Bus\NativeMessageBus;

// This is your custom function that does something when a message arrives.
$handler = function (MyMessage $message): mixed {
// Do stuff with the message here...
};

// Setting up the bus with a middleware that knows who handles the message.
$bus = new NativeBus([
$bus = new NativeMessageBus([
new HandlingMiddleware(new MessageHandlersLocator([
MyMessage::class => [$handler], // Match messages to handlers.
])),
Expand Down Expand Up @@ -63,17 +63,17 @@ Middleware are helpers that do stuff before and after your message is handled. T
Here’s how to create one:

```php
use OpenSolid\Bus\Envelope\Envelope;
use OpenSolid\Bus\Middleware\Middleware;
use OpenSolid\Bus\Middleware\NextMiddleware;
use OpenSolid\Bus\Model\Envelope;

class MyMiddleware implements Middleware
{
public function handle(Envelope $envelope, NextMiddleware $next): void
{
// Do something before the message handler works.

$next->handle($envelope); // Pass the message along.
$next->handle($envelope); // Pass the message to the next middleware

// Do something after the message handler is done.
}
Expand Down

0 comments on commit 27806dd

Please sign in to comment.