Skip to content

Commit 64c1dfd

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Translation] Fix merge [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set Update Redis version to 6.2.8 [Contracts] Fix setting $container before calling parent::setContainer in ServiceSubscriberTrait [Messenger][Cache] fixed CallbackInterface support in async expiration handler do not drop embed label classes
2 parents 72030ac + 4cafe62 commit 64c1dfd

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

Service/ServiceSubscriberTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ public static function getSubscribedServices(): array
6666
#[Required]
6767
public function setContainer(ContainerInterface $container): ?ContainerInterface
6868
{
69-
$this->container = $container;
70-
69+
$ret = null;
7170
if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
72-
return parent::setContainer($container);
71+
$ret = parent::setContainer($container);
7372
}
7473

75-
return null;
74+
$this->container = $container;
75+
76+
return $ret;
7677
}
7778
}

Tests/Service/ServiceSubscriberTraitTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public function testParentNotCalledIfNoParent()
6868
$this->assertNull($service->setContainer($container));
6969
$this->assertSame([], $service::getSubscribedServices());
7070
}
71+
72+
public function testSetContainerCalledFirstOnParent()
73+
{
74+
$container1 = new class([]) implements ContainerInterface {
75+
use ServiceLocatorTrait;
76+
};
77+
$container2 = clone $container1;
78+
79+
$testService = new TestService2();
80+
$this->assertNull($testService->setContainer($container1));
81+
$this->assertSame($container1, $testService->setContainer($container2));
82+
}
7183
}
7284

7385
class ParentTestService
@@ -126,3 +138,22 @@ public static function __callStatic($method, $args)
126138
class Service3
127139
{
128140
}
141+
142+
class ParentTestService2
143+
{
144+
/** @var ContainerInterface */
145+
protected $container;
146+
147+
public function setContainer(ContainerInterface $container)
148+
{
149+
$previous = $this->container;
150+
$this->container = $container;
151+
152+
return $previous;
153+
}
154+
}
155+
156+
class TestService2 extends ParentTestService2 implements ServiceSubscriberInterface
157+
{
158+
use ServiceSubscriberTrait;
159+
}

0 commit comments

Comments
 (0)