Skip to content

Commit 7da8fba

Browse files
Merge branch '7.1' into 7.2
* 7.1: fix: ignore missing directory in isVendor() [OptionsResolver] Allow Union/Intersection Types in Resolved Closures Issue #58821: [DependencyInjection] Support interfaces in ContainerBuilder::getReflectionClass(). Dynamically fix compatibility with doctrine/data-fixtures v2 [HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception don't call EntityManager::initializeObject() with scalar values make RelayProxyTrait compatible with relay extension 0.9.0 [Validator] review italian translations Update PR template
2 parents 4f69e6b + 0f4099f commit 7da8fba

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

OptionsResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function setDefault(string $option, mixed $value): static
232232
return $this;
233233
}
234234

235-
if (isset($params[0]) && null !== ($type = $params[0]->getType()) && self::class === $type->getName() && (!isset($params[1]) || (($type = $params[1]->getType()) instanceof \ReflectionNamedType && Options::class === $type->getName()))) {
235+
if (isset($params[0]) && ($type = $params[0]->getType()) instanceof \ReflectionNamedType && self::class === $type->getName() && (!isset($params[1]) || (($type = $params[1]->getType()) instanceof \ReflectionNamedType && Options::class === $type->getName()))) {
236236
// Store closure for later evaluation
237237
$this->nested[$option][] = $value;
238238
$this->defaults[$option] = [];

Tests/OptionsResolverTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,28 @@ public function testClosureWithoutParametersNotInvoked()
159159
$this->assertSame(['foo' => $closure], $this->resolver->resolve());
160160
}
161161

162+
public function testClosureWithUnionTypesNotInvoked()
163+
{
164+
$closure = function (int|string|null $value) {
165+
Assert::fail('Should not be called');
166+
};
167+
168+
$this->resolver->setDefault('foo', $closure);
169+
170+
$this->assertSame(['foo' => $closure], $this->resolver->resolve());
171+
}
172+
173+
public function testClosureWithIntersectionTypesNotInvoked()
174+
{
175+
$closure = function (\Stringable&\JsonSerializable $value) {
176+
Assert::fail('Should not be called');
177+
};
178+
179+
$this->resolver->setDefault('foo', $closure);
180+
181+
$this->assertSame(['foo' => $closure], $this->resolver->resolve());
182+
}
183+
162184
public function testAccessPreviousDefaultValue()
163185
{
164186
// defined by superclass

0 commit comments

Comments
 (0)