Skip to content

Commit 728ae8f

Browse files
Merge branch '5.4' into 6.4
* 5.4: initialize RedisAdapter cursor to 0 do not skip tests from data providers ensure compatibility with Twig 3.15 [Mime] fix encoding issue with UTF-8 addresses containing doubles spaces fix translation file syntax [Validator] [Choice] Fix callback option if not array returned [DependencyInjection] Fix linting factories implemented via __callStatic [DependencyInjection] Fix replacing abstract arguments with bindings Minor fixes around parse_url() checks Ensure compatibility with mongodb v2 Add missing translations for Turkish (tr)
2 parents 0484e9c + 0c199da commit 728ae8f

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

Compiler/AbstractRecursivePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ protected function getReflectionMethod(Definition $definition, string $method):
219219
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
220220
}
221221

222+
if ($r->hasMethod('__callStatic') && ($r = $r->getMethod('__callStatic')) && $r->isPublic()) {
223+
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
224+
}
225+
222226
throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
223227
}
224228

Compiler/ResolveBindingsPass.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1415
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1516
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1617
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
@@ -182,10 +183,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
182183
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
183184
$names[$key] = $parameter->name;
184185

185-
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
186+
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key] && !$arguments[$key] instanceof AbstractArgument) {
186187
continue;
187188
}
188-
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
189+
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name] && !$arguments[$parameter->name] instanceof AbstractArgument) {
189190
continue;
190191
}
191192
if (
@@ -230,7 +231,9 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
230231

231232
foreach ($names as $key => $name) {
232233
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
233-
$arguments[$key] = $arguments[$name];
234+
if (!array_key_exists($key, $arguments)) {
235+
$arguments[$key] = $arguments[$name];
236+
}
234237
unset($arguments[$name]);
235238
}
236239
}

EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
304304
throw new RuntimeException(sprintf('Invalid URL in env var "%s".', $name));
305305
}
306306
if (!isset($params['scheme'], $params['host'])) {
307-
throw new RuntimeException(sprintf('Invalid URL env var "%s": schema and host expected, "%s" given.', $name, $env));
307+
throw new RuntimeException(sprintf('Invalid URL in env var "%s": scheme and host expected.', $name));
308308
}
309309
$params += [
310310
'port' => null,

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,17 @@ public function testCallableClass()
985985
$this->addToAssertionCount(1);
986986
}
987987

988+
public function testStaticCallableClass()
989+
{
990+
$container = new ContainerBuilder();
991+
$container->register('foo', StaticCallableClass::class)
992+
->setFactory([StaticCallableClass::class, 'staticMethodCall']);
993+
994+
(new CheckTypeDeclarationsPass())->process($container);
995+
996+
$this->addToAssertionCount(1);
997+
}
998+
988999
public function testIgnoreDefinitionFactoryArgument()
9891000
{
9901001
$container = new ContainerBuilder();
@@ -1020,3 +1031,10 @@ public function __call($name, $arguments)
10201031
{
10211032
}
10221033
}
1034+
1035+
class StaticCallableClass
1036+
{
1037+
public static function __callStatic($name, $arguments)
1038+
{
1039+
}
1040+
}

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1617
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1718
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1819
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
@@ -277,11 +278,23 @@ public function testBindWithNamedArgs()
277278
$definition->setArguments(['c' => 'C', 'hostName' => 'H']);
278279
$definition->setBindings($bindings);
279280

280-
$container->register('foo', CaseSensitiveClass::class);
281-
282281
$pass = new ResolveBindingsPass();
283282
$pass->process($container);
284283

285284
$this->assertEquals(['C', 'K', 'H'], $definition->getArguments());
286285
}
286+
287+
public function testAbstractArg()
288+
{
289+
$container = new ContainerBuilder();
290+
291+
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
292+
$definition->setArguments([new AbstractArgument(), 'apiKey' => new AbstractArgument()]);
293+
$definition->setBindings(['$c' => new BoundArgument('C'), '$apiKey' => new BoundArgument('K')]);
294+
295+
$pass = new ResolveBindingsPass();
296+
$pass->process($container);
297+
298+
$this->assertEquals(['C', 'K'], $definition->getArguments());
299+
}
287300
}

0 commit comments

Comments
 (0)