Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix resolving DSN from dynamic environment variables #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Enqueue\Bundle\DependencyInjection\Compiler;

use Enqueue\Bundle\DependencyInjection\EnqueueExtension;
use Enqueue\Symfony\DriverFactoryInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class BuildTransportFactoriesPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
/** @var EnqueueExtension $extension */
$extension = $container->getExtension('enqueue');
$config = $container->resolveEnvPlaceholders($extension->getProcessedConfig(), true);

$factories = $extension->getTransportFactories();

foreach ($config['transport'] as $name => $transportConfig) {
$factories[$name]->createConnectionFactory($container, $transportConfig);
$factories[$name]->createContext($container, $transportConfig);

if ($factories[$name] instanceof DriverFactoryInterface && isset($config['client'])) {
$factories[$name]->createDriver($container, $transportConfig);
}
}
}
}
34 changes: 23 additions & 11 deletions pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,36 @@ class EnqueueExtension extends Extension implements PrependExtensionInterface
*/
private $factories;

/**
* @var array
*/
private $processedConfig;

public function __construct()
{
$this->factories = [];
$this->processedConfig = [];

$this->addTransportFactory(new DefaultTransportFactory());
$this->addTransportFactory(new NullTransportFactory());
}

/**
* @return array
*/
public function getProcessedConfig()
{
return $this->processedConfig;
}

/**
* @return TransportFactoryInterface[]
*/
public function getTransportFactories()
{
return $this->factories;
}

/**
* @param TransportFactoryInterface $transportFactory
*/
Expand Down Expand Up @@ -70,28 +92,18 @@ public function setTransportFactory(TransportFactoryInterface $transportFactory)
public function load(array $configs, ContainerBuilder $container)
{
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
$this->processedConfig = $config;

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$this->setupAutowiringForProcessors($container);

foreach ($config['transport'] as $name => $transportConfig) {
$this->factories[$name]->createConnectionFactory($container, $transportConfig);
$this->factories[$name]->createContext($container, $transportConfig);
}

if (isset($config['client'])) {
$loader->load('client.yml');
$loader->load('extensions/flush_spool_producer_extension.yml');
$loader->load('extensions/exclusive_command_extension.yml');

foreach ($config['transport'] as $name => $transportConfig) {
if ($this->factories[$name] instanceof DriverFactoryInterface) {
$this->factories[$name]->createDriver($container, $transportConfig);
}
}

if (isset($config['transport']['default']['alias']) && !isset($config['transport'][$config['transport']['default']['alias']])) {
throw new \LogicException(sprintf('Transport is not enabled: %s', $config['transport']['default']['alias']));
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/enqueue-bundle/EnqueueBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Enqueue\AsyncEventDispatcher\DependencyInjection\AsyncTransformersPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildClientExtensionsPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildClientRoutingPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildTransportFactoriesPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildConsumptionExtensionsPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildExclusiveCommandsExtensionPass;
use Enqueue\Bundle\DependencyInjection\Compiler\BuildProcessorRegistryPass;
Expand Down Expand Up @@ -45,6 +46,7 @@ class EnqueueBundle extends Bundle
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new BuildTransportFactoriesPass());
$container->addCompilerPass(new BuildConsumptionExtensionsPass());
$container->addCompilerPass(new BuildClientRoutingPass());
$container->addCompilerPass(new BuildProcessorRegistryPass());
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue-bundle/Tests/Functional/Client/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function setUp()

public function tearDown()
{
parent::tearDown();

static::$container->get(Producer::class)->clearTraces();

parent::tearDown();
}

public function testCouldBeGetFromContainerAsService()
Expand Down
Loading