Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit461b475

Browse files
committed
Replace plus operator with array_merge
1 parentb52c0e5 commit461b475

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,12 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
300300
};
301301

302302
if ($checkAttributes) {
303-
$autowire =$parameter->getAttributes(Autowire::class, \ReflectionAttribute::IS_INSTANCEOF);
304-
$lazy =$parameter->getAttributes(Lazy::class, \ReflectionAttribute::IS_INSTANCEOF);
303+
$attributes =\array_merge($parameter->getAttributes(Autowire::class, \ReflectionAttribute::IS_INSTANCEOF),$parameter->getAttributes(Lazy::class, \ReflectionAttribute::IS_INSTANCEOF));
305304

306-
if (\count($autowire) >0 &&\count($lazy) >0) {
307-
thrownewAutowiringFailedException($this->currentId,"'Lazy' and'Autowire' attributes cannot be used onthesame argument.");
305+
if (1 <\count($attributes)) {
306+
thrownewAutowiringFailedException($this->currentId,'Using both attributes #[Lazy] and#[Autowire] on an argument is not allowed; usethe"lazy" parameter of #[Autowire] instead.');
308307
}
309308

310-
$attributes =$autowire +$lazy;
311309
foreach ($attributesas$attribute) {
312310
$attribute =$attribute->newInstance();
313311
$invalidBehavior =$parameter->allowsNull() ? ContainerInterface::NULL_ON_INVALID_REFERENCE : ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE;

‎src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function accept(Definition $definition): bool
4343

4444
publicfunctionprocessClass(ContainerBuilder$container,\ReflectionClass$class):void
4545
{
46-
$attributes =$class->getAttributes(Autoconfigure::class, \ReflectionAttribute::IS_INSTANCEOF) +$class->getAttributes(Lazy::class, \ReflectionAttribute::IS_INSTANCEOF);
46+
$attributes =array_merge($class->getAttributes(Autoconfigure::class, \ReflectionAttribute::IS_INSTANCEOF),$class->getAttributes(Lazy::class, \ReflectionAttribute::IS_INSTANCEOF));
4747
foreach ($attributesas$attribute) {
4848
self::registerForAutoconfiguration($container,$class,$attribute);
4949
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ public function testLazyNotCompatibleWithAutowire()
13901390
try {
13911391
(newAutowirePass())->process($container);
13921392
}catch (AutowiringFailedException$e) {
1393-
$this->assertSame("'Lazy' and'Autowire' attributes cannot be used onthesame argument.",$e->getMessage());
1393+
$this->assertSame('Using both attributes #[Lazy] and#[Autowire] on an argument is not allowed; usethe"lazy" parameter of #[Autowire] instead.',$e->getMessage());
13941394
}
13951395
}
13961396
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
useSymfony\Component\DependencyInjection\Reference;
2020
useSymfony\Component\DependencyInjection\Tests\Fixtures\AutoconfigureAttributed;
2121
useSymfony\Component\DependencyInjection\Tests\Fixtures\AutoconfiguredInterface;
22+
useSymfony\Component\DependencyInjection\Tests\Fixtures\LazyAutoconfigured;
2223
useSymfony\Component\DependencyInjection\Tests\Fixtures\LazyLoaded;
2324
useSymfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
2425
useSymfony\Component\DependencyInjection\Tests\Fixtures\StaticConstructorAutoconfigure;
@@ -119,4 +120,18 @@ public function testLazyServiceAttribute()
119120
;
120121
$this->assertEquals([LazyLoaded::class =>$expected],$container->getAutoconfiguredInstanceof());
121122
}
123+
124+
publicfunctiontestLazyAutoconfigureServiceAttribute()
125+
{
126+
$container =newContainerBuilder();
127+
$container->register('foo', LazyAutoconfigured::class)
128+
->setAutoconfigured(true);
129+
130+
(newRegisterAutoconfigureAttributesPass())->process($container);
131+
132+
$expected = (newChildDefinition(''))
133+
->setLazy(true)
134+
;
135+
$this->assertEquals([LazyAutoconfigured::class =>$expected],$container->getAutoconfiguredInstanceof());
136+
}
122137
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespaceSymfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
useSymfony\Component\DependencyInjection\Attribute\Autoconfigure;
6+
useSymfony\Component\DependencyInjection\Attribute\Lazy;
7+
8+
#[Lazy, Autoconfigure(lazy:true)]
9+
class LazyAutoconfigured
10+
{
11+
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp