8000 [DI] Throw when a service name or an alias contains dynamic values (prevent an infinite loop) by dunglas · Pull Request #24673 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[DI] Throw when a service name or an alias contains dynamic values (prevent an infinite loop) #24673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\EnvParameterException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

/**
Expand Down Expand Up @@ -75,6 +76,18 @@ public function process(ContainerBuilder $container)
}
}
}

$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
if (null !== $usedEnvs) {
throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.');
}
}

foreach ($container->getAliases() as $id => $alias) {
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
if (null !== $usedEnvs) {
throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.');
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ public function testInvalidTags()
$this->process($container);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
*/
public function testDynamicServiceName()
{
$container = new ContainerBuilder();
$env = $container->getParameterBag()->get('env(BAR)');
$container->register("foo.$env", 'class');

$this->process($container);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
*/
public function testDynamicAliasName()
{
$container = new ContainerBuilder();
$env = $container->getParameterBag()->get('env(BAR)');
$container->setAlias("foo.$env", 'class');

$this->process($container);
}

protected function process(ContainerBuilder $container)
{
$pass = new CheckDefinitionValidityPass();
Expand Down
0