From 9024c07d0335749f1db97b2a2b12d5920e1a11ff Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 23 Jan 2013 12:25:17 +0100 Subject: [PATCH] [2.3] [DI] Improve the generated PHPDoc of the dumped PHP container --- .../DependencyInjection/Dumper/PhpDumper.php | 26 +++++++++++++------ .../Tests/Fixtures/php/services9.php | 4 +-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 2a29b01c9005..172d3782f74c 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -441,19 +441,30 @@ private function addService($id, $definition) $this->referenceVariables = array(); $this->variableCount = 0; - $return = ''; + $return = array(); + if ($definition->isSynthetic()) { - $return = sprintf('@throws RuntimeException always since this service is expected to be injected dynamically'); + $return[] = '@throws RuntimeException always since this service is expected to be injected dynamically'; } elseif ($class = $definition->getClass()) { - $return = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'Object' : $class, $class); + $return[] = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'object' : $class, $class); } elseif ($definition->getFactoryClass()) { - $return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod()); + $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod()); } elseif ($definition->getFactoryService()) { - $return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod()); + $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod()); + } + + $scope = $definition->getScope(); + if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) { + if ($return && 0 === strpos($return[count($return) - 1], '@return')) { + $return[] = ''; + } + $return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope); } + $return = implode("\n * ", $return); + $doc = ''; - if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) { + if (ContainerInterface::SCOPE_PROTOTYPE !== $scope) { $doc .= <<getScope(); - if (ContainerInterface::SCOPE_CONTAINER !== $scope && ContainerInterface::SCOPE_PROTOTYPE !== $scope) { + if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) { $code .= <<scopedServices['$scope'])) { throw new InactiveScopeException('$id', '$scope'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 80d24c540dbd..324b77f66c7f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -102,7 +102,7 @@ protected function getFooService() * This service is shared. * This method always returns the same instance of the service. * - * @return Object A %baz_class% instance. + * @return object A %baz_class% instance. */ protected function getFoo_BazService() { @@ -116,7 +116,7 @@ protected function getFoo_BazService() /** * Gets the 'foo_bar' service. * - * @return Object A %foo_class% instance. + * @return object A %foo_class% instance. */ protected function getFooBarService() {