npo / message-media-bundle
Symfony bundle for npo/message-media
42.0
2024-11-12 09:54 UTC
Requires
- php: ^8.3
- npo/message-media: ^42
- symfony/framework-bundle: ^6.3.8|^7.1.2
Requires (Dev)
- phpunit/phpunit: ^10.5.20
This package is not auto-updated.
Last update: 2024-12-10 10:17:39 UTC
README
composer require npo/message-media-bundle
This package provides a configured factory for message-media
messages aliased as @npo_message_media.message_factory
.
Usage
Add to config/bundles.php
:
NpoMessage\MediaBundle\MessageMediaBundle::class => ['all' => true],
Example in services.yaml
:
App\MyMessageHandler:
arguments:
$messageFactory: '@npo_message_media.message_factory'
Example in App\MyMessageHandler
<php
namespace App;
use NpoMessage\Media\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
}
}
}