diff --git a/UPGRADE-6.3.md b/UPGRADE-6.3.md index 17e9002f0882e..77c7858198d80 100644 --- a/UPGRADE-6.3.md +++ b/UPGRADE-6.3.md @@ -11,6 +11,14 @@ HttpKernel * Deprecate parameters `container.dumper.inline_factories` and `container.dumper.inline_class_loader`, use `.container.dumper.inline_factories` and `.container.dumper.inline_class_loader` instead +Messenger +--------- + + * Deprecate `Symfony\Component\Messenger\Transport\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemoryTransportFactory` in favor of + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory` + SecurityBundle -------------- diff --git a/UPGRADE-7.0.md b/UPGRADE-7.0.md index 587796bbb6e9f..42279c090c308 100644 --- a/UPGRADE-7.0.md +++ b/UPGRADE-7.0.md @@ -1,6 +1,14 @@ UPGRADE FROM 6.4 to 7.0 ======================= +Messenger +--------- + + * Remove `Symfony\Component\Messenger\Transport\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemoryTransportFactory` in favor of + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory` + Workflow -------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php index 13e8dad627835..39030ce51132e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php @@ -35,7 +35,7 @@ use Symfony\Component\Messenger\Middleware\ValidationMiddleware; use Symfony\Component\Messenger\Retry\MultiplierRetryStrategy; use Symfony\Component\Messenger\RoutableMessageBus; -use Symfony\Component\Messenger\Transport\InMemoryTransportFactory; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory; use Symfony\Component\Messenger\Transport\Sender\SendersLocator; use Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer; use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer; diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 509d4278daca6..0f0645331f774 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -48,7 +48,7 @@ "symfony/http-client": "^5.4|^6.0", "symfony/lock": "^5.4|^6.0", "symfony/mailer": "^5.4|^6.0", - "symfony/messenger": "^6.2", + "symfony/messenger": "^6.3", "symfony/mime": "^6.2", "symfony/notifier": "^5.4|^6.0", "symfony/process": "^5.4|^6.0", @@ -83,7 +83,7 @@ "symfony/form": "<5.4", "symfony/lock": "<5.4", "symfony/mailer": "<5.4", - "symfony/messenger": "<6.2", + "symfony/messenger": "<6.3", "symfony/mime": "<6.2", "symfony/property-info": "<5.4", "symfony/property-access": "<5.4", diff --git a/src/Symfony/Component/Messenger/CHANGELOG.md b/src/Symfony/Component/Messenger/CHANGELOG.md index 650e2ff0ac44f..4e2f52ebf2ff3 100644 --- a/src/Symfony/Component/Messenger/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +6.3 +--- + + * Deprecate `Symfony\Component\Messenger\Transport\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemoryTransportFactory` in favor of + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport` and + `Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory` + 6.2 --- diff --git a/src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportFactoryTest.php b/src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportFactoryTest.php similarity index 93% rename from src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportFactoryTest.php rename to src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportFactoryTest.php index d29ab10639da2..2be1ee57a0bd9 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportFactoryTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportFactoryTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Messenger\Tests\Transport; +namespace Symfony\Component\Messenger\Tests\Transport\InMemory; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp; use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage; -use Symfony\Component\Messenger\Transport\InMemoryTransport; -use Symfony\Component\Messenger\Transport\InMemoryTransportFactory; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; /** diff --git a/src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportTest.php b/src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportTest.php similarity index 97% rename from src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportTest.php rename to src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportTest.php index 1b10a6165823a..97e7f227a50e1 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/InMemory/InMemoryTransportTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Messenger\Tests\Transport; +namespace Symfony\Component\Messenger\Tests\Transport\InMemory; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp; use Symfony\Component\Messenger\Tests\Fixtures\AnEnvelopeStamp; use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage; -use Symfony\Component\Messenger\Transport\InMemoryTransport; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; /** diff --git a/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransport.php b/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransport.php new file mode 100644 index 0000000000000..40132068aecae --- /dev/null +++ b/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransport.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Transport\InMemory; + +use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\LogicException; +use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp; +use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; +use Symfony\Component\Messenger\Transport\TransportInterface; +use Symfony\Contracts\Service\ResetInterface; + +/** + * Transport that stays in memory. Useful for testing purpose. + * + * @author Gary PEGEOT + */ +class InMemoryTransport implements TransportInterface, ResetInterface +{ + /** + * @var Envelope[] + */ + private array $sent = []; + + /** + * @var Envelope[] + */ + private array $acknowledged = []; + + /** + * @var Envelope[] + */ + private array $rejected = []; + + /** + * @var Envelope[] + */ + private array $queue = []; + + private int $nextId = 1; + private ?SerializerInterface $serializer; + + public function __construct(SerializerInterface $serializer = null) + { + $this->serializer = $serializer; + } + + public function get(): iterable + { + return array_values($this->decode($this->queue)); + } + + public function ack(Envelope $envelope): void + { + $this->acknowledged[] = $this->encode($envelope); + + if (!$transportMessageIdStamp = $envelope->last(TransportMessageIdStamp::class)) { + throw new LogicException('No TransportMessageIdStamp found on the Envelope.'); + } + + unset($this->queue[$transportMessageIdStamp->getId()]); + } + + public function reject(Envelope $envelope): void + { + $this->rejected[] = $this->encode($envelope); + + if (!$transportMessageIdStamp = $envelope->last(TransportMessageIdStamp::class)) { + throw new LogicException('No TransportMessageIdStamp found on the Envelope.'); + } + + unset($this->queue[$transportMessageIdStamp->getId()]); + } + + public function send(Envelope $envelope): Envelope + { + $id = $this->nextId++; + $envelope = $envelope->with(new TransportMessageIdStamp($id)); + $encodedEnvelope = $this->encode($envelope); + $this->sent[] = $encodedEnvelope; + $this->queue[$id] = $encodedEnvelope; + + return $envelope; + } + + public function reset() + { + $this->sent = $this->queue = $this->rejected = $this->acknowledged = []; + } + + /** + * @return Envelope[] + */ + public function getAcknowledged(): array + { + return $this->decode($this->acknowledged); + } + + /** + * @return Envelope[] + */ + public function getRejected(): array + { + return $this->decode($this->rejected); + } + + /** + * @return Envelope[] + */ + public function getSent(): array + { + return $this->decode($this->sent); + } + + private function encode(Envelope $envelope): Envelope|array + { + if (null === $this->serializer) { + return $envelope; + } + + return $this->serializer->encode($envelope); + } + + /** + * @param array $messagesEncoded + * + * @return Envelope[] + */ + private function decode(array $messagesEncoded): array + { + if (null === $this->serializer) { + return $messagesEncoded; + } + + return array_map($this->serializer->decode(...), $messagesEncoded); + } +} diff --git a/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransportFactory.php b/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransportFactory.php new file mode 100644 index 0000000000000..3e704b1bb3528 --- /dev/null +++ b/src/Symfony/Component/Messenger/Transport/InMemory/InMemoryTransportFactory.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Transport\InMemory; + +use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; +use Symfony\Component\Messenger\Transport\TransportFactoryInterface; +use Symfony\Component\Messenger\Transport\TransportInterface; +use Symfony\Contracts\Service\ResetInterface; + +/** + * @author Gary PEGEOT + */ +class InMemoryTransportFactory implements TransportFactoryInterface, ResetInterface +{ + /** + * @var InMemoryTransport[] + */ + private array $createdTransports = []; + + public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface + { + ['serialize' => $serialize] = $this->parseDsn($dsn); + + return $this->createdTransports[] = new InMemoryTransport($serialize ? $serializer : null); + } + + public function supports(string $dsn, array $options): bool + { + return str_starts_with($dsn, 'in-memory://'); + } + + public function reset() + { + foreach ($this->createdTransports as $transport) { + $transport->reset(); + } + } + + private function parseDsn(string $dsn): array + { + $query = []; + if ($queryAsString = strstr($dsn, '?')) { + parse_str(ltrim($queryAsString, '?'), $query); + } + + return [ + 'serialize' => filter_var($query['serialize'] ?? false, \FILTER_VALIDATE_BOOL), + ]; + } +} diff --git a/src/Symfony/Component/Messenger/Transport/InMemoryTransport.php b/src/Symfony/Component/Messenger/Transport/InMemoryTransport.php index 68ec8b619eb77..a8941b00b67ad 100644 --- a/src/Symfony/Component/Messenger/Transport/InMemoryTransport.php +++ b/src/Symfony/Component/Messenger/Transport/InMemoryTransport.php @@ -11,134 +11,13 @@ namespace Symfony\Component\Messenger\Transport; -use Symfony\Component\Messenger\Envelope; -use Symfony\Component\Messenger\Exception\LogicException; -use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp; -use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; -use Symfony\Contracts\Service\ResetInterface; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport as BaseInMemoryTransport; + +trigger_deprecation('symfony/messenger', '6.3', 'The "%s" class is deprecated, use "%s" instead. ', InMemoryTransport::class, BaseInMemoryTransport::class); /** - * Transport that stays in memory. Useful for testing purpose. - * - * @author Gary PEGEOT + * @deprecated since Symfony 6.3, use {@link BaseInMemoryTransport} instead */ -class InMemoryTransport implements TransportInterface, ResetInterface +class InMemoryTransport extends BaseInMemoryTransport { - /** - * @var Envelope[] - */ - private array $sent = []; - - /** - * @var Envelope[] - */ - private array $acknowledged = []; - - /** - * @var Envelope[] - */ - private array $rejected = []; - - /** - * @var Envelope[] - */ - private array $queue = []; - - private int $nextId = 1; - private ?SerializerInterface $serializer; - - public function __construct(SerializerInterface $serializer = null) - { - $this->serializer = $serializer; - } - - public function get(): iterable - { - return array_values($this->decode($this->queue)); - } - - public function ack(Envelope $envelope): void - { - $this->acknowledged[] = $this->encode($envelope); - - if (!$transportMessageIdStamp = $envelope->last(TransportMessageIdStamp::class)) { - throw new LogicException('No TransportMessageIdStamp found on the Envelope.'); - } - - unset($this->queue[$transportMessageIdStamp->getId()]); - } - - public function reject(Envelope $envelope): void - { - $this->rejected[] = $this->encode($envelope); - - if (!$transportMessageIdStamp = $envelope->last(TransportMessageIdStamp::class)) { - throw new LogicException('No TransportMessageIdStamp found on the Envelope.'); - } - - unset($this->queue[$transportMessageIdStamp->getId()]); - } - - public function send(Envelope $envelope): Envelope - { - $id = $this->nextId++; - $envelope = $envelope->with(new TransportMessageIdStamp($id)); - $encodedEnvelope = $this->encode($envelope); - $this->sent[] = $encodedEnvelope; - $this->queue[$id] = $encodedEnvelope; - - return $envelope; - } - - public function reset() - { - $this->sent = $this->queue = $this->rejected = $this->acknowledged = []; - } - - /** - * @return Envelope[] - */ - public function getAcknowledged(): array - { - return $this->decode($this->acknowledged); - } - - /** - * @return Envelope[] - */ - public function getRejected(): array - { - return $this->decode($this->rejected); - } - - /** - * @return Envelope[] - */ - public function getSent(): array - { - return $this->decode($this->sent); - } - - private function encode(Envelope $envelope): Envelope|array - { - if (null === $this->serializer) { - return $envelope; - } - - return $this->serializer->encode($envelope); - } - - /** - * @param array $messagesEncoded - * - * @return Envelope[] - */ - private function decode(array $messagesEncoded): array - { - if (null === $this->serializer) { - return $messagesEncoded; - } - - return array_map($this->serializer->decode(...), $messagesEncoded); - } } diff --git a/src/Symfony/Component/Messenger/Transport/InMemoryTransportFactory.php b/src/Symfony/Component/Messenger/Transport/InMemoryTransportFactory.php index 232b941c2970c..bdd4817d6a600 100644 --- a/src/Symfony/Component/Messenger/Transport/InMemoryTransportFactory.php +++ b/src/Symfony/Component/Messenger/Transport/InMemoryTransportFactory.php @@ -11,47 +11,13 @@ namespace Symfony\Component\Messenger\Transport; -use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; -use Symfony\Contracts\Service\ResetInterface; +use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory as BaseInMemoryTransportFactory; + +trigger_deprecation('symfony/messenger', '6.3', 'The "%s" class is deprecated, use "%s" instead. ', InMemoryTransportFactory::class, BaseInMemoryTransportFactory::class); /** - * @author Gary PEGEOT + * @deprecated since Symfony 6.3, use {@link BaseInMemoryTransportFactory} instead */ -class InMemoryTransportFactory implements TransportFactoryInterface, ResetInterface +class InMemoryTransportFactory extends BaseInMemoryTransportFactory { - /** - * @var InMemoryTransport[] - */ - private array $createdTransports = []; - - public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface - { - ['serialize' => $serialize] = $this->parseDsn($dsn); - - return $this->createdTransports[] = new InMemoryTransport($serialize ? $serializer : null); - } - - public function supports(string $dsn, array $options): bool - { - return str_starts_with($dsn, 'in-memory://'); - } - - public function reset() - { - foreach ($this->createdTransports as $transport) { - $transport->reset(); - } - } - - private function parseDsn(string $dsn): array - { - $query = []; - if ($queryAsString = strstr($dsn, '?')) { - parse_str(ltrim($queryAsString, '?'), $query); - } - - return [ - 'serialize' => filter_var($query['serialize'] ?? false, \FILTER_VALIDATE_BOOL), - ]; - } }