4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Exception;
15 * This exception is thrown when a non-existent service is requested.
17 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
19 class ServiceNotFoundException extends InvalidArgumentException
24 public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array())
26 if (null === $sourceId) {
27 $msg = sprintf('You have requested a non-existent service "%s".', $id);
29 $msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id);
33 if (1 == count($alternatives)) {
34 $msg .= ' Did you mean this: "';
36 $msg .= ' Did you mean one of these: "';
38 $msg .= implode('", "', $alternatives).'"?';
41 parent::__construct($msg, 0, $previous);
44 $this->sourceId = $sourceId;
47 public function getId()
52 public function getSourceId()
54 return $this->sourceId;