Skip to content

Commit b6729d9

Browse files
authored
Revert "feat: allow non-contextual attributes to have an after callback (#5…" (#52281)
This reverts commit 45592e6.
1 parent 9e781c2 commit b6729d9

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

src/Illuminate/Container/Container.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,12 @@ protected function fireAfterResolvingCallbacks($abstract, $object)
13661366
protected function fireAfterResolvingAttributeCallbacks(array $attributes, $object)
13671367
{
13681368
foreach ($attributes as $attribute) {
1369-
if (method_exists($instance = $attribute->newInstance(), 'after')) {
1370-
$instance->after($instance, $object, $this);
1369+
if (is_a($attribute->getName(), ContextualAttribute::class, true)) {
1370+
$instance = $attribute->newInstance();
1371+
1372+
if (method_exists($instance, 'after')) {
1373+
$instance->after($instance, $object, $this);
1374+
}
13711375
}
13721376

13731377
$callbacks = $this->getCallbacksForType(

tests/Container/AfterResolvingAttributeCallbackTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ class AfterResolvingAttributeCallbackTest extends TestCase
1111
public function testCallbackIsCalledAfterDependencyResolutionWithAttribute()
1212
{
1313
$container = new Container();
14-
$stack = [];
1514

16-
$container->afterResolvingAttribute(ContainerTestOnTenant::class, function (ContainerTestOnTenant $attribute, HasTenantImpl $hasTenantImpl, Container $container) use (&$stack) {
15+
$container->afterResolvingAttribute(ContainerTestOnTenant::class, function (ContainerTestOnTenant $attribute, HasTenantImpl $hasTenantImpl, Container $container) {
1716
$hasTenantImpl->onTenant($attribute->tenant);
18-
$stack[] = $attribute->tenant;
1917
});
2018

2119
$hasTenantA = $container->make(ContainerTestHasTenantImplPropertyWithTenantA::class);
2220
$this->assertInstanceOf(HasTenantImpl::class, $hasTenantA->property);
2321
$this->assertEquals(Tenant::TenantA, $hasTenantA->property->tenant);
24-
$this->assertContains(Tenant::TenantA, $stack);
2522

2623
$hasTenantB = $container->make(ContainerTestHasTenantImplPropertyWithTenantB::class);
2724
$this->assertInstanceOf(HasTenantImpl::class, $hasTenantB->property);
2825
$this->assertEquals(Tenant::TenantB, $hasTenantB->property->tenant);
29-
$this->assertContains(Tenant::TenantB, $stack);
3026
}
3127

3228
public function testCallbackIsCalledAfterClassWithAttributeIsResolved()
@@ -61,19 +57,6 @@ public function testCallbackIsCalledAfterClassWithConstructorAndAttributeIsResol
6157
$this->assertInstanceOf(ContainerTestHasSelfConfiguringAttributeAndConstructor::class, $instance);
6258
$this->assertEquals('the-right-value', $instance->value);
6359
}
64-
65-
public function testAfterCallbackIsCalled()
66-
{
67-
$container = new Container();
68-
69-
$hasTenantA = $container->make(ContainerTestHasTenantImplPropertyWithTenantA::class);
70-
$this->assertInstanceOf(HasTenantImpl::class, $hasTenantA->property);
71-
$this->assertEquals(Tenant::TenantA, $hasTenantA->property->tenant);
72-
73-
$hasTenantB = $container->make(ContainerTestHasTenantImplPropertyWithTenantB::class);
74-
$this->assertInstanceOf(HasTenantImpl::class, $hasTenantB->property);
75-
$this->assertEquals(Tenant::TenantB, $hasTenantB->property->tenant);
76-
}
7760
}
7861

7962
#[Attribute(Attribute::TARGET_PARAMETER)]
@@ -83,11 +66,6 @@ public function __construct(
8366
public readonly Tenant $tenant
8467
) {
8568
}
86-
87-
public function after(self $attribute, HasTenantImpl $class, Container $container): void
88-
{
89-
$class->onTenant($attribute->tenant);
90-
}
9169
}
9270

9371
enum Tenant

0 commit comments

Comments
 (0)