Skip to content

Commit 61e6239

Browse files
Merge branch '6.4' into 7.2
* 6.4: switch to Composer 2 metadata Fix `ContainerDebugCommandTest::testNoDumpedXML` doc: update UserInterface header comments Fix: Lack of recipient in case DSN does not have optional LIST_ID parameter. [PhpUnitBridge] Mark as dev package [DependencyInjection] Make `YamlDumper` quote resolved env vars if necessary Bump Symfony version to 6.4.23 Update VERSION for 6.4.22 Update CONTRIBUTORS for 6.4.22 Update CHANGELOG for 6.4.22 fixed Via regex
2 parents 8007d7a + aeb34cc commit 61e6239

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

Dumper/YamlDumper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ public function dump(array $options = []): string
5050

5151
$this->dumper ??= new YmlDumper();
5252

53-
return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices());
53+
return $this->addParameters()."\n".$this->addServices();
5454
}
5555

5656
private function addService(string $id, Definition $definition): string
5757
{
58-
$code = " $id:\n";
58+
$code = " {$this->dumper->dump($id)}:\n";
5959
if ($class = $definition->getClass()) {
6060
if (str_starts_with($class, '\\')) {
6161
$class = substr($class, 1);
6262
}
6363

64-
$code .= \sprintf(" class: %s\n", $this->dumper->dump($class));
64+
$code .= \sprintf(" class: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($class)));
6565
}
6666

6767
if (!$definition->isPrivate()) {
@@ -87,7 +87,7 @@ private function addService(string $id, Definition $definition): string
8787
}
8888

8989
if ($definition->getFile()) {
90-
$code .= \sprintf(" file: %s\n", $this->dumper->dump($definition->getFile()));
90+
$code .= \sprintf(" file: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($definition->getFile())));
9191
}
9292

9393
if ($definition->isSynthetic()) {
@@ -238,7 +238,7 @@ private function dumpCallable(mixed $callable): mixed
238238
}
239239
}
240240

241-
return $callable;
241+
return $this->container->resolveEnvPlaceholders($callable);
242242
}
243243

244244
/**
@@ -299,7 +299,7 @@ private function dumpValue(mixed $value): mixed
299299
if (\is_array($value)) {
300300
$code = [];
301301
foreach ($value as $k => $v) {
302-
$code[$k] = $this->dumpValue($v);
302+
$code[$this->container->resolveEnvPlaceholders($k)] = $this->dumpValue($v);
303303
}
304304

305305
return $code;
@@ -319,7 +319,7 @@ private function dumpValue(mixed $value): mixed
319319
throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
320320
}
321321

322-
return $value;
322+
return $this->container->resolveEnvPlaceholders($value);
323323
}
324324

325325
private function getServiceCall(string $id, ?Reference $reference = null): string
@@ -359,7 +359,7 @@ private function prepareParameters(array $parameters, bool $escape = true): arra
359359
$filtered[$key] = $value;
360360
}
361361

362-
return $escape ? $this->escape($filtered) : $filtered;
362+
return $escape ? $this->container->resolveEnvPlaceholders($this->escape($filtered)) : $filtered;
363363
}
364364

365365
private function escape(array $arguments): array

Tests/Dumper/YamlDumperTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ public function testDumpNonScalarTags()
215215
$this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services_with_array_tags.yml'), $dumper->dump());
216216
}
217217

218+
public function testDumpResolvedEnvPlaceholders()
219+
{
220+
$container = new ContainerBuilder();
221+
$container->setParameter('%env(PARAMETER_NAME)%', '%env(PARAMETER_VALUE)%');
222+
$container
223+
->register('service', '%env(SERVICE_CLASS)%')
224+
->setFile('%env(SERVICE_FILE)%')
225+
->addArgument('%env(SERVICE_ARGUMENT)%')
226+
->setProperty('%env(SERVICE_PROPERTY_NAME)%', '%env(SERVICE_PROPERTY_VALUE)%')
227+
->addMethodCall('%env(SERVICE_METHOD_NAME)%', ['%env(SERVICE_METHOD_ARGUMENT)%'])
228+
->setFactory('%env(SERVICE_FACTORY)%')
229+
->setConfigurator('%env(SERVICE_CONFIGURATOR)%')
230+
->setPublic(true)
231+
;
232+
$container->compile();
233+
$dumper = new YamlDumper($container);
234+
235+
$this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/container_with_env_placeholders.yml'), $dumper->dump());
236+
}
237+
218238
private function assertEqualYamlStructure(string $expected, string $yaml, string $message = '')
219239
{
220240
$parser = new Parser();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
'%env(PARAMETER_NAME)%': '%env(PARAMETER_VALUE)%'
3+
4+
services:
5+
service_container:
6+
class: Symfony\Component\DependencyInjection\ContainerInterface
7+
public: true
8+
synthetic: true
9+
service:
10+
class: '%env(SERVICE_CLASS)%'
11+
public: true
12+
file: '%env(SERVICE_FILE)%'
13+
arguments: ['%env(SERVICE_ARGUMENT)%']
14+
properties: { '%env(SERVICE_PROPERTY_NAME)%': '%env(SERVICE_PROPERTY_VALUE)%' }
15+
calls:
16+
- ['%env(SERVICE_METHOD_NAME)%', ['%env(SERVICE_METHOD_ARGUMENT)%']]
17+
18+
factory: '%env(SERVICE_FACTORY)%'
19+
configurator: '%env(SERVICE_CONFIGURATOR)%'

0 commit comments

Comments
 (0)