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;
15 * This exception is thrown when a non-existent parameter is used.
17 * @author Fabien Potencier <fabien@symfony.com>
19 class ParameterNotFoundException extends InvalidArgumentException
24 private $alternatives;
27 * @param string $key The requested parameter key
28 * @param string $sourceId The service id that references the non-existent parameter
29 * @param string $sourceKey The parameter key that references the non-existent parameter
30 * @param \Exception $previous The previous exception
31 * @param string[] $alternatives Some parameter name alternatives
33 public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array())
36 $this->sourceId = $sourceId;
37 $this->sourceKey = $sourceKey;
38 $this->alternatives = $alternatives;
40 parent::__construct('', 0, $previous);
45 public function updateRepr()
47 if (null !== $this->sourceId) {
48 $this->message = sprintf('The service "%s" has a dependency on a non-existent parameter "%s".', $this->sourceId, $this->key);
49 } elseif (null !== $this->sourceKey) {
50 $this->message = sprintf('The parameter "%s" has a dependency on a non-existent parameter "%s".', $this->sourceKey, $this->key);
52 $this->message = sprintf('You have requested a non-existent parameter "%s".', $this->key);
55 if ($this->alternatives) {
56 if (1 == count($this->alternatives)) {
57 $this->message .= ' Did you mean this: "';
59 $this->message .= ' Did you mean one of these: "';
61 $this->message .= implode('", "', $this->alternatives).'"?';
65 public function getKey()
70 public function getSourceId()
72 return $this->sourceId;
75 public function getSourceKey()
77 return $this->sourceKey;
80 public function setSourceId($sourceId)
82 $this->sourceId = $sourceId;
87 public function setSourceKey($sourceKey)
89 $this->sourceKey = $sourceKey;