Last active
October 2, 2022 13:09
-
-
Save ismail1432/9cf455f15ccc2d13effb77cf7f550bc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Message | |
class MyMessage | |
{ | |
// boring stuff that you should adapt to your fit. | |
public $id = 42; | |
} | |
// Handler | |
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | |
// We should implements `MessageHandlerInterface` to register our handler | |
class MyMessageHandler implements MessageHandlerInterface | |
{ | |
// Thanks to the type hint Symfony will match the message with the good handler | |
public function __invoke(MyMessage $message) | |
{ | |
dump('We are in '.__CLASS__.' in method: '.__FUNCTION__, $message); | |
// return emojis for the fun. | |
return ['π', 'π', 'π₯']; | |
} | |
} | |
// Controller | |
class HelloController extends AbstractController | |
{ | |
#[Route('/hello', name: 'app_hello')] | |
public function hello(MessageBusInterface $bus): Response | |
{ | |
// dispatch the message | |
$bus->dispatch(new MyMessage()); | |
return $this->render('hello/index.html.twig', [ | |
'value' => 'Hello', | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment