class CheckAliasValidityPass
This pass validates aliases, it provides the following checks:
- An alias which happens to be an interface must resolve to a service implementing this interface. This ensures injecting the aliased interface won't cause a type error at runtime.
Hierarchy
- class \Symfony\Component\DependencyInjection\Compiler\CheckAliasValidityPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
Expanded class hierarchy of CheckAliasValidityPass
File
-
vendor/
symfony/ dependency-injection/ Compiler/ CheckAliasValidityPass.php, line 22
Namespace
Symfony\Component\DependencyInjection\CompilerView source
class CheckAliasValidityPass implements CompilerPassInterface {
public function process(ContainerBuilder $container) : void {
foreach ($container->getAliases() as $id => $alias) {
try {
if (!$container->hasDefinition((string) $alias)) {
continue;
}
$target = $container->getDefinition((string) $alias);
if (null === $target->getClass() || null !== $target->getFactory()) {
continue;
}
$reflection = $container->getReflectionClass($id);
if (null === $reflection || !$reflection->isInterface()) {
continue;
}
$targetReflection = $container->getReflectionClass($target->getClass());
if (null !== $targetReflection && !$targetReflection->implementsInterface($id)) {
throw new RuntimeException(\sprintf('Invalid alias definition: alias "%s" is referencing class "%s" but this class does not implement "%s". Because this alias is an interface, "%s" must implement "%s".', $id, $target->getClass(), $id, $target->getClass(), $id));
}
} catch (\ReflectionException) {
continue;
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CheckAliasValidityPass::process | public | function | You can modify the container here before it is dumped to PHP code. | Overrides CompilerPassInterface::process |