Skip to content

Commit 5ff3af3

Browse files
committed
Merge branch '4.0' into 4.1
* 4.0: do not mock the session in token storage tests [DependencyInjection] resolve array env vars Add Occitan plural rule Fix security/* cross-dependencies [Lock] Skip test if posix extension is not installed [DI] Allow defining bindings on ChildDefinition use strict compare in url validator Disallow illegal characters like "." in session.name [HttpKernel] do file_exists() check instead of silent notice fix rounding from string
2 parents 18937a6 + c5d5cd9 commit 5ff3af3

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

ChildDefinition.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,4 @@ public function setInstanceofConditionals(array $instanceof)
121121
{
122122
throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
123123
}
124-
125-
/**
126-
* @internal
127-
*/
128-
public function setBindings(array $bindings)
129-
{
130-
throw new BadMethodCallException('A ChildDefinition cannot have bindings set on it.');
131-
}
132124
}

Compiler/ResolveChildDefinitionsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function doResolveDefinition(ChildDefinition $definition)
100100
$def->setAutowired($parentDef->isAutowired());
101101
$def->setChanges($parentDef->getChanges());
102102

103-
$def->setBindings($parentDef->getBindings());
103+
$def->setBindings($definition->getBindings() + $parentDef->getBindings());
104104

105105
// overwrite with values specified in the decorator
106106
$changes = $definition->getChanges();

ContainerBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
13631363
}
13641364
$envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders;
13651365

1366+
$completed = false;
13661367
foreach ($envPlaceholders as $env => $placeholders) {
13671368
foreach ($placeholders as $placeholder) {
13681369
if (false !== stripos($value, $placeholder)) {
@@ -1373,14 +1374,19 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
13731374
}
13741375
if ($placeholder === $value) {
13751376
$value = $resolved;
1377+
$completed = true;
13761378
} else {
13771379
if (!is_string($resolved) && !is_numeric($resolved)) {
1378-
throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type %s inside string value "%s".', $env, gettype($resolved), $value));
1380+
throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type %s inside string value "%s".', $env, gettype($resolved), $this->resolveEnvPlaceholders($value)));
13791381
}
13801382
$value = str_ireplace($placeholder, $resolved, $value);
13811383
}
13821384
$usedEnvs[$env] = $env;
13831385
$this->envCounters[$env] = isset($this->envCounters[$env]) ? 1 + $this->envCounters[$env] : 1;
1386+
1387+
if ($completed) {
1388+
break 2;
1389+
}
13841390
}
13851391
}
13861392
}

Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,27 @@ public function testProcessSetsArguments()
355355
$this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments());
356356
}
357357

358+
public function testBindings()
359+
{
360+
$container = new ContainerBuilder();
361+
362+
$container->register('parent', 'stdClass')
363+
->setBindings(array('a' => '1', 'b' => '2'))
364+
;
365+
366+
$child = $container->setDefinition('child', new ChildDefinition('parent'))
367+
->setBindings(array('b' => 'B', 'c' => 'C'))
368+
;
369+
370+
$this->process($container);
371+
372+
$bindings = array();
373+
foreach ($container->getDefinition('child')->getBindings() as $k => $v) {
374+
$bindings[$k] = $v->getValues()[0];
375+
}
376+
$this->assertEquals(array('b' => 'B', 'c' => 'C', 'a' => '1'), $bindings);
377+
}
378+
358379
public function testSetAutoconfiguredOnServiceIsParent()
359380
{
360381
$container = new ContainerBuilder();

Tests/ContainerBuilderTest.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,49 @@ public function testCompileWithResolveEnv()
665665
putenv('DUMMY_ENV_VAR');
666666
}
667667

668+
public function testCompileWithArrayResolveEnv()
669+
{
670+
putenv('ARRAY={"foo":"bar"}');
671+
672+
$container = new ContainerBuilder();
673+
$container->setParameter('foo', '%env(json:ARRAY)%');
674+
$container->compile(true);
675+
676+
$this->assertSame(array('foo' => 'bar'), $container->getParameter('foo'));
677+
678+
putenv('ARRAY');
679+
}
680+
681+
public function testCompileWithArrayAndAnotherResolveEnv()
682+
{
683+
putenv('DUMMY_ENV_VAR=abc');
684+
putenv('ARRAY={"foo":"bar"}');
685+
686+
$container = new ContainerBuilder();
687+
$container->setParameter('foo', '%env(json:ARRAY)%');
688+
$container->setParameter('bar', '%env(DUMMY_ENV_VAR)%');
689+
$container->compile(true);
690+
691+
$this->assertSame(array('foo' => 'bar'), $container->getParameter('foo'));
692+
$this->assertSame('abc', $container->getParameter('bar'));
693+
694+
putenv('DUMMY_ENV_VAR');
695+
putenv('ARRAY');
696+
}
697+
668698
/**
669699
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
670-
* @expectedExceptionMessage A string value must be composed of strings and/or numbers, but found parameter "env(ARRAY)" of type array inside string value "ABC %env(ARRAY)%".
700+
* @expectedExceptionMessage A string value must be composed of strings and/or numbers, but found parameter "env(json:ARRAY)" of type array inside string value "ABC %env(json:ARRAY)%".
671701
*/
672-
public function testCompileWithArrayResolveEnv()
702+
public function testCompileWithArrayInStringResolveEnv()
673703
{
674-
$bag = new TestingEnvPlaceholderParameterBag();
675-
$container = new ContainerBuilder($bag);
676-
$container->setParameter('foo', '%env(ARRAY)%');
677-
$container->setParameter('bar', 'ABC %env(ARRAY)%');
704+
putenv('ARRAY={"foo":"bar"}');
705+
706+
$container = new ContainerBuilder();
707+
$container->setParameter('foo', 'ABC %env(json:ARRAY)%');
678708
$container->compile(true);
709+
710+
putenv('ARRAY');
679711
}
680712

681713
/**
@@ -1415,11 +1447,3 @@ public function __construct(A $a)
14151447
{
14161448
}
14171449
}
1418-
1419-
class TestingEnvPlaceholderParameterBag extends EnvPlaceholderParameterBag
1420-
{
1421-
public function get($name)
1422-
{
1423-
return 'env(array)' === strtolower($name) ? array(123) : parent::get($name);
1424-
}
1425-
}

0 commit comments

Comments
 (0)