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

Skip to content

Commit 6b6ccbb

Browse files
committed
merged branch vicb/dic/scopeexc (PR #6846)
This PR was squashed before being merged into the master branch (closes #6846). Commits ------- 9024c07 [2.3] [DI] Improve the generated PHPDoc of the dumped PHP container Discussion ---------- [2.3] [DI] Improve the generated PHPDoc of the dumped PHP container By adding "@throws InactiveScopeException" where applicable --------------------------------------------------------------------------- by vicb at 2013-01-23T11:51:11Z thanks @stof > Native types should be lowercase Never say that to @fabpot :) --------------------------------------------------------------------------- by stof at 2013-01-23T12:10:56Z @vicb he has an exception for ``Boolean`` (and explained why) but the reason cannot be applied to ``object`` --------------------------------------------------------------------------- by vicb at 2013-01-23T13:01:55Z @stof all "Object"s should be covered now. Yeah I know he has such a mannerism ! --------------------------------------------------------------------------- by stof at 2013-01-23T19:01:07Z @vicb none of the dumping tests modified ? this looks weird --------------------------------------------------------------------------- by stof at 2013-01-23T19:06:06Z hmm, travis is indeed agreeing with me... --------------------------------------------------------------------------- by vicb at 2013-01-23T20:07:16Z I'll fix that tomorrow --------------------------------------------------------------------------- by vicb at 2013-01-24T08:37:55Z travis I hope you like it !
2 parents feaee36 + 9024c07 commit 6b6ccbb

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,30 @@ private function addService($id, $definition)
441441
$this->referenceVariables = array();
442442
$this->variableCount = 0;
443443

444-
$return = '';
444+
$return = array();
445+
445446
if ($definition->isSynthetic()) {
446-
$return = sprintf('@throws RuntimeException always since this service is expected to be injected dynamically');
447+
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
447448
} elseif ($class = $definition->getClass()) {
448-
$return = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'Object' : $class, $class);
449+
$return[] = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'object' : $class, $class);
449450
} elseif ($definition->getFactoryClass()) {
450-
$return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
451+
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
451452
} elseif ($definition->getFactoryService()) {
452-
$return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
453+
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
454+
}
455+
456+
$scope = $definition->getScope();
457+
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
458+
if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
459+
$return[] = '';
460+
}
461+
$return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope);
453462
}
454463

464+
$return = implode("\n * ", $return);
465+
455466
$doc = '';
456-
if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) {
467+
if (ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
457468
$doc .= <<<EOF
458469
459470
*
@@ -484,8 +495,7 @@ protected function get{$name}Service()
484495
485496
EOF;
486497

487-
$scope = $definition->getScope();
488-
if (ContainerInterface::SCOPE_CONTAINER !== $scope && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
498+
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
489499
$code .= <<<EOF
490500
if (!isset(\$this->scopedServices['$scope'])) {
491501
throw new InactiveScopeException('$id', '$scope');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function getFooService()
102102
* This service is shared.
103103
* This method always returns the same instance of the service.
104104
*
105-
* @return Object A %baz_class% instance.
105+
* @return object A %baz_class% instance.
106106
*/
107107
protected function getFoo_BazService()
108108
{
@@ -116,7 +116,7 @@ protected function getFoo_BazService()
116116
/**
117117
* Gets the 'foo_bar' service.
118118
*
119-
* @return Object A %foo_class% instance.
119+
* @return object A %foo_class% instance.
120120
*/
121121
protected function getFooBarService()
122122
{

0 commit comments

Comments
 (0)