merged branch gimler/compiler_replace_alias_exception_pimp (PR #6757)

This PR was merged into the master branch.

Commits
-------

27d9385 wrap the exception to get information about where the exception comes from

Discussion
----------

Wrap the exception to get more information about where the exception comes from

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

This patch add more information about where the exception comes from.
Actual you get one exception
```
The service definition "fos_user.registration.form" does not exist.
```

After the patch you get
```
[2/2] Try to replace alias "fos_user.registration.form" with "hwi_oauth.registration.form".
[1/2] The service definition "fos_user.registration.form" does not exist.
```

---------------------------------------------------------------------------

by gimler at 2013-01-16T08:38:36Z

@fabpot i have changed the wording

---------------------------------------------------------------------------

by stloyd at 2013-01-16T08:40:53Z

@gimler Maybe you add [test too](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php) ? Anyway 👍
This commit is contained in:
Fabien Potencier 2013-01-16 09:43:59 +01:00
commit f3e905c44b

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
/**
@ -30,6 +31,8 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
* Process the Container to replace aliases with service definitions.
*
* @param ContainerBuilder $container
*
* @throws InvalidArgumentException if the service definition does not exist
*/
public function process(ContainerBuilder $container)
{
@ -39,7 +42,11 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
foreach ($container->getAliases() as $id => $alias) {
$aliasId = (string) $alias;
$definition = $container->getDefinition($aliasId);
try {
$definition = $container->getDefinition($aliasId);
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null, $e);
}
if ($definition->isPublic()) {
continue;