Skip to content

Commit

Permalink
TASK: Add environment specific configurations (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon authored Feb 15, 2023
1 parent 6d6d4e6 commit 2556d1b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
20 changes: 15 additions & 5 deletions Classes/DependencyInjection/MessengerConfigurationCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Ssch\T3Messenger\DependencyInjection;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Package\PackageManager;

final class MessengerConfigurationCollector
Expand All @@ -24,13 +25,22 @@ public function __construct(PackageManager $packageManager)

public function collect(): \ArrayObject
{
$configPackages = ['Configuration/Messenger.php'];
if (Environment::getContext()->isDevelopment()) {
$configPackages[] = 'Configuration/dev/Messenger.php';
} elseif (Environment::getContext()->isTesting()) {
$configPackages[] = 'Configuration/test/Messenger.php';
}

$config = new \ArrayObject();
foreach ($this->packageManager->getAvailablePackages() as $package) {
$commandBusConfigurationFile = $package->getPackagePath() . 'Configuration/Messenger.php';
if (file_exists($commandBusConfigurationFile)) {
$commandBusInPackage = require $commandBusConfigurationFile;
if (is_array($commandBusInPackage)) {
$config->exchangeArray(array_replace_recursive($config->getArrayCopy(), $commandBusInPackage));
foreach ($configPackages as $configPackage) {
$commandBusConfigurationFile = $package->getPackagePath() . $configPackage;
if (file_exists($commandBusConfigurationFile)) {
$commandBusInPackage = require $commandBusConfigurationFile;
if (is_array($commandBusInPackage)) {
$config->exchangeArray(array_replace_recursive($config->getArrayCopy(), $commandBusInPackage));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
'failed' => [
'dsn' => 'typo3-db://Default?queue_name=failed',
],
'sync' => [
'dsn' => 'sync://',
],
],
'routing' => [
MyCommand::class => [
'senders' => ['async'],
'senders' => ['sync'],
],
MyFailingCommand::class => [
'senders' => ['async'],
'senders' => ['sync'],
],
],
'buses' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "t3_messenger" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Command\MyCommand;
use Ssch\T3Messenger\Tests\Functional\Fixtures\Extensions\t3_messenger_test\Classes\Command\MyFailingCommand;

return [
'routing' => [
MyCommand::class => [
'senders' => ['async'],
],
MyFailingCommand::class => [
'senders' => ['async'],
],
],
];

0 comments on commit 2556d1b

Please sign in to comment.