-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Allow to typehint multiple buses #27054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger; | ||
|
||
/** | ||
* A decorated message bus. | ||
* | ||
* Use this abstract class to created your message bus decorator to specialise your | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
* bus instances and type-hint them. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest |
||
* | ||
* @author Samuel Roze <samuel.roze@gmail.com> | ||
*/ | ||
abstract class DecoratedMessageBus implements MessageBusInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If concrete children are decorators then this is a base decorator, isn't it? Also core abstract classes are prefixed by |
||
{ | ||
private $decoratedBus; | ||
|
||
public function __construct(MessageBusInterface $decoratedBus) | ||
{ | ||
$this->decoratedBus = $decoratedBus; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function dispatch($message) | ||
{ | ||
return $this->decoratedBus->dispatch($message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use Symfony\Component\Messenger\Adapter\AmqpExt\AmqpSender; | ||
use Symfony\Component\Messenger\ContainerHandlerLocator; | ||
use Symfony\Component\Messenger\DataCollector\MessengerDataCollector; | ||
use Symfony\Component\Messenger\DecoratedMessageBus; | ||
use Symfony\Component\Messenger\DependencyInjection\MessengerPass; | ||
use Symfony\Component\Messenger\Handler\ChainHandler; | ||
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface; | ||
|
@@ -260,6 +261,17 @@ public function testRegistersTraceableBusesToCollector() | |
$this->assertEquals(array(array('registerBus', array('foo', new Reference($debuggedFooBusId))), array('registerBus', array('messenger.bus.bar', new Reference($debuggedBarBusId)))), $container->getDefinition('messenger.data_collector')->getMethodCalls()); | ||
} | ||
|
||
public function testRegistersBusDecoratedClass() | ||
{ | ||
$container = $this->getContainerBuilder(); | ||
$container->register($fooBusId = 'messenger.bus.foo', MessageBusInterface::class)->addTag('messenger.bus', array('decorator_class' => MyTypeHintedBus::class)); | ||
|
||
(new MessengerPass())->process($container); | ||
|
||
$this->assertTrue($container->hasDefinition(MyTypeHintedBus::class)); | ||
$this->assertSame(array($fooBusId, null, 0), $container->getDefinition(MyTypeHintedBus::class)->getDecoratedService()); | ||
} | ||
|
||
public function testRegistersMiddlewaresFromServices() | ||
{ | ||
$container = $this->getContainerBuilder(); | ||
|
@@ -413,3 +425,7 @@ public function handle($messa 7694 ge, callable $next) | |
return $next($message); | ||
} | ||
} | ||
|
||
final class MyTypeHintedBus extends DecoratedMessageBus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeHinted is misleading here :) a class is a type, method arguments are type-hinted |
||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it fail if the class does not implement
MessageBusInterface
at least? Perhaps give a complete hint about what is needed for using this option