Skip to content

Commit 0f2db57

Browse files
bastnicnicolas-grekas
authored andcommitted
[DependencyInjection] Skip scanning scalar values in compiler passes when not needed
1 parent ceeb4e6 commit 0f2db57

30 files changed

+70
-10
lines changed

Compiler/AbstractRecursivePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
3131
*/
3232
protected $container;
3333
protected $currentId;
34+
protected bool $skipScalars = false;
3435

3536
private bool $processExpressions = false;
3637
private ExpressionLanguage $expressionLanguage;
@@ -77,6 +78,9 @@ protected function processValue(mixed $value, bool $isRoot = false)
7778
{
7879
if (\is_array($value)) {
7980
foreach ($value as $k => $v) {
81+
if ((!$v || \is_scalar($v)) && $this->skipScalars) {
82+
continue;
83+
}
8084
if ($isRoot) {
8185
if ($v->hasTag('container.excluded')) {
8286
continue;

Compiler/AliasDeprecatedPublicServicesPass.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@
1717

1818
final class AliasDeprecatedPublicServicesPass extends AbstractRecursivePass
1919
{
20-
private array $aliases = [];
21-
22-
protected function processValue(mixed $value, bool $isRoot = false): mixed
23-
{
24-
if ($value instanceof Reference && isset($this->aliases[$id = (string) $value])) {
25-
return new Reference($this->aliases[$id], $value->getInvalidBehavior());
26-
}
20+
protected bool $skipScalars = true;
2721

28-
return parent::processValue($value, $isRoot);
29-
}
22+
private array $aliases = [];
3023

3124
public function process(ContainerBuilder $container): void
3225
{
@@ -56,4 +49,13 @@ public function process(ContainerBuilder $container): void
5649

5750
parent::process($container);
5851
}
52+
53+
protected function processValue(mixed $value, bool $isRoot = false): mixed
54+
{
55+
if ($value instanceof Reference && isset($this->aliases[$id = (string) $value])) {
56+
return new Reference($this->aliases[$id], $value->getInvalidBehavior());
57+
}
58+
59+
return parent::processValue($value, $isRoot);
60+
}
5961
}

Compiler/AnalyzeServiceReferencesPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
class AnalyzeServiceReferencesPass extends AbstractRecursivePass
3434
{
35+
protected bool $skipScalars = true;
36+
3537
private ServiceReferenceGraph $graph;
3638
private ?Definition $currentDefinition = null;
3739
private bool $onlyConstructorArguments;

Compiler/AttributeAutoconfigurationPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
final class AttributeAutoconfigurationPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
private $classAttributeConfigurators = [];
2628
private $methodAttributeConfigurators = [];
2729
private $propertyAttributeConfigurators = [];

Compiler/AutowirePass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
class AutowirePass extends AbstractRecursivePass
3737
{
38+
protected bool $skipScalars = true;
39+
3840
private array $types;
3941
private array $ambiguousServiceTypes;
4042
private array $autowiringAliases;

Compiler/AutowireRequiredMethodsPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
class AutowireRequiredMethodsPass extends AbstractRecursivePass
2323
{
24+
protected bool $skipScalars = true;
25+
2426
protected function processValue(mixed $value, bool $isRoot = false): mixed
2527
{
2628
$value = parent::processValue($value, $isRoot);

Compiler/AutowireRequiredPropertiesPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class AutowireRequiredPropertiesPass extends AbstractRecursivePass
2626
{
27+
protected bool $skipScalars = true;
28+
2729
protected function processValue(mixed $value, bool $isRoot = false): mixed
2830
{
2931
$value = parent::processValue($value, $isRoot);

Compiler/CheckArgumentsValidityPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class CheckArgumentsValidityPass extends AbstractRecursivePass
2424
{
25+
protected bool $skipScalars = true;
26+
2527
private bool $throwExceptions;
2628

2729
public function __construct(bool $throwExceptions = true)

Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
2525
{
26+
protected bool $skipScalars = true;
27+
2628
private array $serviceLocatorContextIds = [];
2729

2830
/**

Compiler/CheckReferenceValidityPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class CheckReferenceValidityPass extends AbstractRecursivePass
2727
{
28+
protected bool $skipScalars = true;
29+
2830
protected function processValue(mixed $value, bool $isRoot = false): mixed
2931
{
3032
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {

0 commit comments

Comments
 (0)