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