Drupal investigation

ParameterNotFoundException.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Exception;
  11. /**
  12. * This exception is thrown when a non-existent parameter is used.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class ParameterNotFoundException extends InvalidArgumentException
  17. {
  18. private $key;
  19. private $sourceId;
  20. private $sourceKey;
  21. private $alternatives;
  22. /**
  23. * @param string $key The requested parameter key
  24. * @param string $sourceId The service id that references the non-existent parameter
  25. * @param string $sourceKey The parameter key that references the non-existent parameter
  26. * @param \Exception $previous The previous exception
  27. * @param string[] $alternatives Some parameter name alternatives
  28. */
  29. public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array())
  30. {
  31. $this->key = $key;
  32. $this->sourceId = $sourceId;
  33. $this->sourceKey = $sourceKey;
  34. $this->alternatives = $alternatives;
  35. parent::__construct('', 0, $previous);
  36. $this->updateRepr();
  37. }
  38. public function updateRepr()
  39. {
  40. if (null !== $this->sourceId) {
  41. $this->message = sprintf('The service "%s" has a dependency on a non-existent parameter "%s".', $this->sourceId, $this->key);
  42. } elseif (null !== $this->sourceKey) {
  43. $this->message = sprintf('The parameter "%s" has a dependency on a non-existent parameter "%s".', $this->sourceKey, $this->key);
  44. } else {
  45. $this->message = sprintf('You have requested a non-existent parameter "%s".', $this->key);
  46. }
  47. if ($this->alternatives) {
  48. if (1 == count($this->alternatives)) {
  49. $this->message .= ' Did you mean this: "';
  50. } else {
  51. $this->message .= ' Did you mean one of these: "';
  52. }
  53. $this->message .= implode('", "', $this->alternatives).'"?';
  54. }
  55. }
  56. public function getKey()
  57. {
  58. return $this->key;
  59. }
  60. public function getSourceId()
  61. {
  62. return $this->sourceId;
  63. }
  64. public function getSourceKey()
  65. {
  66. return $this->sourceKey;
  67. }
  68. public function setSourceId($sourceId)
  69. {
  70. $this->sourceId = $sourceId;
  71. $this->updateRepr();
  72. }
  73. public function setSourceKey($sourceKey)
  74. {
  75. $this->sourceKey = $sourceKey;
  76. $this->updateRepr();
  77. }
  78. }