Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MessageBusFactory | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Queue message bus factory. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2026-02-11 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Queue; |
| 21 | |
| 22 | use phpMyFAQ\Configuration; |
| 23 | use phpMyFAQ\Queue\Transport\DatabaseTransport; |
| 24 | use RuntimeException; |
| 25 | |
| 26 | final readonly class MessageBusFactory |
| 27 | { |
| 28 | public function __construct( |
| 29 | private Configuration $configuration, |
| 30 | private DatabaseTransport $databaseTransport, |
| 31 | ) { |
| 32 | } |
| 33 | |
| 34 | public function create(): DatabaseMessageBus |
| 35 | { |
| 36 | $transport = strtolower((string) ($this->configuration->get('queue.transport') ?? 'database')); |
| 37 | |
| 38 | return match ($transport) { |
| 39 | 'database' => new DatabaseMessageBus($this->databaseTransport), |
| 40 | 'redis', 'amqp' => throw new RuntimeException(sprintf( |
| 41 | 'Queue transport "%s" is not implemented yet.', |
| 42 | $transport, |
| 43 | )), |
| 44 | default => throw new RuntimeException('Unsupported queue transport: ' . $transport), |
| 45 | }; |
| 46 | } |
| 47 | } |