PHP code example of softonic / laravel-protobuf-events
1. Go to this page and download the library: Download softonic/laravel-protobuf-events 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/ */
softonic / laravel-protobuf-events example snippets
/**
* Register any events for your application.
*/
public function boot(): void
{
$this->listen = [
'my.routing.key' => [
ExternalEvents::decorateListener(MyListener::class),
],
];
parent::boot();
}
class MyListener
{
public function setClient(string $client): void
{
// ...
}
public function handle(ProtobufExampleMessage $event): void
{
// ...
}
}
ExternalEvents::publish(
':service:',
(new ProtobufExampleMessage)
->setName('My name')
->setAge(10)
);
$message = ExternalEvents::decode(
ProtobufExampleMessage::class,
'\n My name\n 10\n' // The message is a string with the protobuf message.
);