Skip to content
Merged
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
Expand Up @@ -2207,6 +2207,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
$resourceStore = 'null';
}

$usedEnvs = [];
$storeDsn = $container->resolveEnvPlaceholders($resourceStore, null, $usedEnvs);
if (!$usedEnvs && !str_contains($resourceStore, ':') && !\in_array($resourceStore, ['flock', 'semaphore', 'in-memory', 'null'], true)) {
$resourceStore = new Reference($resourceStore);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$container->setParameter('env(REDIS_DSN)', 'redis://paas.com');

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'lock' => [
'foo' => '%env(REDIS_DSN)%',
'bar' => 'my_service',
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<parameters>
<parameter key="env(REDIS_URL)">redis://paas.com</parameter>
</parameters>

<framework:config http-method-override="false" handle-all-throwables="true">
<framework:annotations enabled="false" />
<framework:php-errors log="true" />
<framework:lock>
<framework:resource name="foo">%env(REDIS_DSN)%</framework:resource>
<framework:resource name="bar">my_service</framework:resource>
</framework:lock>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
my_service:
class: \Redis

framework:
annotations: false
http_method_override: false
handle_all_throwables: true
php_errors:
log: true
lock:
foo: "%env(REDIS_DSN)%"
bar: my_service
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,21 @@ public function testLockWithService()
self::assertEquals(new Reference('my_service'), $storeDef->getArgument(0));
}

public function testLockWithServiceAndEnv()
{
$container = $this->createContainerFromFile('lock_service_and_env', [], true, false);
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]);
$container->compile();

self::assertTrue($container->hasDefinition('lock.foo.factory'));
self::assertTrue($container->hasDefinition('lock.bar.factory'));
$storeDef = $container->getDefinition($container->getDefinition('lock.bar.factory')->getArgument(0));

$connection = $storeDef->getArgument(0);
self::assertInstanceOf(Reference::class, $connection);
self::assertEquals('my_service', $connection->__toString());
}

public function testDefaultSemaphore()
{
$container = $this->createContainerFromFile('semaphore');
Expand Down
Loading