-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
415 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fmasa\Messenger\DI; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TransportConfig | ||
{ | ||
/** @var string */ | ||
public $dsn; | ||
|
||
/** @var mixed[] */ | ||
public $options = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fmasa\Messenger; | ||
|
||
use Symfony\Component\Messenger\Envelope; | ||
use function class_implements; | ||
use function class_parents; | ||
use function get_class; | ||
|
||
/** | ||
* @internal This class is not part of public API and can be changed between versions | ||
*/ | ||
final class MessageTypeResolver | ||
{ | ||
/** | ||
* @return string[] | ||
*/ | ||
public static function listTypes(Envelope $envelope) : array | ||
{ | ||
$class = get_class($envelope->getMessage()); | ||
|
||
return [$class => $class] | ||
+ class_parents($class) | ||
+ class_implements($class) | ||
+ ['*' => '*']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fmasa\Messenger\Transport; | ||
|
||
use Fmasa\Messenger\MessageTypeResolver; | ||
use Nette\DI\Container; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Exception\UnknownSenderException; | ||
use Symfony\Component\Messenger\Transport\Sender\SenderInterface; | ||
use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface; | ||
use function sprintf; | ||
|
||
final class SendersLocator implements SendersLocatorInterface | ||
{ | ||
public const TAG_SENDER_ALIAS = 'messenger.sender.alias'; | ||
|
||
/** @var array<string, string[]> */ | ||
private $messageTypeToSender; | ||
|
||
/** @var Container */ | ||
private $container; | ||
|
||
/** | ||
* @param array<string, string[]> $messageTypeToSenders | ||
*/ | ||
public function __construct(array $messageTypeToSenders, Container $container) | ||
{ | ||
$this->messageTypeToSender = $messageTypeToSenders; | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSenders(Envelope $envelope) : iterable | ||
{ | ||
foreach (MessageTypeResolver::listTypes($envelope) as $type) { | ||
foreach ($this->messageTypeToSender[$type] ?? [] as $alias) { | ||
yield $alias => $this->getSenderByAlias($alias); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSenderByAlias(string $alias) : SenderInterface | ||
{ | ||
foreach ($this->container->findByTag(self::TAG_SENDER_ALIAS) as $serviceName => $serviceAlias) { | ||
if ($serviceAlias !== $alias) { | ||
continue; | ||
} | ||
|
||
return $this->container->getService($serviceName); | ||
} | ||
|
||
throw new UnknownSenderException(sprintf('Unknown sender alias "%s".', $alias)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
messenger: | ||
buses: | ||
default: | ||
singleHandlerPerMessage: true | ||
transports: | ||
test: custom://foo | ||
routing: | ||
Fixtures\Message: test | ||
|
||
services: | ||
- Fixtures\CustomTransport | ||
- class: Fixtures\CustomTransportFactory | ||
tags: [messenger.transportFactory] |
Oops, something went wrong.