[DependencyInjection] enhanced some error messages

This commit is contained in:
Fabien Potencier 2013-02-06 16:37:27 +01:00
parent 4284f19bd3
commit 3053194cd7
2 changed files with 4 additions and 4 deletions

View File

@ -192,14 +192,14 @@ class Container implements IntrospectableContainerInterface
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
{
if (self::SCOPE_PROTOTYPE === $scope) {
throw new InvalidArgumentException('You cannot set services of scope "prototype".');
throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id));
}
$id = strtolower($id);
if (self::SCOPE_CONTAINER !== $scope) {
if (!isset($this->scopedServices[$scope])) {
throw new RuntimeException('You cannot set services of inactive scopes.');
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
}
$this->scopedServices[$scope][$id] = $service;

View File

@ -857,7 +857,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
} elseif (null !== $definition->getFactoryService()) {
$factory = $this->get($parameterBag->resolveValue($definition->getFactoryService()));
} else {
throw new RuntimeException('Cannot create service from factory method without a factory service or factory class.');
throw new RuntimeException(sprintf('Cannot create service "%s" from factory method without a factory service or factory class.', $id));
}
$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
@ -869,7 +869,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) {
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
throw new RuntimeException('You tried to create a service of an inactive scope.');
throw new RuntimeException(sprintf('You tried to create the "%s" service of an inactive scope.', $id));
}
$this->services[$lowerId = strtolower($id)] = $service;