npo / message-content-bundle
Symfony bundle for npo/message-content
41.2.1
2024-10-29 15:00 UTC
Requires
- php: ^8.3
- npo/message-content: ^41.2.1
- npo/phpunit-extension: ^1.1
- symfony/framework-bundle: ^6.3|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.2.7
README
composer require npo/message-content-bundle
This package provides a configured factory for message-content
messages aliased as @npo_message_content.message_factory
.
Usage
Add to config/bundles.php
:
NpoMessage\ContentBundle\MessageContentBundle::class => ['all' => true],
Example in services.yaml
:
App\MyMessageHandler:
arguments:
$messageFactory: '@npo_message_content.message_factory'
Example in App\MyMessageHandler
<php
namespace App;
use NpoMessage\Content\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
}
}
}