Skip to content

Commit 6d5c652

Browse files
Merge branch '7.1' into 7.2
* 7.1: 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 [DependencyInjection] Fix parsing nested AutowireInline attributes Minor fixes around parse_url() checks Ensure compatibility with mongodb v2 Add missing translations for Turkish (tr)
2 parents 550f5a5 + 1f12f9d commit 6d5c652

8 files changed

+92
-18
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/ResolveAutowireInlineAttributesPass.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ResolveAutowireInlineAttributesPass extends AbstractRecursivePass
2828
{
2929
protected bool $skipScalars = true;
3030

31+
private int $counter;
32+
3133
protected function processValue(mixed $value, bool $isRoot = false): mixed
3234
{
3335
$value = parent::processValue($value, $isRoot);
@@ -36,6 +38,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
3638
return $value;
3739
}
3840

41+
if ($isRoot) {
42+
$this->counter = 0;
43+
}
44+
3945
$isChildDefinition = $value instanceof ChildDefinition;
4046

4147
try {
@@ -92,10 +98,14 @@ private function registerAutowireInlineAttributes(\ReflectionFunctionAbstract $m
9298
}
9399

94100
if (\array_key_exists('$'.$parameter->name, $arguments) || (\array_key_exists($index, $arguments) && '' !== $arguments[$index])) {
101+
$attribute = \array_key_exists('$'.$parameter->name, $arguments) ? $arguments['$'.$parameter->name] : $arguments[$index];
102+
if (!$attribute instanceof AutowireInline) {
103+
continue;
104+
}
105+
} elseif (!$attribute = $parameter->getAttributes(AutowireInline::class, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
95106
continue;
96-
}
97-
if (!$attribute = $parameter->getAttributes(AutowireInline::class, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
98-
continue;
107+
} else {
108+
$attribute = $attribute->newInstance();
99109
}
100110

101111
$type = ProxyHelper::exportType($parameter, true);
@@ -104,25 +114,18 @@ private function registerAutowireInlineAttributes(\ReflectionFunctionAbstract $m
104114
continue;
105115
}
106116

107-
$attribute = $attribute->newInstance();
108117
$definition = $attribute->buildDefinition($attribute->value, $type, $parameter);
109118

110119
$paramResolverContainer->setDefinition('.autowire_inline', $definition);
111120
(new ResolveParameterPlaceHoldersPass(false, false))->process($paramResolverContainer);
112121

113-
$id = '.autowire_inline.'.ContainerBuilder::hash([$this->currentId, $method->class ?? null, $method->name, (string) $parameter]);
122+
$id = '.autowire_inline.'.$this->currentId.'.'.++$this->counter;
114123

115124
$this->container->setDefinition($id, $definition);
116125
$arguments[$isChildDefinition ? '$'.$parameter->name : $index] = new Reference($id);
117126

118127
if ($definition->isAutowired()) {
119-
$currentId = $this->currentId;
120-
try {
121-
$this->currentId = $id;
122-
$this->processValue($definition, true);
123-
} finally {
124-
$this->currentId = $currentId;
125-
}
128+
$this->processValue($definition);
126129
}
127130
}
128131

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/ResolveAutowireInlineAttributesPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
1919
use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass;
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\Reference;
2123

2224
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
2325

@@ -66,4 +68,20 @@ public function testChildDefinition()
6668

6769
$this->assertSame(['$inlined'], array_keys($container->getDefinition('autowire_inline1')->getArguments()));
6870
}
71+
72+
public function testNestedAttribute()
73+
{
74+
$container = new ContainerBuilder();
75+
76+
$container->register('nested_autowire_inline', NestedAutowireInlineAttribute::class)
77+
->setAutowired(true);
78+
79+
(new ResolveAutowireInlineAttributesPass())->process($container);
80+
81+
$this->assertEquals([new Reference('.autowire_inline.nested_autowire_inline.1')], $container->getDefinition('nested_autowire_inline')->getArguments());
82+
$this->assertSame(AutowireInlineAttributesBar::class, $container->getDefinition('.autowire_inline.nested_autowire_inline.1')->getClass());
83+
84+
$this->assertEquals([new Reference('.autowire_inline.nested_autowire_inline.2'), 'testString'], $container->getDefinition('.autowire_inline.nested_autowire_inline.1')->getArguments());
85+
$this->assertSame(Foo::class, $container->getDefinition('.autowire_inline.nested_autowire_inline.2')->getClass());
86+
}
6987
}

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
}

Tests/Fixtures/includes/autowiring_classes_80.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,18 @@ public function __construct(
198198
) {
199199
}
200200
}
201+
202+
class NestedAutowireInlineAttribute
203+
{
204+
public function __construct(
205+
#[AutowireInline(
206+
AutowireInlineAttributesBar::class,
207+
arguments: [
208+
new AutowireInline(Foo::class),
209+
'testString',
210+
],
211+
)]
212+
public AutowireInlineAttributesBar $inlined,
213+
) {
214+
}
215+
}

0 commit comments

Comments
 (0)