TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\Messenger;
|
||||
|
||||
use Symfony\Component\Messenger\MessageBus;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/**
|
||||
* @internal not part of TYPO3 Core API
|
||||
*/
|
||||
final readonly class BusFactory
|
||||
{
|
||||
/**
|
||||
* @param array<string, \IteratorAggregate> $middlewares
|
||||
*/
|
||||
public function __construct(
|
||||
private array $middlewares
|
||||
) {}
|
||||
|
||||
public function createBus(string $bus = 'default'): MessageBusInterface
|
||||
{
|
||||
return new MessageBus(
|
||||
$this->middlewares[$bus] ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\Messenger;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
|
||||
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
|
||||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
|
||||
|
||||
/**
|
||||
* @internal not part of TYPO3 Core API
|
||||
*/
|
||||
final class DoctrineTransportFactory
|
||||
{
|
||||
public function __construct(private SerializerInterface $serializer) {}
|
||||
|
||||
public function createTransport(array $options = []): DoctrineTransport
|
||||
{
|
||||
$options['table_name'] ??= 'sys_messenger_messages';
|
||||
if ($options['table_name'] === 'sys_messenger_messages') {
|
||||
$options['auto_setup'] = false;
|
||||
}
|
||||
|
||||
// use native doctrine dbal connection instead of TYPO3s overwritten one
|
||||
// as the overwritten querybuilder is not fully compatible with symfony messenger
|
||||
$connection = DriverManager::getConnection($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']);
|
||||
$doctrineTransportConnection = new Connection($options, $connection);
|
||||
return new DoctrineTransport($doctrineTransportConnection, $this->serializer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\Messenger;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Messenger\Handler\HandlerDescriptor;
|
||||
use Symfony\Component\Messenger\Handler\HandlersLocator;
|
||||
|
||||
/**
|
||||
* @internal not part of TYPO3 Core API
|
||||
*/
|
||||
final class HandlersLocatorFactory
|
||||
{
|
||||
private array $handlers = [];
|
||||
|
||||
public function __construct(private readonly ContainerInterface $container) {}
|
||||
|
||||
public function createHandlersLocator(): HandlersLocator
|
||||
{
|
||||
return new HandlersLocator(
|
||||
$this->handlers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* internally called by the messageHandlerPass
|
||||
*/
|
||||
public function addHandler(string $messageClass, string $handlerService, string $handlerMethod): void
|
||||
{
|
||||
$container = $this->container;
|
||||
$this->handlers[$messageClass][] = new HandlerDescriptor(
|
||||
function (...$args) use ($container, $handlerService, $handlerMethod) {
|
||||
if ($handlerMethod === '__invoke') {
|
||||
return $container->get($handlerService)(...$args);
|
||||
}
|
||||
return $container->get($handlerService)->{$handlerMethod}(...$args);
|
||||
},
|
||||
[
|
||||
'alias' => $handlerService . '::' . $handlerMethod,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\Messenger;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\RuntimeException;
|
||||
use Symfony\Component\Messenger\Handler\HandlersLocator;
|
||||
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
|
||||
use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface;
|
||||
|
||||
/**
|
||||
* A locator that returns the senders for a given message.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
readonly class TransportLocator implements SendersLocatorInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[AutowireLocator('messenger.sender', indexAttribute: 'identifier')]
|
||||
private ContainerInterface $sendersLocator,
|
||||
) {}
|
||||
|
||||
public function getSenders(Envelope $envelope): iterable
|
||||
{
|
||||
$sendersMap = $GLOBALS['TYPO3_CONF_VARS']['SYS']['messenger']['routing'];
|
||||
if ($envelope->all(TransportNamesStamp::class)) {
|
||||
foreach ($envelope->last(TransportNamesStamp::class)->getTransportNames() as $senderAlias) {
|
||||
yield from $this->getSenderFromConfiguration($senderAlias);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$seen = [];
|
||||
|
||||
foreach (HandlersLocator::listTypes($envelope) as $type) {
|
||||
$transportForMessage = $sendersMap[$type] ?? [];
|
||||
if (is_string($transportForMessage)) {
|
||||
$transportForMessage = [$transportForMessage];
|
||||
}
|
||||
foreach ($transportForMessage as $senderAlias) {
|
||||
if (!in_array($senderAlias, $seen, true)) {
|
||||
$seen[] = $senderAlias;
|
||||
|
||||
yield from $this->getSenderFromConfiguration($senderAlias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getSenderFromConfiguration(string $senderAlias): iterable
|
||||
{
|
||||
if (!$this->sendersLocator->has($senderAlias)) {
|
||||
throw new RuntimeException(sprintf('Invalid senders configuration: sender "%s" is not registered via messenger.sender tag.', $senderAlias), 1605192311);
|
||||
}
|
||||
|
||||
yield $senderAlias => $this->sendersLocator->get($senderAlias);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user