Skip to content

Commit bf6ae96

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: Fix LICENSE CI check fixes retrieving multiple values for extra fields [String] Remove duplicates in fold maps fail with a meaningful error when a needed package is missing [DependencyInjection] Fix combinatory explosion when autowiring union and intersection types Update license years (last time) [Tests] New iteration of removing `$this` occurrences in future static data providers
2 parents 2a6dd14 + 0b9af76 commit bf6ae96

File tree

2 files changed

+24
-41
lines changed

2 files changed

+24
-41
lines changed

Compiler/AutowirePass.php

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class AutowirePass extends AbstractRecursivePass
5050
private ?int $decoratedMethodIndex = null;
5151
private ?int $decoratedMethodArgumentIndex = null;
5252
private ?self $typesClone = null;
53-
private array $combinedAliases;
5453

5554
public function __construct(bool $throwOnAutowireException = true)
5655
{
@@ -63,8 +62,6 @@ public function __construct(bool $throwOnAutowireException = true)
6362

6463
public function process(ContainerBuilder $container)
6564
{
66-
$this->populateCombinedAliases($container);
67-
6865
try {
6966
$this->typesClone = clone $this;
7067
parent::process($container);
@@ -77,7 +74,6 @@ public function process(ContainerBuilder $container)
7774
$this->decoratedMethodIndex = null;
7875
$this->decoratedMethodArgumentIndex = null;
7976
$this->typesClone = null;
80-
$this->combinedAliases = [];
8177
}
8278
}
8379

@@ -401,12 +397,12 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
401397
return new TypedReference($alias, $type, $reference->getInvalidBehavior());
402398
}
403399

404-
if (null !== ($alias = $this->combinedAliases[$alias] ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
400+
if (null !== ($alias = $this->getCombinedAlias($type, $name) ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
405401
return new TypedReference($alias, $type, $reference->getInvalidBehavior());
406402
}
407403

408404
if ($this->container->has($name) && !$this->container->findDefinition($name)->isAbstract()) {
409-
foreach ($this->container->getAliases() + $this->combinedAliases as $id => $alias) {
405+
foreach ($this->container->getAliases() as $id => $alias) {
410406
if ($name === (string) $alias && str_starts_with($id, $type.' $')) {
411407
return new TypedReference($name, $type, $reference->getInvalidBehavior());
412408
}
@@ -418,7 +414,7 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
418414
return new TypedReference($type, $type, $reference->getInvalidBehavior());
419415
}
420416

421-
if (null !== ($alias = $this->combinedAliases[$type] ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
417+
if (null !== ($alias = $this->getCombinedAlias($type) ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
422418
return new TypedReference($alias, $type, $reference->getInvalidBehavior());
423419
}
424420

@@ -624,44 +620,31 @@ private function populateAutowiringAlias(string $id): void
624620
}
625621
}
626622

627-
private function populateCombinedAliases(ContainerBuilder $container): void
623+
private function getCombinedAlias(string $type, string $name = null): ?string
628624
{
629-
$this->combinedAliases = [];
630-
$reverseAliases = [];
631-
632-
foreach ($container->getAliases() as $id => $alias) {
633-
if (!preg_match('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))^((?&V)(?:\\\\(?&V))*+)(?: \$((?&V)))?$/', $id, $m)) {
634-
continue;
635-
}
636-
637-
$type = $m[2];
638-
$name = $m[3] ?? '';
639-
$reverseAliases[(string) $alias][$name][] = $type;
625+
if (str_contains($type, '&')) {
626+
$types = explode('&', $type);
627+
} elseif (str_contains($type, '|')) {
628+
$types = explode('|', $type);
629+
} else {
630+
return null;
640631
}
641632

642-
foreach ($reverseAliases as $alias => $names) {
643-
foreach ($names as $name => $types) {
644-
if (2 > $count = \count($types)) {
645-
continue;
646-
}
647-
sort($types);
648-
$i = 1 << $count;
649-
650-
// compute the powerset of the list of types
651-
while ($i--) {
652-
$set = [];
653-
for ($j = 0; $j < $count; ++$j) {
654-
if ($i & (1 << $j)) {
655-
$set[] = $types[$j];
656-
}
657-
}
633+
$alias = null;
634+
$suffix = $name ? ' $'.$name : '';
658635

659-
if (2 <= \count($set)) {
660-
$this->combinedAliases[implode('&', $set).('' === $name ? '' : ' $'.$name)] = $alias;
661-
$this->combinedAliases[implode('|', $set).('' === $name ? '' : ' $'.$name)] = $alias;
662-
}
663-
}
636+
foreach ($types as $type) {
637+
if (!$this->container->hasAlias($type.$suffix)) {
638+
return null;
639+
}
640+
641+
if (null === $alias) {
642+
$alias = (string) $this->container->getAlias($type.$suffix);
643+
} elseif ((string) $this->container->getAlias($type.$suffix) !== $alias) {
644+
return null;
664645
}
665646
}
647+
648+
return $alias;
666649
}
667650
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2023 Fabien Potencier
1+
Copyright (c) 2004-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)