You are here

public function MarkdownUnexpectedValueException::__construct in Markdown 8.2

Creates a new instance of the exception.

Parameters

mixed $value: The unexpected value.

string|int $key: Known key, if value is in an array or Traversable object.

array $parents: Know parents, if value is nested inside an array or Traversable object.

\Throwable $previous: A previous exception, if rethrown.

string[] $templates: An indexed array of templates to be used depending on whether there is known hierarchy (i.e. if $key and/or $parents were provided):

  • (string) No hierarchy known. Only a single variable (%s) will be replaced with the unexpected value.
  • (string) Hierarchy known. Two variables (%s) will be passed, the first is the unexpected value and the second is the full path in dot' notation, constructed from passed $key and $parents.

File

src/Exception/MarkdownUnexpectedValueException.php, line 48

Class

MarkdownUnexpectedValueException

Namespace

Drupal\markdown\Exception

Code

public function __construct($value, $key = NULL, array $parents = [], $previous = NULL, array $templates = []) {
  $this->value = $value;
  $this->key = $key;
  $this->parents = $parents;
  list($message, $messageHierarchy) = $templates + [
    'Unexpected value "%s".',
    'Unexpected value "%s" set at %s.',
  ];
  if (isset($this->key)) {
    $name = $this->key;
    if ($this->parents) {
      $name = implode('.', $parents) . ".{$name}";
    }
    $message = sprintf($messageHierarchy, $value, $name);
  }
  else {
    $message = sprintf($message, $value);
  }
  parent::__construct($message, 0, $previous);
}