From 2f37cb184f3be0d0eb2db583b4cf0b83b9af0047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Fri, 7 Aug 2015 18:08:40 +0200 Subject: [PATCH] [DI] Dump the deprecated status --- .../DependencyInjection/Dumper/PhpDumper.php | 14 +++++++++++++- .../DependencyInjection/Dumper/XmlDumper.php | 3 +++ .../DependencyInjection/Dumper/YamlDumper.php | 4 ++++ .../Tests/Fixtures/containers/container9.php | 4 ++++ .../Tests/Fixtures/graphviz/services9.dot | 1 + .../Tests/Fixtures/php/services9.php | 18 ++++++++++++++++++ .../Tests/Fixtures/php/services9_compiled.php | 18 ++++++++++++++++++ .../Tests/Fixtures/xml/services9.xml | 1 + .../Tests/Fixtures/yaml/services9.yml | 3 +++ 9 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index c1c6f80f70b7..c9b8d0e358f8 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -592,7 +592,15 @@ private function addService($id, $definition) $return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope); } - $return = implode("\n * ", $return); + if ($definition->isDeprecated()) { + if ($return && 0 === strpos($return[count($return) - 1], '@return')) { + $return[] = ''; + } + + $return[] = '@deprecated'; + } + + $return = str_replace("\n * \n", "\n *\n", implode("\n * ", $return)); $doc = ''; if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) { @@ -652,6 +660,10 @@ private function addService($id, $definition) if ($definition->isSynthetic()) { $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); } else { + if ($definition->isDeprecated()) { + $code .= sprintf(" @trigger_error('The service %s has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED);\n\n", $id); + } + $code .= $this->addServiceInclude($id, $definition). $this->addServiceLocalTempVariables($id, $definition). diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index c405c4ce902c..f9fee16d4bec 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -148,6 +148,9 @@ private function addService($definition, $id, \DOMElement $parent) if ($definition->isLazy()) { $service->setAttribute('lazy', 'true'); } + if ($definition->isDeprecated()) { + $service->setAttribute('deprecated', 'true'); + } if (null !== $decorated = $definition->getDecoratedService()) { list($decorated, $renamedId, $priority) = $decorated; $service->setAttribute('decorates', $decorated); diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 3fac53e01c33..987bb6d26cdf 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -104,6 +104,10 @@ private function addService($id, $definition) $code .= sprintf(" synchronized: true\n"); } + if ($definition->isDeprecated()) { + $code .= " deprecated: true\n"; + } + if ($definition->getFactoryClass(false)) { $code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass(false)); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 5d63e348e5de..96f334fdd153 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -89,6 +89,10 @@ ->register('decorator_service_with_name', 'stdClass') ->setDecoratedService('decorated', 'decorated.pif-pouf') ; +$container + ->register('deprecated_service', 'stdClass') + ->setDeprecated(true) +; $container ->register('new_factory', 'FactoryClass') ->setProperty('foo', 'bar') diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index b3b424e2e73c..f6536980aa54 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -17,6 +17,7 @@ digraph sc { node_decorated [label="decorated\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_decorator_service [label="decorator_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_decorator_service_with_name [label="decorator_service_with_name\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_deprecated_service [label="deprecated_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_new_factory [label="new_factory\nFactoryClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_new_factory_service [label="new_factory_service\nFooBarBaz\n", shape=record, fillcolor="#eeeeee", style="filled"]; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 5977c1c6e7a7..1dcc429c3f46 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -33,6 +33,7 @@ public function __construct() 'decorated' => 'getDecoratedService', 'decorator_service' => 'getDecoratorServiceService', 'decorator_service_with_name' => 'getDecoratorServiceWithNameService', + 'deprecated_service' => 'getDeprecatedServiceService', 'factory_service' => 'getFactoryServiceService', 'foo' => 'getFooService', 'foo.baz' => 'getFoo_BazService', @@ -143,6 +144,23 @@ protected function getDecoratorServiceWithNameService() return $this->services['decorator_service_with_name'] = new \stdClass(); } + /** + * Gets the 'deprecated_service' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance. + * + * @deprecated + */ + protected function getDeprecatedServiceService() + { + @trigger_error('The service deprecated_service has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED); + + return $this->services['deprecated_service'] = new \stdClass(); + } + /** * Gets the 'factory_service' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 8c1e71f437a8..447e5454b290 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -37,6 +37,7 @@ public function __construct() 'configured_service' => 'getConfiguredServiceService', 'decorator_service' => 'getDecoratorServiceService', 'decorator_service_with_name' => 'getDecoratorServiceWithNameService', + 'deprecated_service' => 'getDeprecatedServiceService', 'factory_service' => 'getFactoryServiceService', 'foo' => 'getFooService', 'foo.baz' => 'getFoo_BazService', @@ -144,6 +145,23 @@ protected function getDecoratorServiceWithNameService() return $this->services['decorator_service_with_name'] = new \stdClass(); } + /** + * Gets the 'deprecated_service' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance. + * + * @deprecated + */ + protected function getDeprecatedServiceService() + { + @trigger_error('The service deprecated_service has been marked as deprecated. You should stop using it.', E_USER_DEPRECATED); + + return $this->services['deprecated_service'] = new \stdClass(); + } + /** * Gets the 'factory_service' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index f1e6e98efaf6..a9743d2c26d5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -87,6 +87,7 @@ + bar diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index ddb5d3a96abd..1fac54231226 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -76,6 +76,9 @@ services: class: stdClass decorates: decorated decoration_inner_name: decorated.pif-pouf + deprecated_service: + class: stdClass + deprecated: true new_factory: class: FactoryClass public: false