Skip to content

Commit 201ac82

Browse files
committed
open 1.35-dev
1 parent c6e8e34 commit 201ac82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1579
-0
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tests/ export-ignore
2+
.gitattributes export-ignore
3+
behat.yaml export-ignore
4+
phpstan.neon export-ignore
5+
phpunit.xml export-ignore

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [dgafka]
4+
patreon: # Replace with a single Open Collective username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: This is Read-Only repository
3+
about: Report at ecotoneframework/ecotone-dev
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
Report issue at [ecotone-dev](ecotoneframework/ecotone-dev)

App/Kernel.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Ecotone\SymfonyBundle\App;
4+
5+
use function dirname;
6+
7+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8+
use Symfony\Component\Config\Loader\LoaderInterface;
9+
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
11+
use Symfony\Component\Routing\RouteCollectionBuilder;
12+
13+
class Kernel extends BaseKernel
14+
{
15+
use MicroKernelTrait;
16+
17+
public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
18+
19+
public function getCacheDir(): string
20+
{
21+
return $this->getProjectDir().'/var/cache/'.$this->environment;
22+
}
23+
24+
public function getLogDir(): string
25+
{
26+
return $this->getProjectDir().'/var/log';
27+
}
28+
29+
public function getProjectDir(): string
30+
{
31+
return dirname(__DIR__);
32+
}
33+
34+
public function registerBundles(): iterable
35+
{
36+
$contents = require $this->getProjectDir().'/config/bundles.php';
37+
foreach ($contents as $class => $envs) {
38+
if (isset($envs['all']) || isset($envs[$this->environment])) {
39+
yield new $class();
40+
}
41+
}
42+
}
43+
44+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
45+
{
46+
$container->setParameter('container.autowiring.strict_mode', true);
47+
$container->setParameter('container.dumper.inline_class_loader', true);
48+
$confDir = $this->getProjectDir().'/config';
49+
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
50+
if (is_dir($confDir.'/packages/'.$this->environment)) {
51+
$loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
52+
}
53+
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
54+
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
55+
}
56+
57+
protected function configureRoutes(RouteCollectionBuilder $routes)
58+
{
59+
$confDir = $this->getProjectDir().'/config';
60+
if (is_dir($confDir.'/routes/')) {
61+
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
62+
}
63+
if (is_dir($confDir.'/routes/'.$this->environment)) {
64+
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
65+
}
66+
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
67+
}
68+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Ecotone\SymfonyBundle\DepedencyInjection\Compiler;
4+
5+
use Ecotone\Messaging\Config\MessagingSystemConfiguration;
6+
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
7+
8+
class CacheCleaner implements CacheClearerInterface
9+
{
10+
public function clear($cacheDir)
11+
{
12+
MessagingSystemConfiguration::cleanCache($cacheDir . EcotoneCompilerPass::CACHE_DIRECTORY_SUFFIX);
13+
}
14+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Ecotone\SymfonyBundle\DepedencyInjection\Compiler;
4+
5+
use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
6+
use Ecotone\Messaging\Endpoint\ExecutionPollingMetadata;
7+
use Ecotone\Messaging\MessageChannel;
8+
use Ecotone\Messaging\MessagePublisher;
9+
use Ecotone\Messaging\Support\Assert;
10+
use Ecotone\Modelling\CommandBus;
11+
use Ecotone\Modelling\DistributedBus;
12+
use Ecotone\Modelling\EventBus;
13+
use Ecotone\Modelling\QueryBus;
14+
use Ecotone\SymfonyBundle\EcotoneSymfonyBundle;
15+
use Symfony\Component\DependencyInjection\Container;
16+
17+
class ConfiguredMessagingSystemWrapper implements ConfiguredMessagingSystem
18+
{
19+
private Container $container;
20+
21+
public function __construct(Container $container)
22+
{
23+
$this->container = $container;
24+
}
25+
26+
public function getGatewayByName(string $gatewayReferenceName): object
27+
{
28+
return $this->getConfiguredSystem()->getGatewayByName($gatewayReferenceName);
29+
}
30+
31+
public function getNonProxyGatewayByName(string $gatewayReferenceName): \Ecotone\Messaging\Config\NonProxyCombinedGateway
32+
{
33+
return $this->getConfiguredSystem()->getNonProxyGatewayByName($gatewayReferenceName);
34+
}
35+
36+
public function getGatewayList(): iterable
37+
{
38+
return $this->getConfiguredSystem()->getGatewayList();
39+
}
40+
41+
public function getMessageChannelByName(string $channelName): MessageChannel
42+
{
43+
return $this->getConfiguredSystem()->getMessageChannelByName($channelName);
44+
}
45+
46+
public function run(string $endpointId, ?ExecutionPollingMetadata $executionPollingMetadata = null): void
47+
{
48+
$this->getConfiguredSystem()->run($endpointId, $executionPollingMetadata);
49+
}
50+
51+
public function getServiceFromContainer(string $referenceName): object
52+
{
53+
Assert::isTrue($this->container->has($referenceName), "Service with reference {$referenceName} does not exists");
54+
55+
return $this->container->get($referenceName);
56+
}
57+
58+
public function getCommandBus(): CommandBus
59+
{
60+
return $this->getGatewayByName(CommandBus::class);
61+
}
62+
63+
public function getQueryBus(): QueryBus
64+
{
65+
return $this->getGatewayByName(QueryBus::class);
66+
}
67+
68+
public function getEventBus(): EventBus
69+
{
70+
return $this->getGatewayByName(EventBus::class);
71+
}
72+
73+
public function getDistributedBus(): DistributedBus
74+
{
75+
return $this->getGatewayByName(DistributedBus::class);
76+
}
77+
78+
public function getMessagePublisher(string $referenceName = MessagePublisher::class): MessagePublisher
79+
{
80+
return $this->getGatewayByName($referenceName);
81+
}
82+
83+
public function list(): array
84+
{
85+
return $this->getConfiguredSystem()->list();
86+
}
87+
88+
public function runConsoleCommand(string $commandName, array $parameters): mixed
89+
{
90+
return $this->getConfiguredSystem()->runConsoleCommand($commandName, $parameters);
91+
}
92+
93+
private function getConfiguredSystem(): ConfiguredMessagingSystem
94+
{
95+
return $this->container->get(EcotoneSymfonyBundle::CONFIGURED_MESSAGING_SYSTEM);
96+
}
97+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
namespace Ecotone\SymfonyBundle\DepedencyInjection\Compiler;
4+
5+
use Ecotone\Messaging\Config\MessagingSystemConfiguration;
6+
use Ecotone\Messaging\Config\ServiceConfiguration;
7+
use Ecotone\Messaging\ConfigurationVariableService;
8+
use Ecotone\Messaging\Gateway\ConsoleCommandRunner;
9+
use Ecotone\Messaging\Handler\Recoverability\RetryTemplateBuilder;
10+
use Ecotone\SymfonyBundle\DepedencyInjection\MessagingEntrypointCommand;
11+
use Ecotone\SymfonyBundle\EcotoneSymfonyBundle;
12+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13+
use Symfony\Component\DependencyInjection\Container;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
class EcotoneCompilerPass implements CompilerPassInterface
19+
{
20+
public const FRAMEWORK_NAMESPACE = 'Ecotone';
21+
public const SERVICE_NAME = 'ecotone.service_name';
22+
public const WORKING_NAMESPACES_CONFIG = 'ecotone.namespaces';
23+
public const FAIL_FAST_CONFIG = 'ecotone.fail_fast';
24+
public const LOAD_SRC = 'ecotone.load_src';
25+
public const DEFAULT_SERIALIZATION_MEDIA_TYPE = 'ecotone.serializationMediaType';
26+
public const ERROR_CHANNEL = 'ecotone.errorChannel';
27+
public const DEFAULT_MEMORY_LIMIT = 'ecotone.defaultMemoryLimit';
28+
public const DEFAULT_CONNECTION_EXCEPTION_RETRY = 'ecotone.defaultChannelPollRetry';
29+
public const SRC_CATALOG = 'src';
30+
public const CACHE_DIRECTORY_SUFFIX = DIRECTORY_SEPARATOR . 'ecotone';
31+
32+
/**
33+
* @param Container $container
34+
*
35+
* @return bool|string
36+
*/
37+
public static function getRootProjectPath(Container $container)
38+
{
39+
return realpath(($container->hasParameter('kernel.project_dir') ? $container->getParameter('kernel.project_dir') : $container->getParameter('kernel.root_dir') . '/..'));
40+
}
41+
42+
public function process(ContainerBuilder $container)
43+
{
44+
$ecotoneCacheDirectory = $container->getParameter('kernel.cache_dir') . self::CACHE_DIRECTORY_SUFFIX;
45+
$applicationConfiguration = ServiceConfiguration::createWithDefaults()
46+
->withEnvironment($container->getParameter('kernel.environment'))
47+
->withFailFast($container->getParameter('kernel.environment') === 'prod' ? false : $container->getParameter(self::FAIL_FAST_CONFIG))
48+
->withLoadCatalog($container->getParameter(self::LOAD_SRC) ? 'src' : '')
49+
->withNamespaces(
50+
array_merge(
51+
$container->getParameter(self::WORKING_NAMESPACES_CONFIG),
52+
[self::FRAMEWORK_NAMESPACE]
53+
)
54+
)
55+
->withCacheDirectoryPath($ecotoneCacheDirectory);
56+
57+
if ($container->getParameter(self::SERVICE_NAME)) {
58+
$applicationConfiguration = $applicationConfiguration
59+
->withServiceName($container->getParameter(self::SERVICE_NAME));
60+
}
61+
62+
if ($container->getParameter(self::DEFAULT_SERIALIZATION_MEDIA_TYPE)) {
63+
$applicationConfiguration = $applicationConfiguration
64+
->withDefaultSerializationMediaType($container->getParameter(self::DEFAULT_SERIALIZATION_MEDIA_TYPE));
65+
}
66+
if ($container->getParameter(self::DEFAULT_MEMORY_LIMIT)) {
67+
$applicationConfiguration = $applicationConfiguration
68+
->withConsumerMemoryLimit($container->getParameter(self::DEFAULT_MEMORY_LIMIT));
69+
}
70+
if ($container->getParameter(self::DEFAULT_CONNECTION_EXCEPTION_RETRY)) {
71+
$retryTemplate = $container->getParameter(self::DEFAULT_CONNECTION_EXCEPTION_RETRY);
72+
$applicationConfiguration = $applicationConfiguration
73+
->withConnectionRetryTemplate(
74+
RetryTemplateBuilder::exponentialBackoffWithMaxDelay(
75+
$retryTemplate['initialDelay'],
76+
$retryTemplate['maxAttempts'],
77+
$retryTemplate['multiplier']
78+
)
79+
);
80+
}
81+
if ($container->getParameter(self::ERROR_CHANNEL)) {
82+
$applicationConfiguration = $applicationConfiguration
83+
->withDefaultErrorChannel($container->getParameter(self::ERROR_CHANNEL));
84+
}
85+
86+
$configurationVariableService = new SymfonyConfigurationVariableService($container);
87+
$messagingConfiguration = MessagingSystemConfiguration::prepare(
88+
self::getRootProjectPath($container),
89+
new SymfonyReferenceTypeResolver($container),
90+
$configurationVariableService,
91+
$applicationConfiguration,
92+
false
93+
);
94+
95+
$definition = new Definition();
96+
$definition->setClass(SymfonyConfigurationVariableService::class);
97+
$definition->setPublic(true);
98+
$definition->addArgument(new Reference('service_container'));
99+
$container->setDefinition(ConfigurationVariableService::REFERENCE_NAME, $definition);
100+
101+
$definition = new $definition();
102+
$definition->setClass(CacheCleaner::class);
103+
$definition->setPublic(true);
104+
$definition->addTag('kernel.cache_clearer');
105+
$container->setDefinition(CacheCleaner::class, $definition);
106+
107+
$definition = new Definition();
108+
$definition->setClass(SymfonyReferenceSearchService::class);
109+
$definition->setPublic(true);
110+
$definition->addArgument(new Reference('service_container'));
111+
$container->setDefinition('symfonyReferenceSearchService', $definition);
112+
113+
foreach ($messagingConfiguration->getRegisteredGateways() as $gatewayProxyBuilder) {
114+
$definition = new Definition();
115+
$definition->setFactory([ProxyGenerator::class, 'createFor']);
116+
$definition->setClass($gatewayProxyBuilder->getInterfaceName());
117+
$definition->addArgument($gatewayProxyBuilder->getReferenceName());
118+
$definition->addArgument(new Reference('service_container'));
119+
$definition->addArgument($gatewayProxyBuilder->getInterfaceName());
120+
$definition->addArgument($ecotoneCacheDirectory);
121+
$definition->addArgument($container->getParameter(self::FAIL_FAST_CONFIG));
122+
$definition->setPublic(true);
123+
124+
$container->setDefinition($gatewayProxyBuilder->getReferenceName(), $definition);
125+
}
126+
127+
foreach ($messagingConfiguration->getRequiredReferences() as $requiredReference) {
128+
$alias = $container->setAlias($requiredReference . '-proxy', $requiredReference);
129+
130+
if ($alias) {
131+
$alias->setPublic(true);
132+
}
133+
}
134+
135+
foreach ($messagingConfiguration->getOptionalReferences() as $requiredReference) {
136+
if ($container->has($requiredReference)) {
137+
$alias = $container->setAlias($requiredReference . '-proxy', $requiredReference);
138+
139+
if ($alias) {
140+
$alias->setPublic(true);
141+
}
142+
}
143+
}
144+
145+
foreach ($messagingConfiguration->getRegisteredConsoleCommands() as $oneTimeCommandConfiguration) {
146+
$definition = new Definition();
147+
$definition->setClass(MessagingEntrypointCommand::class);
148+
$definition->addArgument($oneTimeCommandConfiguration->getName());
149+
$definition->addArgument(serialize($oneTimeCommandConfiguration->getParameters()));
150+
$definition->addArgument(new Reference(ConsoleCommandRunner::class));
151+
$definition->addTag('console.command', ['command' => $oneTimeCommandConfiguration->getName()]);
152+
153+
$container->setDefinition($oneTimeCommandConfiguration->getChannelName(), $definition);
154+
}
155+
156+
$container->setParameter(EcotoneSymfonyBundle::APPLICATION_CONFIGURATION_CONTEXT, serialize($applicationConfiguration));
157+
}
158+
}

0 commit comments

Comments
 (0)