Skip to content

Commit 83f4e9c

Browse files
committed
[DI] Support deprecated definitions in decorators
1 parent 0b3d0a0 commit 83f4e9c

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
127127
if ($parentDef->getFactoryService(false)) {
128128
$def->setFactoryService($parentDef->getFactoryService(false));
129129
}
130+
if ($parentDef->isDeprecated()) {
131+
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
132+
}
130133
$def->setFactory($parentDef->getFactory());
131134
$def->setConfigurator($parentDef->getConfigurator());
132135
$def->setFile($parentDef->getFile());
@@ -162,6 +165,9 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
162165
if (isset($changes['lazy'])) {
163166
$def->setLazy($definition->isLazy());
164167
}
168+
if (isset($changes['deprecated'])) {
169+
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
170+
}
165171
if (isset($changes['decorated_service'])) {
166172
$decoratedService = $definition->getDecoratedService();
167173
if (null === $decoratedService) {

src/Symfony/Component/DependencyInjection/DefinitionDecorator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ public function setDecoratedService($id, $renamedId = null, $priority = 0)
180180
return parent::setDecoratedService($id, $renamedId, $priority);
181181
}
182182

183+
/**
184+
* {@inheritdoc}
185+
*/
186+
public function setDeprecated($boolean = true, $template = null)
187+
{
188+
$this->changes['deprecated'] = true;
189+
190+
return parent::setDeprecated($boolean, $template);
191+
}
192+
183193
/**
184194
* Gets an argument to pass to the service constructor/factory method.
185195
*

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,36 @@ public function testSetDecoratedServiceOnServiceHasParent()
244244
$this->assertEquals(array('foo', 'foo_inner', 0), $container->getDefinition('child1')->getDecoratedService());
245245
}
246246

247+
public function testDecoratedServiceCopiesDeprecatedStatusFromParent()
248+
{
249+
$container = new ContainerBuilder();
250+
$container->register('deprecated_parent')
251+
->setDeprecated(true)
252+
;
253+
254+
$container->setDefinition('decorated_deprecated_parent', new DefinitionDecorator('deprecated_parent'));
255+
256+
$this->process($container);
257+
258+
$this->assertTrue($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
259+
}
260+
261+
public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
262+
{
263+
$container = new ContainerBuilder();
264+
$container->register('deprecated_parent')
265+
->setDeprecated(true)
266+
;
267+
268+
$container->setDefinition('decorated_deprecated_parent', new DefinitionDecorator('deprecated_parent'))
269+
->setDeprecated(false)
270+
;
271+
272+
$this->process($container);
273+
274+
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
275+
}
276+
247277
protected function process(ContainerBuilder $container)
248278
{
249279
$pass = new ResolveDefinitionTemplatesPass();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy