Skip to content

Commit

Permalink
Merge branch '5.4' into 6.2
Browse files Browse the repository at this point in the history
* 5.4:
  [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s
  [Intl] fix test
  [Intl] Use VarExporter::export() in PhpBundleWriter
  Use triggering class to generate baseline for deprecation messages from DebugClassLoader
  [Security] Fix false-string handling in RememberMeAuthenticator
  [CssSelector] Tests on Xpath translator will always pass
  [Serializer] Fix Normalizer not utilizing converted name for index variadic param
  [DepdencyInjection] Fix costly logic when checking errored definitions
  fix children cond
  [DoctrineBridge] Load refreshed user proxy
  [DependencyInjection] Don't ignore attributes on the actual decorator
  [FrameworkBundle] Prevent `cache:clear` to lose files on subsequent runs
  • Loading branch information
nicolas-grekas committed Jul 12, 2023
2 parents 462409e + cc80120 commit 3885c83
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
68 changes: 27 additions & 41 deletions Compiler/DefinitionErrorExceptionPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
class DefinitionErrorExceptionPass extends AbstractRecursivePass
{
private $erroredDefinitions = [];
private $targetReferences = [];
private $sourceReferences = [];

/**
Expand All @@ -37,45 +36,10 @@ public function process(ContainerBuilder $container)
try {
parent::process($container);

if (!$this->erroredDefinitions) {
return;
}

$runtimeIds = [];

foreach ($this->sourceReferences as $id => $sourceIds) {
foreach ($sourceIds as $sourceId => $isRuntime) {
if (!$isRuntime) {
continue 2;
}
}

unset($this->erroredDefinitions[$id]);
$runtimeIds[$id] = $id;
}

if (!$this->erroredDefinitions) {
return;
}

foreach ($this->targetReferences as $id => $targetIds) {
if (!isset($this->sourceReferences[$id]) || isset($runtimeIds[$id]) || isset($this->erroredDefinitions[$id])) {
continue;
}
foreach ($this->targetReferences[$id] as $targetId => $isRuntime) {
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
if ($sourceId !== $targetId) {
$this->sourceReferences[$targetId][$sourceId] = false;
$this->targetReferences[$sourceId][$targetId] = false;
}
}
}

unset($this->sourceReferences[$id]);
}
$visitedIds = [];

foreach ($this->erroredDefinitions as $id => $definition) {
if (isset($this->sourceReferences[$id])) {
if ($this->isErrorForRuntime($id, $visitedIds)) {
continue;
}

Expand All @@ -86,7 +50,6 @@ public function process(ContainerBuilder $container)
}
} finally {
$this->erroredDefinitions = [];
$this->targetReferences = [];
$this->sourceReferences = [];
}
}
Expand All @@ -102,10 +65,8 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
$this->sourceReferences[$targetId][$this->currentId] ??= true;
$this->targetReferences[$this->currentId][$targetId] ??= true;
} else {
$this->sourceReferences[$targetId][$this->currentId] = false;
$this->targetReferences[$this->currentId][$targetId] = false;
}

return $value;
Expand All @@ -119,4 +80,29 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed

return parent::processValue($value);
}

private function isErrorForRuntime(string $id, array &$visitedIds): bool
{
if (!isset($this->sourceReferences[$id])) {
return false;
}

if (isset($visitedIds[$id])) {
return $visitedIds[$id];
}

$visitedIds[$id] = true;

foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
if ($visitedIds[$sourceId] ?? $visitedIds[$sourceId] = $this->isErrorForRuntime($sourceId, $visitedIds)) {
continue;
}

if (!$isRuntime) {
return false;
}
}

return true;
}
}
7 changes: 4 additions & 3 deletions Compiler/ResolveInstanceofConditionalsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
$instanceofDef->setAbstract(true)->setParent($parent ?: '.abstract.instanceof.'.$id);
$parent = '.instanceof.'.$interface.'.'.$key.'.'.$id;
$container->setDefinition($parent, $instanceofDef);
$instanceofTags[] = $instanceofDef->getTags();
$instanceofTags[] = [$interface, $instanceofDef->getTags()];
$instanceofBindings = $instanceofDef->getBindings() + $instanceofBindings;

foreach ($instanceofDef->getMethodCalls() as $methodCall) {
Expand Down Expand Up @@ -123,8 +123,9 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
// Don't add tags to service decorators
$i = \count($instanceofTags);
while (0 <= --$i) {
foreach ($instanceofTags[$i] as $k => $v) {
if (null === $definition->getDecoratedService() || \in_array($k, $tagsToKeep, true)) {
[$interface, $tags] = $instanceofTags[$i];
foreach ($tags as $k => $v) {
if (null === $definition->getDecoratedService() || $interface === $definition->getClass() || \in_array($k, $tagsToKeep, true)) {
foreach ($v as $v) {
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
continue;
Expand Down
10 changes: 9 additions & 1 deletion Tests/Compiler/ResolveInstanceofConditionalsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,26 @@ public function testDecoratorsAreNotAutomaticallyTagged()
$decorator->setDecoratedService('decorated');
$decorator->setInstanceofConditionals([
parent::class => (new ChildDefinition(''))->addTag('tag'),
self::class => (new ChildDefinition(''))->addTag('other-tag'),
]);
$decorator->setAutoconfigured(true);
$decorator->addTag('manual');

$container->registerForAutoconfiguration(parent::class)
->addTag('tag')
;
$container->registerForAutoconfiguration(self::class)
->addTag('last-tag')
;

(new ResolveInstanceofConditionalsPass())->process($container);
(new ResolveChildDefinitionsPass())->process($container);

$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
$this->assertSame([
'manual' => [[]],
'other-tag' => [[]],
'last-tag' => [[]],
], $container->getDefinition('decorator')->getTags());
}

public function testDecoratorsKeepBehaviorDescribingTags()
Expand Down

0 comments on commit 3885c83

Please sign in to comment.