Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2313a67

Browse files
committed
[DependencyInjection] Dump the deprecated status
1 parent 43ef709 commit 2313a67

File tree

9 files changed

+58
-0
lines changed

9 files changed

+58
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ private function addService($id, $definition)
584584
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(false), $definition->getFactoryMethod(false));
585585
}
586586

587+
if ($definition->isDeprecated()) {
588+
$return[] = '@deprecated';
589+
}
590+
587591
$scope = $definition->getScope(false);
588592
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
589593
if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
@@ -652,6 +656,10 @@ private function addService($id, $definition)
652656
if ($definition->isSynthetic()) {
653657
$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);
654658
} else {
659+
if ($definition->isDeprecated()) {
660+
$code .= sprintf(" @trigger_error('The service %s has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);\n\n", $id);
661+
}
662+
655663
$code .=
656664
$this->addServiceInclude($id, $definition).
657665
$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 .= sprintf(" 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', '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 [label="deprecated\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: 17 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' => 'getDeprecatedService',
3637
'factory_service' => 'getFactoryServiceService',
3738
'foo' => 'getFooService',
3839
'foo.baz' => 'getFoo_BazService',
@@ -143,6 +144,22 @@ protected function getDecoratorServiceWithNameService()
143144
return $this->services['decorator_service_with_name'] = new \stdClass();
144145
}
145146

147+
/**
148+
* Gets the 'deprecated' 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+
* @deprecated
155+
*/
156+
protected function getDeprecatedService()
157+
{
158+
@trigger_error('The service deprecated has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);
159+
160+
return $this->services['deprecated'] = new \stdClass();
161+
}
162+
146163
/**
147164
* Gets the 'factory_service' service.
148165
*

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

Lines changed: 17 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' => 'getDeprecatedService',
4041
'factory_service' => 'getFactoryServiceService',
4142
'foo' => 'getFooService',
4243
'foo.baz' => 'getFoo_BazService',
@@ -144,6 +145,22 @@ protected function getDecoratorServiceWithNameService()
144145
return $this->services['decorator_service_with_name'] = new \stdClass();
145146
}
146147

148+
/**
149+
* Gets the 'deprecated' 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+
* @deprecated
156+
*/
157+
protected function getDeprecatedService()
158+
{
159+
@trigger_error('The service deprecated has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);
160+
161+
return $this->services['deprecated'] = new \stdClass();
162+
}
163+
147164
/**
148165
* Gets the 'factory_service' service.
149166
*

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" 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:
80+
class: stdClass
81+
deprecated: true
7982
new_factory:
8083
class: FactoryClass
8184
public: false

0 commit comments

Comments
 (0)