8000 Merge branch '3.3' into 3.4 · symfony/symfony@f897542 · GitHub
[go: up one dir, main page]

Skip to content

Commit f897542

Browse files
Merge branch '3.3' into 3.4
* 3.3: [DI] Dont resolve envs in service ids Add tests proving it can load annotated files [WebProfilerBundle] Reset letter-spacing in toolbar Prefer overflow-wrap to word-break [Routing] Fix "config-file-relative" annotation loader resources Make search in debug:container command case-insensitive `resolveEnvPlaceholders` will return a mixed value
2 parents 6cb2707 + ca5b15a commit f897542

File tree

14 files changed

+319
-41
lines changed

14 files changed

+319
-41
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ private function findServiceIdsContaining(ContainerBuilder $builder, $name)
220220
{
221221
$serviceIds = $builder->getServiceIds();
222222
$foundServiceIds = array();
223-
$name = strtolower($name);
224223
foreach ($serviceIds as $serviceId) {
225-
if (false === strpos($serviceId, $name)) {
224+
if (false === stripos($serviceId, $name)) {
226225
continue;
227226
}
228227
$foundServiceIds[] = $serviceId;

src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ table th { background-color: #E0E0E0; font-weight: bold; text-align: left; }
2222
.hidden { display: none; }
2323
.nowrap { white-space: nowrap; }
2424
.newline { display: block; }
25-
.break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; }
25+
.break-long-words { word-wrap: break-word; overflow-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; min-width: 0; }
2626
.text-small { font-size: 12px !important; }
2727
.text-muted { color: #999; }
2828
.text-bold { font-weight: bold; }

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
-moz-box-sizing: content-box;
4141
box-sizing: content-box;
4242
vertical-align: baseline;
43+
letter-spacing: normal;
4344
}
4445

4546
.sf-toolbarreset {

src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ public function process(ContainerBuilder $container)
7777
}
7878
}
7979

80-
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
81-
if (null !== $usedEnvs) {
82-
throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.');
80+
if ($definition->isPublic() && !$definition->isPrivate()) {
81+
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
82+
if (null !== $usedEnvs) {
83+
throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.');
84+
}
8385
}
8486
}
8587

8688
foreach ($container->getAliases() as $id => $alias) {
87-
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
88-
if (null !== $usedEnvs) {
89-
throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.');
89+
if ($alias->isPublic() && !$alias->isPrivate()) {
90+
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
91+
if (null !== $usedEnvs) {
92+
throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.');
93+
}
9094
}
9195
}
9296
}

src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function processValue($value, $isRoot = false)
3535

3636
$value = parent::processValue($value, $isRoot);
3737

38-
if ($value && is_array($value)) {
38+
if ($value && is_array($value) && !$isRoot) {
3939
$value = array_combine($this->container->resolveEnvPlaceholders(array_keys($value), true), $value);
4040
}
4141

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ public function getAutoconfiguredInstanceof()
13411341
* true to resolve to the actual values of the referenced env vars
13421342
* @param array &$usedEnvs Env vars found while resolving are added to this array
13431343
*
1344-
* @return string The string with env parameters resolved
1344+
* @return mixed The value with env parameters resolved if a string or an array is passed
13451345
*/
13461346
public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null)
13471347
{

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function dump(array $options = array())
192192
sort($ids);
193193
$c = "<?php\n\nreturn array(\n";
194194
foreach ($ids as $id) {
195-
$c .= ' '.$this->export($id)." => true,\n";
195+
$c .= ' '.$this->doExport($id)." => true,\n";
196196
}
197197
$files['removed-ids.php'] = $c .= ");\n";
198198
}
@@ -894,6 +894,7 @@ private function generateServiceFiles()
894894
private function addNewInstance(Definition $definition, $return, $instantiation, $id)
895895
{
896896
$class = $this->dumpValue($definition->getClass());
897+
$return = ' '.$return.$instantiation;
897898

898899
$arguments = array();
899900
foreach ($definition->getArguments() as $value) {
@@ -909,7 +910,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
909910

910911
F438 if ($callable[0] instanceof Reference
911912
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) {
912-
return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
913+
return $return.sprintf("%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
913914
}
914915

915916
$class = $this->dumpValue($callable[0]);
@@ -919,24 +920,24 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
919920
throw new RuntimeException(sprintf('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id));
920921
}
921922

922-
return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
923+
return $return.sprintf("%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
923924
}
924925

925926
if (0 === strpos($class, 'new ')) {
926-
return sprintf(" $return{$instantiation}(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
927+
return $return.sprintf("(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
927928
}
928929

929-
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
930+
return $return.sprintf("call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
930931
}
931932

932-
return sprintf(" $return{$instantiation}%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : '');
933+
return $return.sprintf("%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : '');
933934
}
934935

935936
if (false !== strpos($class, '$')) {
936-
return sprintf(" \$class = %s;\n\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
937+
return sprintf(" \$class = %s;\n\n%snew \$class(%s);\n", $class, $return, implode(', ', $arguments));
937938
}
938939

939-
return sprintf(" $return{$instantiation}new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments));
940+
return $return.sprintf("new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments));
940941
}
941942

942943
/**
@@ -1087,7 +1088,7 @@ private function addNormalizedIds()
10871088
ksort($normalizedIds);
10881089
foreach ($normalizedIds as $id => $normalizedId) {
10891090
if ($this->container->has($normalizedId)) {
1090-
$code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n";
1091+
$code .= ' '.$this->doExport($id).' => '.$this->doExport($normalizedId).",\n";
10911092
}
10921093
}
10931094

@@ -1106,7 +1107,7 @@ private function addSyntheticIds()
11061107
ksort($definitions);
11071108
foreach ($definitions as $id => $definition) {
11081109
if ($definition->isSynthetic() && 'service_container' !== $id) {
1109-
$code .= ' '.$this->export($id)." => true,\n";
1110+
$code .= ' '.$this->doExport($id)." => true,\n";
11101111
}
11111112
}
11121113

@@ -1130,7 +1131,7 @@ private function addRemovedIds()
11301131
$ids = array_keys($ids);
11311132
sort($ids);
11321133
foreach ($ids as $id) {
1133-
$code .= ' '.$this->export($id)." => true,\n";
1134+
$code .= ' '.$this->doExport($id)." => true,\n";
11341135
}
11351136

11361137
$code = "array(\n{$code} )";
@@ -1158,7 +1159,7 @@ private function addMethodMap()
11581159
ksort($definitions);
11591160
foreach ($definitions as $id => $definition) {
11601161
if (!$definition->isSynthetic() && (!$this->asFiles || !$definition->isShared() || $this->isHotPath($definition))) {
1161-
$code .= ' '.$this->export($id).' => '.$this->export($this->generateMethodName($id)).",\n";
1162+
$code .= ' '.$this->doExport($id).' => '.$this->doExport($this->generateMethodName($id)).",\n";
11621163
}
11631164
}
11641165

@@ -1177,7 +1178,7 @@ private function addFileMap()
11771178
ksort($definitions);
11781179
foreach ($definitions as $id => $definition) {
11791180
if (!$definition->isSynthetic() && $definition->isShared() && !$this->isHotPath($definition)) {
1180-
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this< 10000 /span>->export($id), $this->generateMethodName($id));
1181+
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
11811182
}
11821183
}
11831184

@@ -1197,15 +1198,15 @@ private function addPrivateServices()
11971198
ksort($aliases);
11981199
foreach ($aliases as $id => $alias) {
11991200
if ($alias->isPrivate()) {
1200-
$code .= ' '.$this->export($id)." => true,\n";
1201+
$code .= ' '.$this->doExport($id)." => true,\n";
12011202
}
12021203
}
12031204

12041205
$definitions = $this->container->getDefinitions();
12051206
ksort($definitions);
12061207
foreach ($definitions as $id => $definition) {
12071208
if (!$definition->isPublic()) {
1208-
$code .= ' '.$this->export($id)." => true,\n";
1209+
$code .= ' '.$this->doExport($id)." => true,\n";
12091210
}
12101211
}
12111212

@@ -1238,7 +1239,7 @@ private function addAliases()
12381239
while (isset($aliases[$id])) {
12391240
$id = (string) $aliases[$id];
12401241
}
1241-
$code .= ' '.$this->export($alias).' => '.$this->export($id).",\n";
1242+
$code .= ' '.$this->doExport($alias).' => '.$this->doExport($id).",\n";
12421243
}
12431244

12441245
return $code." );\n";
@@ -2037,9 +2038,9 @@ private function isHotPath(Definition $definition)
20372038
private function export($value)
20382039
{
20392040
if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
2040-
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1])).'.' : '';
2041+
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
20412042
$suffix = $matches[0][1] + strlen($matches[0][0]);
2042-
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix)) : '';
2043+
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
20432044
$dirname = '__DIR__';
20442045
$offset = 1 + $this->targetDirMaxMatches - count($matches);
20452046

@@ -2054,10 +2055,10 @@ private function export($value)
20542055
return $dirname;
20552056
}
20562057

2057-
return $this->doExport($value);
2058+
return $this->doExport($value, true);
20582059
}
20592060

2060-
private function doExport($value)
2061+
private function doExport($value, $resolveEnv = false)
20612062
{
20622063
if (is_string($value) && false !== strpos($value, "\n")) {
20632064
$cleanParts = explode("\n", $value);
@@ -2067,7 +2068,7 @@ private function doExport($value)
20672068
$export = var_export($value, true);
20682069
}
20692070

2070-
if ("'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) {
2071+
if ($resolveEnv && "'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) {
20712072
$export = $resolvedExport;
20722073
if (".''" === substr($export, -3)) {
20732074
$export = substr($export, 0, -3);

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php

Lines changed: 16 additions & 4 deletions
93
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,39 @@ public function testInvalidTags()
7979
/**
8080
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
8181
*/
82-
public function testDynamicServiceName()
82+
public function testDynamicPublicServiceName()
8383
{
8484
$container = new ContainerBuilder();
8585
$env = $container->getParameterBag()->get('env(BAR)');
86-
$container->register("foo.$env", 'class');
86+
$container->register("foo.$env", 'class')->setPublic(true);
8787

8888
$this->process($container);
8989
}
9090

9191
/**
9292
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
93
*/
94-
public function testDynamicAliasName()
94+
public function testDynamicPublicAliasName()
9595
{
9696
$container = new ContainerBuilder();
9797
$env = $container->getParameterBag()->get('env(BAR)');
98-
$container->setAlias("foo.$env", 'class');
98+
$container->setAlias("foo.$env", 'class')->setPublic(true);
9999

100100
$this->process($container);
101101
}
102102

103+
public function testDynamicPrivateName()
104+
{
105+
$container = new ContainerBuilder();
106+
$env = $container->getParameterBag()->get('env(BAR)');
107+
$container->register("foo.$env", 'class');
108+
$container->setAlias("bar.$env", 'class');
109+
110+
$this->process($container);
111+
112+
$this->addToAssertionCount(1);
113+
}
114+
103115
protected function process(ContainerBuilder $container)
104116
{
105117
$pass = new CheckDefinitionValidityPass();

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,29 @@ public function testEnvAreNullable()
716716
$this->assertNull($container->get('foo')->fake);
717717
}
718718

719+
public function testEnvInId()
720+
{
721+
$container = include __DIR__.'/Fixtures/containers/container_env_in_id.php';
722+
$container->compile(true);
723+
724+
$expected = array(
725+
'service_container',
726+
'foo',
727+
'bar',
728+
'bar_%env(BAR)%',
729+
);
730+
$this->assertSame($expected, array_keys($container->getDefinitions()));
731+
732+
$expected = array(
733+
PsrContainerInterface::class => true,
734+
ContainerInterface::class => true,
735+
'baz_%env(BAR)%' => true,
736+
);
737+
$this->assertSame($expected, $container->getRemovedIds());
738+
739+
$this->assertSame(array('baz_bar'), array_keys($container->getDefinition('foo')->getArgument(1)));
740+
}
741+
719742
/**
720743
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException
721744
* @expectedExceptionMessage Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)").

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ public function testDumpAutowireData()
326326
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump());
327327
}
328328

329+
public function testEnvInId()
330+
{
331+
$container = include self::$fixturesPath.'/containers/container_env_in_id.php';
332+
$container->compile();
333+
$dumper = new PhpDumper($container);
334+
335+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_env_in_id.php', $dumper->dump());
336+
}
337+
329338
public function testEnvParameter()
330339
{
331340
$rand = mt_rand();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerBuilder;
4+
use Symfony\Component\DependencyInjection\Definition;
5+
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
6+
use Symfony\Component\DependencyInjection\Reference;
7+
8+
$container = new ContainerBuilder();
9+
10+
$container->setParameter('env(BAR)', 'bar');
11+
12+
$container->register('foo', 'stdClass')->setPublic(true)
13+
->addArgument(new Reference('bar_%env(BAR)%'))
14+
->addArgument(array('baz_%env(BAR)%' => new Reference('baz_%env(BAR)%')));
15+
16+
$container->register('bar', 'stdClass')->setPublic(true)
17+
->addArgument(new Reference('bar_%env(BAR)%'));
18+
19+
$container->register('bar_%env(BAR)%', 'stdClass')->setPublic(false);
20+
$container->register('baz_%env(BAR)%', 'stdClass')->setPublic(false);
21+
22+
return $container;

0 commit comments

Comments
 (0)
0