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@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@0: class ServiceNotFoundException extends InvalidArgumentException Chris@0: { Chris@0: private $id; Chris@0: private $sourceId; Chris@0: Chris@0: public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array()) Chris@0: { Chris@0: if (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@0: 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@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@0: }