npo / message-resource-bundle
Symfony bundle for npo/message-resource
11
2024-09-04 07:22 UTC
Requires
- php: ^8.3
- npo/message-resource: 11.0
- symfony/framework-bundle: ^6.4 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5
README
composer require npo/message-resource-bundle
This package provides a configured factory for message-resource
messages aliased as @npo_message_resource.message_factory
.
Usage
Add to config/bundles.php
:
NpoMessage\ResourceBundle\MessageResourceBundle::class => ['all' => true],
Example in services.yaml
:
App\MyMessageHandler:
arguments:
$messageFactory: '@npo_message_resource.message_factory'
Example in App\MyMessageHandler
<php
namespace App;
use NpoMessage\Resource\Domain\Factory\IChainMessageFactory;
class MyMessageHandler
{
public function __construct(
private IChainMessageFactory $factory
){}
public function handleMessage(string $message): void
{
if(!$this->factory->supports($message)) {
return;
}
try {
$messageAbstract = $this->factory->create($message);
} catch (UnsupportedMessageException $exception) {
// handle unsupported message
}
}
}