[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Exception/ -> ParameterNotFoundException.php (source)

   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 parameter is used.
  16   *
  17   * @author Fabien Potencier <fabien@symfony.com>
  18   */
  19  class ParameterNotFoundException extends InvalidArgumentException
  20  {
  21      private $key;
  22      private $sourceId;
  23      private $sourceKey;
  24      private $alternatives;
  25  
  26      /**
  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
  32       */
  33      public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array())
  34      {
  35          $this->key = $key;
  36          $this->sourceId = $sourceId;
  37          $this->sourceKey = $sourceKey;
  38          $this->alternatives = $alternatives;
  39  
  40          parent::__construct('', 0, $previous);
  41  
  42          $this->updateRepr();
  43      }
  44  
  45      public function updateRepr()
  46      {
  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);
  51          } else {
  52              $this->message = sprintf('You have requested a non-existent parameter "%s".', $this->key);
  53          }
  54  
  55          if ($this->alternatives) {
  56              if (1 == \count($this->alternatives)) {
  57                  $this->message .= ' Did you mean this: "';
  58              } else {
  59                  $this->message .= ' Did you mean one of these: "';
  60              }
  61              $this->message .= implode('", "', $this->alternatives).'"?';
  62          }
  63      }
  64  
  65      public function getKey()
  66      {
  67          return $this->key;
  68      }
  69  
  70      public function getSourceId()
  71      {
  72          return $this->sourceId;
  73      }
  74  
  75      public function getSourceKey()
  76      {
  77          return $this->sourceKey;
  78      }
  79  
  80      public function setSourceId($sourceId)
  81      {
  82          $this->sourceId = $sourceId;
  83  
  84          $this->updateRepr();
  85      }
  86  
  87      public function setSourceKey($sourceKey)
  88      {
  89          $this->sourceKey = $sourceKey;
  90  
  91          $this->updateRepr();
  92      }
  93  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1