Skip to content

Commit 2f37cb1

Browse files
committed
[DI] Dump the deprecated status
1 parent 8f6c21c commit 2f37cb1

File tree

9 files changed

+65
-1
lines changed

9 files changed

+65
-1
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,15 @@ private function addService($id, $definition)
592592
$return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope);
593593
}
594594

595-
$return = implode("\n * ", $return);
595+
if ($definition->isDeprecated()) {
596+
if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
597+
$return[] = '';
598+
}
599+
600+
$return[] = '@deprecated';
601+
}
602+
603+
$return = str_replace("\n * \n", "\n *\n", implode("\n * ", $return));
596604

597605
$doc = '';
598606
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
@@ -652,6 +660,10 @@ private function addService($id, $definition)
652660
if ($definition->isSynthetic()) {
653661
$code .= sprintf(" throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n }\n", $id);
654662
} else {
663+
if ($definition->isDeprecated()) {
664+
$code .= sprintf(" @trigger_error('The service %s has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);\n\n", $id);
665+
}
666+
655667
$code .=
656668
$this->addServiceInclude($id, $definition).
657669
$this->addServiceLocalTempVariables($id, $definition).

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ private function addService($definition, $id, \DOMElement $parent)
148148
if ($definition->isLazy()) {
149149
$service->setAttribute('lazy', 'true');
150150
}
151+
if ($definition->isDeprecated()) {
152+
$service->setAttribute('deprecated', 'true');
153+
}
151154
if (null !== $decorated = $definition->getDecoratedService()) {
152155
list($decorated, $renamedId, $priority) = $decorated;
153156
$service->setAttribute('decorates', $decorated);

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ private function addService($id, $definition)
104104
$code .= sprintf(" synchronized: true\n");
105105
}
106106

107+
if ($definition->isDeprecated()) {
108+
$code .= " deprecated: true\n";
109+
}
110+
107111
if ($definition->getFactoryClass(false)) {
108112
$code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass(false));
109113
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
->register('decorator_service_with_name', 'stdClass')
9090
->setDecoratedService('decorated', 'decorated.pif-pouf')
9191
;
92+
$container
93+
->register('deprecated_service', 'stdClass')
94+
->setDeprecated(true)
95+
;
9296
$container
9397
->register('new_factory', 'FactoryClass')
9498
->setProperty('foo', 'bar')

src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ digraph sc {
1717
node_decorated [label="decorated\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1818
node_decorator_service [label="decorator_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1919
node_decorator_service_with_name [label="decorator_service_with_name\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
20+
node_deprecated_service [label="deprecated_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
2021
node_new_factory [label="new_factory\nFactoryClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
2122
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
2223
node_new_factory_service [label="new_factory_service\nFooBarBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct()
3333
'decorated' => 'getDecoratedService',
3434
'decorator_service' => 'getDecoratorServiceService',
3535
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
36+
'deprecated_service' => 'getDeprecatedServiceService',
3637
'factory_service' => 'getFactoryServiceService',
3738
'foo' => 'getFooService',
3839
'foo.baz' => 'getFoo_BazService',
@@ -143,6 +144,23 @@ protected function getDecoratorServiceWithNameService()
143144
return $this->services['decorator_service_with_name'] = new \stdClass();
144145
}
145146

147+
/**
148+
* Gets the 'deprecated_service' service.
149+
*
150+
* This service is shared.
151+
* This method always returns the same instance of the service.
152+
*
153+
* @return \stdClass A stdClass instance.
154+
*
155+
* @deprecated
156+
*/
157+
protected function getDeprecatedServiceService()
158+
{
159+
@trigger_error('The service deprecated_service has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);
160+
161+
return $this->services['deprecated_service'] = new \stdClass();
162+
}
163+
146164
/**
147165
* Gets the 'factory_service' service.
148166
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct()
3737
'configured_service' => 'getConfiguredServiceService',
3838
'decorator_service' => 'getDecoratorServiceService',
3939
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
40+
'deprecated_service' => 'getDeprecatedServiceService',
4041
'factory_service' => 'getFactoryServiceService',
4142
'foo' => 'getFooService',
4243
'foo.baz' => 'getFoo_BazService',
@@ -144,6 +145,23 @@ protected function getDecoratorServiceWithNameService()
144145
return $this->services['decorator_service_with_name'] = new \stdClass();
145146
}
146147

148+
/**
149+
* Gets the 'deprecated_service' service.
150+
*
151+
* This service is shared.
152+
* This method always returns the same instance of the service.
153+
*
154+
* @return \stdClass A stdClass instance.
155+
*
156+
* @deprecated
157+
*/
158+
protected function getDeprecatedServiceService()
159+
{
160+
@trigger_error('The service deprecated_service has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);
161+
162+
return $this->services['deprecated_service'] = new \stdClass();
163+
}
164+
147165
/**
148166
* Gets the 'factory_service' service.
149167
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<service id="decorated" class="stdClass"/>
8888
<service id="decorator_service" class="stdClass" decorates="decorated"/>
8989
<service id="decorator_service_with_name" class="stdClass" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
90+
<service id="deprecated_service" class="stdClass" deprecated="true"/>
9091
<service id="new_factory" class="FactoryClass" public="false">
9192
<property name="foo">bar</property>
9293
</service>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ services:
7676
class: stdClass
7777
decorates: decorated
7878
decoration_inner_name: decorated.pif-pouf
79+
deprecated_service:
80+
class: stdClass
81+
deprecated: true
7982
new_factory:
8083
class: FactoryClass
8184
public: false

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