Skip to content

Commit

Permalink
[DI] Dump the deprecated status
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Sep 24, 2015
1 parent 8f6c21c commit 2f37cb1
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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).
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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));
}
Expand Down
Expand Up @@ -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')
Expand Down
Expand Up @@ -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"];
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down
Expand Up @@ -87,6 +87,7 @@
<service id="decorated" class="stdClass"/>
<service id="decorator_service" class="stdClass" decorates="decorated"/>
<service id="decorator_service_with_name" class="stdClass" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
<service id="deprecated_service" class="stdClass" deprecated="true"/>
<service id="new_factory" class="FactoryClass" public="false">
<property name="foo">bar</property>
</service>
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 2f37cb1

Please sign in to comment.