e65da506bb5151b77e51cd771635ad6577276895
[yaffs-website] / vendor / symfony / dependency-injection / Exception / ServiceNotFoundException.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Exception;
13
14 /**
15  * This exception is thrown when a non-existent service is requested.
16  *
17  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
18  */
19 class ServiceNotFoundException extends InvalidArgumentException
20 {
21     private $id;
22     private $sourceId;
23
24     public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array())
25     {
26         if (null === $sourceId) {
27             $msg = sprintf('You have requested a non-existent service "%s".', $id);
28         } else {
29             $msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id);
30         }
31
32         if ($alternatives) {
33             if (1 == count($alternatives)) {
34                 $msg .= ' Did you mean this: "';
35             } else {
36                 $msg .= ' Did you mean one of these: "';
37             }
38             $msg .= implode('", "', $alternatives).'"?';
39         }
40
41         parent::__construct($msg, 0, $previous);
42
43         $this->id = $id;
44         $this->sourceId = $sourceId;
45     }
46
47     public function getId()
48     {
49         return $this->id;
50     }
51
52     public function getSourceId()
53     {
54         return $this->sourceId;
55     }
56 }