Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ PropertyAccess

* Deprecate calling `PropertyAccessorBuilder::setCacheItemPool()` without arguments

Messenger
--------

* Deprecate `MessageHandlerInterface` and `MessageSubscriberInterface`, use the `AsMessageHandler` attribute instead

Security
--------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Add new `messenger:stats` command that returns a list of transports with their "to be processed" message count
* Add `TransportNamesStamp` to change the transport while dispatching a message
* Add support for rate limited transports by using the RateLimiter component.
* Deprecate `MessageHandlerInterface` and `MessageSubscriberInterface`, use `#[AsMessageHandler]` instead

6.1
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Handler\HandlerDescriptor;
use Symfony\Component\Messenger\Handler\HandlersLocator;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
use Symfony\Component\Messenger\TraceableMessageBus;
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
Expand Down Expand Up @@ -106,6 +108,8 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)

if (isset($options['bus'])) {
if (!\in_array($options['bus'], $busIds)) {
// @deprecated since Symfony 6.2, in 7.0 change to:
// $messageLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method);
$messageLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : ($r->implementsInterface(MessageSubscriberInterface::class) ? sprintf('returned by method "%s::getHandledMessages()"', $r->getName()) : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method));

throw new RuntimeException(sprintf('Invalid configuration "%s" for message "%s": bus "%s" does not exist.', $messageLocation, $message, $options['bus']));
Expand All @@ -115,6 +119,8 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
}

if ('*' !== $message && !class_exists($message) && !interface_exists($message, false)) {
// @deprecated since Symfony 6.2, in 7.0 change to:
// $messageLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method);
$messageLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : ($r->implementsInterface(MessageSubscriberInterface::class) ? sprintf('returned by method "%s::getHandledMessages()"', $r->getName()) : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method));

throw new RuntimeException(sprintf('Invalid handler service "%s": class or interface "%s" "%s" not found.', $serviceId, $message, $messageLocation));
Expand Down Expand Up @@ -197,9 +203,15 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId, string $methodName): iterable
{
if ($handlerClass->implementsInterface(MessageSubscriberInterface::class)) {
trigger_deprecation('symfony/messenger', '6.2', 'Implementing "%s" is deprecated, use the "%s" attribute instead.', MessageSubscriberInterface::class, AsMessageHandler::class);

return $handlerClass->getName()::getHandledMessages();
}

if ($handlerClass->implementsInterface(MessageHandlerInterface::class)) {
trigger_deprecation('symfony/messenger', '6.2', 'Implementing "%s" is deprecated, use the "%s" attribute instead.', MessageHandlerInterface::class, AsMessageHandler::class);
}

try {
$method = $handlerClass->getMethod($methodName);
} catch (\ReflectionException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

namespace Symfony\Component\Messenger\Handler;

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

/**
* Marker interface for message handlers.
*
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @deprecated since Symfony 6.2, use the {@see AsMessageHandler} attribute instead
*/
interface MessageHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

namespace Symfony\Component\Messenger\Handler;

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

/**
* Handlers can implement this interface to handle multiple messages.
*
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @deprecated since Symfony 6.2, use the {@see AsMessageHandler} attribute instead
*/
interface MessageSubscriberInterface extends MessageHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Tests\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\AttributeAutoconfigurationPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
Expand Down Expand Up @@ -59,6 +60,8 @@

class MessengerPassTest extends TestCase
{
use ExpectDeprecationTrait;

public function testProcess()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
Expand Down Expand Up @@ -302,6 +305,9 @@ public function testProcessTagWithUnknownBus()
(new MessengerPass())->process($container);
}

/**
* @group legacy
*/
public function testGetClassesFromTheHandlerSubscriberInterface()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
Expand All @@ -314,6 +320,7 @@ public function testGetClassesFromTheHandlerSubscriberInterface()
->addTag('messenger.message_handler')
;

$this->expectDeprecation('Since symfony/messenger 6.2: Implementing "Symfony\Component\Messenger\Handler\MessageSubscriberInterface" is deprecated, use the "Symfony\Component\Messenger\Attribute\AsMessageHandler" attribute instead.');
(new MessengerPass())->process($container);

$handlersMapping = $container->getDefinition($busId.'.messenger.handlers_locator')->getArgument(0);
Expand All @@ -325,6 +332,9 @@ public function testGetClassesFromTheHandlerSubscriberInterface()
$this->assertHandlerDescriptor($container, $handlersMapping, SecondMessage::class, [PrioritizedHandler::class, HandlerWithMultipleMessages::class], [['priority' => 10]]);
}

/**
* @group legacy
*/
public function testGetClassesAndMethodsAndPrioritiesFromTheSubscriber()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
Expand Down Expand Up @@ -404,6 +414,9 @@ public function testThrowsExceptionIfTheHandlerClassDoesNotExist()
(new MessengerPass())->process($container);
}

/**
* @group legacy
*/
public function testThrowsExceptionIfTheHandlerMethodDoesNotExist()
{
$this->expectException(RuntimeException::class);
Expand Down Expand Up @@ -475,6 +488,9 @@ public function testItSetsTheReceiverNamesOnTheSetupTransportsCommand()
$this->assertSame(['amqp', 'dummy'], $container->getDefinition('console.command.messenger_setup_transports')->getArgument(1));
}

/**
* @group legacy
*/
public function testItShouldNotThrowIfGeneratorIsReturnedInsteadOfArray()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
Expand Down Expand Up @@ -502,6 +518,9 @@ public function testItShouldNotThrowIfGeneratorIsReturnedInsteadOfArray()
);
}

/**
* @group legacy
*/
public function testItRegistersHandlersOnDifferentBuses()
{
$container = $this->getContainerBuilder($eventsBusId = 'event_bus');
Expand Down Expand Up @@ -534,6 +553,9 @@ public function testItRegistersHandlersOnDifferentBuses()
);
}

/**
* @group legacy
*/
public function testItThrowsAnExceptionOnUnknownBus()
{
$this->expectException(RuntimeException::class);
Expand All @@ -560,6 +582,9 @@ public function testUndefinedMessageClassForHandler()
(new MessengerPass())->process($container);
}

/**
* @group legacy
*/
public function testUndefinedMessageClassForHandlerImplementingMessageHandlerInterface()
{
$this->expectException(RuntimeException::class);
Expand All @@ -573,6 +598,9 @@ public function testUndefinedMessageClassForHandlerImplementingMessageHandlerInt
(new MessengerPass())->process($container);
}

/**
* @group legacy
*/
public function testUndefinedMessageClassForHandlerImplementingMessageSubscriberInterface()
{
$this->expectException(RuntimeException::class);
Expand Down Expand Up @@ -669,6 +697,9 @@ public function testUnionBuiltinArgumentTypeHandler()
(new MessengerPass())->process($container);
}

/**
* @group legacy
*/
public function testNeedsToHandleAtLeastOneMessage()
{
$this->expectException(RuntimeException::class);
Expand Down