diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 4eb1a0ed2a..4a6d02b374 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -236,6 +236,17 @@ DependencyInjection * The `ExtensionCompilerPass` has been moved to before-optimization passes with priority -1000. + * In 3.4, parameter `container.dumper.inline_class_loader` was introduced. Unless + you're using a custom autoloader, you should enable this parameter. This can + drastically improve DX by reducing the time to load classes when the `DebugClassLoader` + is enabled. If you're using `FrameworkBundle`, this performance improvement will + also impact the "dev" environment: + + ```yml + parameters: + container.dumper.inline_class_loader: true + ``` + DoctrineBridge -------------- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index 95a1e5a928..a67d9b044f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -64,7 +64,8 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements Repe $this->lazy = false; foreach ($container->getAliases() as $id => $alias) { - $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null); + $targetId = $this->getDefinitionId((string) $alias); + $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null); } parent::process($container); @@ -87,12 +88,13 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements Repe return $value; } if ($value instanceof Reference) { - $targetDefinition = $this->getDefinition((string) $value); + $targetId = $this->getDefinitionId((string) $value); + $targetDefinition = $this->getDefinition($targetId); $this->graph->connect( $this->currentId, $this->currentDefinition, - $this->getDefinitionId((string) $value), + $targetId, $targetDefinition, $value, $this->lazy || ($targetDefinition && $targetDefinition->isLazy()), @@ -125,10 +127,8 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements Repe return $value; } - private function getDefinition(string $id): ?Definition + private function getDefinition(?string $id): ?Definition { - $id = $this->getDefinitionId($id); - return null === $id ? null : $this->container->getDefinition($id); } @@ -156,11 +156,12 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements Repe $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { if ('""' === substr_replace($arg, '', 1, -1)) { $id = stripcslashes(substr($arg, 1, -1)); + $id = $this->getDefinitionId($id); $this->graph->connect( $this->currentId, $this->currentDefinition, - $this->getDefinitionId($id), + $id, $this->getDefinition($id) ); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php index cb05f90143..d60272b276 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php @@ -90,9 +90,7 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface $value = array_values($value); } } elseif ($value instanceof Reference) { - $id = (string) $value; - - if ($this->container->has($id)) { + if ($this->container->has($value)) { return $value; } $invalidBehavior = $value->getInvalidBehavior(); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 8d7011c1b0..1d49b2af18 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -592,7 +592,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface * * @throws BadMethodCallException When this ContainerBuilder is compiled */ - public function merge(ContainerBuilder $container) + public function merge(self $container) { if ($this->isCompiled()) { throw new BadMethodCallException('Cannot merge on a compiled container.'); @@ -1324,16 +1324,16 @@ class ContainerBuilder extends Container implements TaggedContainerInterface $value = $bag->resolveValue($value); } - if (is_array($value)) { + if (\is_array($value)) { $result = array(); foreach ($value as $k => $v) { - $result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs); + $result[\is_string($k) ? $this->resolveEnvPlaceholders($k, $format, $usedEnvs) : $k] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs); } return $result; } - if (!is_string($value)) { + if (!\is_string($value) || 38 > \strlen($value)) { return $value; } $envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders; diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 4e475fe0b8..55537643d3 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1552,11 +1552,12 @@ EOF; } elseif ($value instanceof Variable) { return '$'.$value; } elseif ($value instanceof Reference) { - if (null !== $this->referenceVariables && isset($this->referenceVariables[$id = (string) $value])) { + $id = (string) $value; + if (null !== $this->referenceVariables && isset($this->referenceVariables[$id])) { return $this->dumpValue($this->referenceVariables[$id], $interpolate); } - return $this->getServiceCall((string) $value, $value); + return $this->getServiceCall($id, $value); } elseif ($value instanceof Expression) { return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container')); } elseif ($value instanceof Parameter) { diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php index da6a21b837..dc5a4be292 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php @@ -171,16 +171,16 @@ class ParameterBag implements ParameterBagInterface */ public function resolveValue($value, array $resolving = array()) { - if (is_array($value)) { + if (\is_array($value)) { $args = array(); foreach ($value as $k => $v) { - $args[$this->resolveValue($k, $resolving)] = $this->resolveValue($v, $resolving); + $args[\is_string($k) ? $this->resolveValue($k, $resolving) : $k] = $this->resolveValue($v, $resolving); } return $args; } - if (!is_string($value)) { + if (!\is_string($value) || 2 > \strlen($value)) { return $value; }