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;
14 use Psr\Container\NotFoundExceptionInterface;
17 * This exception is thrown when a non-existent service is requested.
19 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
21 class ServiceNotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface
25 private $alternatives;
27 public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array(), $msg = null)
31 } elseif (null === $sourceId) {
32 $msg = sprintf('You have requested a non-existent service "%s".', $id);
34 $msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id);
38 if (1 == \count($alternatives)) {
39 $msg .= ' Did you mean this: "';
41 $msg .= ' Did you mean one of these: "';
43 $msg .= implode('", "', $alternatives).'"?';
46 parent::__construct($msg, 0, $previous);
49 $this->sourceId = $sourceId;
50 $this->alternatives = $alternatives;
53 public function getId()
58 public function getSourceId()
60 return $this->sourceId;
63 public function getAlternatives()
65 return $this->alternatives;