Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Exception; Chris@0: Chris@14: use Psr\Container\NotFoundExceptionInterface; Chris@14: Chris@0: /** Chris@0: * This exception is thrown when a non-existent service is requested. Chris@0: * Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@14: class ServiceNotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface Chris@0: { Chris@0: private $id; Chris@0: private $sourceId; Chris@14: private $alternatives; Chris@0: Chris@17: public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = [], $msg = null) Chris@0: { Chris@14: if (null !== $msg) { Chris@14: // no-op Chris@14: } elseif (null === $sourceId) { Chris@0: $msg = sprintf('You have requested a non-existent service "%s".', $id); Chris@0: } else { Chris@0: $msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id); Chris@0: } Chris@0: Chris@0: if ($alternatives) { Chris@17: if (1 == \count($alternatives)) { Chris@0: $msg .= ' Did you mean this: "'; Chris@0: } else { Chris@0: $msg .= ' Did you mean one of these: "'; Chris@0: } Chris@0: $msg .= implode('", "', $alternatives).'"?'; Chris@0: } Chris@0: Chris@0: parent::__construct($msg, 0, $previous); Chris@0: Chris@0: $this->id = $id; Chris@0: $this->sourceId = $sourceId; Chris@14: $this->alternatives = $alternatives; Chris@0: } Chris@0: Chris@0: public function getId() Chris@0: { Chris@0: return $this->id; Chris@0: } Chris@0: Chris@0: public function getSourceId() Chris@0: { Chris@0: return $this->sourceId; Chris@0: } Chris@14: Chris@14: public function getAlternatives() Chris@14: { Chris@14: return $this->alternatives; Chris@14: } Chris@0: }