tienvx / pact-messenger-bundle
Pact Messenger Bundle
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- symfony/config: ^5.4|^6.4|^7.0
- symfony/dependency-injection: ^5.4|^6.4|^7.0
- symfony/http-kernel: ^5.4|^6.4|^7.0
- symfony/messenger: ^5.4|^6.4|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.1
- symfony/framework-bundle: ^5.4|^6.4|7.0
- symfony/test-pack: ^1.0
Conflicts
README
This Symfony Bundle allow collecting dispatched message using Symfony Messenger.
Installation
composer require tienvx/pact-messenger-bundle
Documentation
namespace App\MessageDispatcher; use App\Message\UserCreated; use Tienvx\Bundle\PactMessengerBundle\Service\EnvelopeCollectorInterface; use Tienvx\Bundle\PactProviderBundle\Attribute\AsMessageDispatcher; use Tienvx\Bundle\PactProviderBundle\Model\Message; use Tienvx\Bundle\PactProviderBundle\MessageDispatcher\DispatcherInterface; #[AsMessageDispatcher(description: 'User created message')] class UserDispatcher implements DispatcherInterface { public function __construct(private EnvelopeCollectorInterface $collector) { } public function dispatch(): ?Message { $envelope = $this->collector->getSingle(UserCreated::class); if (!$envelope) { return null; } $message = $envelope->getMessage(); if (!$message instanceof UserCreated) { return null; } return new Message( \json_encode([ 'class' => UserCreated::class, 'id' => $message->userId, ]), 'application/json', json_encode(['contentType' => 'application/json']) ); } }