[Form] Added an exception for invalid type services

Before the introduction of the FormRegistry, the getName() method was
never used for types registered through the DI container. The
FormRegistry now uses the getName() method and missconfigured services
will trigger a notice.
This was reported in FriendsOfSymfony/FOSCommentBundle#234
This commit is contained in:
Christophe Coevoet 2012-07-14 13:04:03 +02:00
parent cf41bf8776
commit 6489a65960
1 changed files with 7 additions and 1 deletions

View File

@ -43,7 +43,13 @@ class DependencyInjectionExtension implements FormExtensionInterface
throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name));
}
return $this->container->get($this->typeServiceIds[$name]);
$type = $this->container->get($this->typeServiceIds[$name]);
if ($type->getName() !== $name) {
throw new \InvalidArgumentException(sprintf('The type name specified for the service %s does not match the actual name', $this->typeServiceIds[$name]));
}
return $type;
}
public function hasType($name)