Skip to content

Commit cb06d0f

Browse files
Merge branch '3.4' into 4.0
* 3.4: [DI] Fix missing "id" normalization when dumping the container Add entry for `container.dumper.inline_class_loader` param at `UPGRADE-3.4.md` and `UPGRADE-4.0.md`
2 parents 1c826ca + 6ac7b50 commit cb06d0f

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

UPGRADE-4.0.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ DependencyInjection
236236

237237
* The `ExtensionCompilerPass` has been moved to before-optimization passes with priority -1000.
238238

239+
* In 3.4, parameter `container.dumper.inline_class_loader` was introduced. Unless
240+
you're using a custom autoloader, you should enable this parameter. This can
241+
drastically improve DX by reducing the time to load classes when the `DebugClassLoader`
242+
is enabled. If you're using `FrameworkBundle`, this performance improvement will
243+
also impact the "dev" environment:
244+
245+
```yml
246+
parameters:
247+
container.dumper.inline_class_loader: true
248+
```
249+
239250
DoctrineBridge
240251
--------------
241252

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public function process(ContainerBuilder $container)
6464
$this->lazy = false;
6565

6666
foreach ($container->getAliases() as $id => $alias) {
67-
$this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null);
67+
$targetId = $this->getDefinitionId((string) $alias);
68+
$this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null);
6869
}
6970

7071
parent::process($container);
@@ -87,12 +88,13 @@ protected function processValue($value, $isRoot = false)
8788
return $value;
8889
}
8990
if ($value instanceof Reference) {
90-
$targetDefinition = $this->getDefinition((string) $value);
91+
$targetId = $this->getDefinitionId((string) $value);
92+
$targetDefinition = $this->getDefinition($targetId);
9193

9294
$this->graph->connect(
9395
$this->currentId,
9496
$this->currentDefinition,
95-
$this->getDefinitionId((string) $value),
97+
$targetId,
9698
$targetDefinition,
9799
$value,
98100
$this->lazy || ($targetDefinition && $targetDefinition->isLazy()),
@@ -125,10 +127,8 @@ protected function processValue($value, $isRoot = false)
125127
return $value;
126128
}
127129

128-
private function getDefinition(string $id): ?Definition
130+
private function getDefinition(?string $id): ?Definition
129131
{
130-
$id = $this->getDefinitionId($id);
131-
132132
return null === $id ? null : $this->container->getDefinition($id);
133133
}
134134

@@ -156,11 +156,12 @@ private function getExpressionLanguage()
156156
$this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) {
157157
if ('""' === substr_replace($arg, '', 1, -1)) {
158158
$id = stripcslashes(substr($arg, 1, -1));
159+
$id = $this->getDefinitionId($id);
159160

160161
$this->graph->connect(
161162
$this->currentId,
162163
$this->currentDefinition,
163-
$this->getDefinitionId($id),
164+
$id,
164165
$this->getDefinition($id)
165166
);
166167
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ private function processValue($value, $rootLevel = 0, $level = 0)
9090
$value = array_values($value);
9191
}
9292
} elseif ($value instanceof Reference) {
93-
$id = (string) $value;
94-
95-
if ($this->container->has($id)) {
93+
if ($this->container->has($value)) {
9694
return $value;
9795
}
9896
$invalidBehavior = $value->getInvalidBehavior();

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_
592592
*
593593
* @throws BadMethodCallException When this ContainerBuilder is compiled
594594
*/
595-
public function merge(ContainerBuilder $container)
595+
public function merge(self $container)
596596
{
597597
if ($this->isCompiled()) {
598598
throw new BadMethodCallException('Cannot merge on a compiled container.');
@@ -1324,16 +1324,16 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
13241324
$value = $bag->resolveValue($value);
13251325
}
13261326

1327-
if (is_array($value)) {
1327+
if (\is_array($value)) {
13281328
$result = array();
13291329
foreach ($value as $k => $v) {
1330-
$result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs);
1330+
$result[\is_string($k) ? $this->resolveEnvPlaceholders($k, $format, $usedEnvs) : $k] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs);
13311331
}
13321332

13331333
return $result;
13341334
}
13351335

1336-
if (!is_string($value)) {
1336+
if (!\is_string($value) || 38 > \strlen($value)) {
13371337
return $value;
13381338
}
13391339
$envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,11 +1552,12 @@ private function dumpValue($value, bool $interpolate = true): string
15521552
} elseif ($value instanceof Variable) {
15531553
return '$'.$value;
15541554
} elseif ($value instanceof Reference) {
1555-
if (null !== $this->referenceVariables && isset($this->referenceVariables[$id = (string) $value])) {
1555+
$id = (string) $value;
1556+
if (null !== $this->referenceVariables && isset($this->referenceVariables[$id])) {
15561557
return $this->dumpValue($this->referenceVariables[$id], $interpolate);
15571558
}
15581559

1559-
return $this->getServiceCall((string) $value, $value);
1560+
return $this->getServiceCall($id, $value);
15601561
} elseif ($value instanceof Expression) {
15611562
return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container'));
15621563
} elseif ($value instanceof Parameter) {

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ public function resolve()
171171
*/
172172
public function resolveValue($value, array $resolving = array())
173173
{
174-
if (is_array($value)) {
174+
if (\is_array($value)) {
175175
$args = array();
176176
foreach ($value as $k => $v) {
177-
$args[$this->resolveValue($k, $resolving)] = $this->resolveValue($v, $resolving);
177+
$args[\is_string($k) ? $this->resolveValue($k, $resolving) : $k] = $this->resolveValue($v, $resolving);
178178
}
179179

180180
return $args;
181181
}
182182

183-
if (!is_string($value)) {
183+
if (!\is_string($value) || 2 > \strlen($value)) {
184184
return $value;
185185
}
186186

0 commit comments

Comments
 (0)