merged branch fabpot/better-exception-messages (PR #6994)

This PR was merged into the 2.2 branch.

Commits
-------

3053194 [DependencyInjection] enhanced some error messages

Discussion
----------

[DependencyInjection] enhanced some error messages

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a
This commit is contained in:
Fabien Potencier 2013-02-07 14:24:42 +01:00
commit 3d43bcc540
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;