Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ecotoneframework/ecotone-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dgafka committed May 28, 2023
2 parents 9c8b0e3 + 7e59fd8 commit a17eb86
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 220 deletions.
9 changes: 5 additions & 4 deletions packages/Ecotone/src/Lite/EcotoneLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ProxyGenerator;
use Ecotone\Messaging\Config\ServiceConfiguration;
use Ecotone\Messaging\Config\StubConfiguredMessagingSystem;
use Ecotone\Messaging\Handler\ClassDefinition;
use Ecotone\Messaging\Handler\TypeDescriptor;
use Ecotone\Messaging\InMemoryConfigurationVariableService;
Expand Down Expand Up @@ -181,9 +180,11 @@ private static function prepareConfiguration(ContainerInterface|array $container
}
}

$messagingSystem = $messagingConfiguration->buildMessagingSystemFromConfiguration(
new PsrContainerReferenceSearchService($container, ['logger' => new NullLogger(), ConfiguredMessagingSystem::class => new StubConfiguredMessagingSystem()])
);
$referenceSearchService = new PsrContainerReferenceSearchService($container, ['logger' => new NullLogger()]);

$messagingSystem = $messagingConfiguration->buildMessagingSystemFromConfiguration($referenceSearchService);

$referenceSearchService->setConfiguredMessagingSystem($messagingSystem);

if ($allowGatewaysToBeRegisteredInContainer) {
$container->set(ConfiguredMessagingSystem::class, $messagingSystem);
Expand Down
6 changes: 4 additions & 2 deletions packages/Ecotone/src/Lite/EcotoneLiteConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Ecotone\Messaging\Config\MessagingSystemConfiguration;
use Ecotone\Messaging\Config\ServiceConfiguration;
use Ecotone\Messaging\Config\StubConfiguredMessagingSystem;
use Ecotone\Messaging\Handler\Logger\EchoLogger;
use Ecotone\Messaging\InMemoryConfigurationVariableService;
use Psr\Container\ContainerInterface;
Expand All @@ -27,13 +26,16 @@ public static function create(string $rootProjectDirectoryPath, ContainerInterfa

public static function createWithConfiguration(string $rootProjectDirectoryPath, ContainerInterface|GatewayAwareContainer $container, ServiceConfiguration $serviceConfiguration, array $configurationVariables, bool $useCachedVersion, array $classesToRegister = []): ConfiguredMessagingSystem
{
$referenceSearchService = new PsrContainerReferenceSearchService($container, ['logger' => new EchoLogger()]);
$configuredMessagingSystem = MessagingSystemConfiguration::prepare(
realpath($rootProjectDirectoryPath),
InMemoryConfigurationVariableService::create($configurationVariables),
$serviceConfiguration,
$useCachedVersion,
$classesToRegister
)->buildMessagingSystemFromConfiguration(new PsrContainerReferenceSearchService($container, ['logger' => new EchoLogger(), ConfiguredMessagingSystem::class => new StubConfiguredMessagingSystem()]));
)->buildMessagingSystemFromConfiguration($referenceSearchService);

$referenceSearchService->setConfiguredMessagingSystem($configuredMessagingSystem);

if ($container instanceof GatewayAwareContainer) {
foreach ($configuredMessagingSystem->getGatewayList() as $gatewayReference) {
Expand Down
18 changes: 18 additions & 0 deletions packages/Ecotone/src/Lite/PsrContainerReferenceSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Ecotone\Lite;

use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Ecotone\Messaging\Config\LazyConfiguredMessagingSystem;
use Ecotone\Messaging\Handler\ReferenceNotFoundException;
use Ecotone\Messaging\Handler\ReferenceSearchService;
use Psr\Container\ContainerInterface;
Expand All @@ -13,10 +15,13 @@ class PsrContainerReferenceSearchService implements ReferenceSearchService
private ContainerInterface $container;
private array $defaults;

private LazyConfiguredMessagingSystem $lazyConfiguredMessagingSystem;

public function __construct(ContainerInterface $container, array $defaults = [])
{
$this->container = $container;
$this->defaults = $defaults;
$this->lazyConfiguredMessagingSystem = new LazyConfiguredMessagingSystem();
}

/**
Expand All @@ -28,6 +33,9 @@ public function get(string $reference): object
if (array_key_exists($reference, $this->defaults)) {
return $this->defaults[$reference];
}
if ($reference === ConfiguredMessagingSystem::class) {
return $this->lazyConfiguredMessagingSystem;
}

if ($this->container->has($reference . self::POSSIBLE_REFERENCE_SUFFIX)) {
return $this->container->get($reference . self::POSSIBLE_REFERENCE_SUFFIX);
Expand All @@ -51,4 +59,14 @@ public function has(string $referenceName): bool

return true;
}

public function setConfiguredMessagingSystem(ConfiguredMessagingSystem $configuredMessagingSystem): void
{
$this->lazyConfiguredMessagingSystem->replaceWith($configuredMessagingSystem);
}

public static function getServiceNameWithSuffix(string $referenceName)
{
return $referenceName . self::POSSIBLE_REFERENCE_SUFFIX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
use Ecotone\Messaging\Endpoint\ExecutionPollingMetadata;
use Ecotone\Messaging\MessageChannel;
use Ecotone\Messaging\MessagePublisher;
use Ecotone\Messaging\Support\Assert;
use Ecotone\Modelling\CommandBus;
use Ecotone\Modelling\DistributedBus;
use Ecotone\Modelling\EventBus;
use Ecotone\Modelling\QueryBus;
use Psr\Container\ContainerInterface;
use InvalidArgumentException;

/**
* configured messaging system is set up on boot, so in case of fetching it during initialization we need to provide lazy config
*/
class LazyConfiguredMessagingSystem implements ConfiguredMessagingSystem
{
public function __construct(private ContainerInterface $container)
private ?ConfiguredMessagingSystem $configuredMessagingSystem = null;

public function __construct()
{
}

Expand Down Expand Up @@ -48,9 +49,7 @@ public function run(string $endpointId, ?ExecutionPollingMetadata $executionPoll

public function getServiceFromContainer(string $referenceName): object
{
Assert::isTrue($this->container->has($referenceName), "Service with reference {$referenceName} does not exists");

return $this->container->get($referenceName);
return $this->getConfiguredSystem()->getServiceFromContainer($referenceName);
}

public function getCommandBus(): CommandBus
Expand Down Expand Up @@ -90,11 +89,14 @@ public function runConsoleCommand(string $commandName, array $parameters): mixed

public function replaceWith(ConfiguredMessagingSystem $messagingSystem): void
{
$this->getConfiguredSystem()->replaceWith($messagingSystem);
$this->configuredMessagingSystem = $messagingSystem;
}

private function getConfiguredSystem(): ConfiguredMessagingSystem
{
return $this->container->get(LazyConfiguredMessagingSystem::class);
if (! $this->configuredMessagingSystem) {
throw new InvalidArgumentException('Configured messaging system was not set');
}
return $this->configuredMessagingSystem;
}
}

This file was deleted.

30 changes: 30 additions & 0 deletions packages/Ecotone/tests/Lite/EcotoneLiteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Test\Ecotone\Lite;

use Ecotone\Lite\EcotoneLite;
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ServiceConfiguration;
use PHPUnit\Framework\TestCase;
use Test\Ecotone\Modelling\Fixture\Order\ChannelConfiguration;
use Test\Ecotone\Modelling\Fixture\Order\OrderService;

/**
* @internal
*/
class EcotoneLiteTest extends TestCase
{
public function test_it_can_run_console_command(): void
{
$ecotone = EcotoneLite::bootstrap(
[OrderService::class, ChannelConfiguration::class],
[new OrderService()],
ServiceConfiguration::createWithDefaults()
->withSkippedModulePackageNames(ModulePackageList::allPackages())
->withEnvironment('test')
);

$ecotone->runConsoleCommand('ecotone:list', []);
$this->expectNotToPerformAssertions();
}
}
15 changes: 6 additions & 9 deletions packages/Laravel/src/EcotoneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use const DIRECTORY_SEPARATOR;

use Ecotone\Lite\PsrContainerReferenceSearchService;

use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Ecotone\Messaging\Config\ConsoleCommandResultSet;

use Ecotone\Messaging\Config\LazyConfiguredMessagingSystem;
use Ecotone\Messaging\Config\MessagingSystemConfiguration;
use Ecotone\Messaging\Config\ProxyGenerator;
use Ecotone\Messaging\Config\ServiceConfiguration;
Expand Down Expand Up @@ -166,15 +167,11 @@ function (ConfiguredMessagingSystem $configuredMessagingSystem) {

$this->app->singleton(
ConfiguredMessagingSystem::class,
function () {
return new LazyConfiguredMessagingSystem($this->app);
}
);

$this->app->singleton(
LazyConfiguredMessagingSystem::class,
function () use ($configuration) {
return $configuration->buildMessagingSystemFromConfiguration(new LaravelReferenceSearchService($this->app));
$referenceSearchService = new PsrContainerReferenceSearchService($this->app);
$messagingSystem = $configuration->buildMessagingSystemFromConfiguration($referenceSearchService);
$referenceSearchService->setConfiguredMessagingSystem($messagingSystem);
return $messagingSystem;
}
);
}
Expand Down
29 changes: 0 additions & 29 deletions packages/Laravel/src/LaravelReferenceSearchService.php

This file was deleted.

39 changes: 0 additions & 39 deletions packages/Laravel/tests/LaravelReferenceSearchServiceTest.php

This file was deleted.

Loading

0 comments on commit a17eb86

Please sign in to comment.