Skip to content

Commit 1f12f9d

Browse files
Merge branch '6.4' into 7.1
* 6.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 [Notifier] Improve Telegrams markdown escaping [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 c4600c5 + 728ae8f commit 1f12f9d

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
@@ -213,6 +213,10 @@ protected function getReflectionMethod(Definition $definition, string $method):
213213
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
214214
}
215215

216+
if ($r->hasMethod('__callStatic') && ($r = $r->getMethod('__callStatic')) && $r->isPublic()) {
217+
return new \ReflectionMethod(static function (...$arguments) {}, '__invoke');
218+
}
219+
216220
throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
217221
}
218222

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;
@@ -179,10 +180,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
179180
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
180181
$names[$key] = $parameter->name;
181182

182-
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
183+
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key] && !$arguments[$key] instanceof AbstractArgument) {
183184
continue;
184185
}
185-
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
186+
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name] && !$arguments[$parameter->name] instanceof AbstractArgument) {
186187
continue;
187188
}
188189
if (
@@ -227,7 +228,9 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
227228

228229
foreach ($names as $key => $name) {
229230
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
230-
$arguments[$key] = $arguments[$name];
231+
if (!array_key_exists($key, $arguments)) {
232+
$arguments[$key] = $arguments[$name];
233+
}
231234
unset($arguments[$name]);
232235
}
233236
}

EnvVarProcessor.php

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

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,17 @@ public function testCallableClass()
982982
$this->addToAssertionCount(1);
983983
}
984984

985+
public function testStaticCallableClass()
986+
{
987+
$container = new ContainerBuilder();
988+
$container->register('foo', StaticCallableClass::class)
989+
->setFactory([StaticCallableClass::class, 'staticMethodCall']);
990+
991+
(new CheckTypeDeclarationsPass())->process($container);
992+
993+
$this->addToAssertionCount(1);
994+
}
995+
985996
public function testIgnoreDefinitionFactoryArgument()
986997
{
987998
$container = new ContainerBuilder();
@@ -1017,3 +1028,10 @@ public function __call($name, $arguments)
10171028
{
10181029
}
10191030
}
1031+
1032+
class StaticCallableClass
1033+
{
1034+
public static function __callStatic($name, $arguments)
1035+
{
1036+
}
1037+
}

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1516
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1617
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1718
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
@@ -256,11 +257,23 @@ public function testBindWithNamedArgs()
256257
$definition->setArguments(['c' => 'C', 'hostName' => 'H']);
257258
$definition->setBindings($bindings);
258259

259-
$container->register('foo', CaseSensitiveClass::class);
260-
261260
$pass = new ResolveBindingsPass();
262261
$pass->process($container);
263262

264263
$this->assertEquals(['C', 'K', 'H'], $definition->getArguments());
265264
}
265+
266+
public function testAbstractArg()
267+
{
268+
$container = new ContainerBuilder();
269+
270+
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
271+
$definition->setArguments([new AbstractArgument(), 'apiKey' => new AbstractArgument()]);
272+
$definition->setBindings(['$c' => new BoundArgument('C'), '$apiKey' => new BoundArgument('K')]);
273+
274+
$pass = new ResolveBindingsPass();
275+
$pass->process($container);
276+
277+
$this->assertEquals(['C', 'K'], $definition->getArguments());
278+
}
266279
}

0 commit comments

Comments
 (0)