Skip to content

Commit

Permalink
merged branch vicb/dic/scopeexc (PR symfony#6846)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the master branch (closes symfony#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 !
  • Loading branch information
fabpot committed Mar 6, 2013
2 parents feaee36 + 9024c07 commit 6b6ccbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= <<<EOF
*
Expand Down Expand Up @@ -484,8 +495,7 @@ protected function get{$name}Service()
EOF;

$scope = $definition->getScope();
if (ContainerInterface::SCOPE_CONTAINER !== $scope && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
$code .= <<<EOF
if (!isset(\$this->scopedServices['$scope'])) {
throw new InactiveScopeException('$id', '$scope');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down

0 comments on commit 6b6ccbb

Please sign in to comment.