<?php
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
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;
}
}
}
}