Skip to content

Commit

Permalink
[DependencyInjection] enhanced some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 6, 2013
1 parent 4284f19 commit 3053194
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -192,14 +192,14 @@ public function setParameter($name, $value)
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;
Expand Down
Expand Up @@ -857,7 +857,7 @@ private function createService(Definition $definition, $id)
} 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);
Expand All @@ -869,7 +869,7 @@ private function createService(Definition $definition, $id)

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;
Expand Down

0 comments on commit 3053194

Please sign in to comment.