You are here

public function Message::setMetadata in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/Message.php \Zend\Stdlib\Message::setMetadata()

Set message metadata

Non-destructive setting of message metadata; always adds to the metadata, never overwrites the entire metadata container.

Parameters

string|int|array|Traversable $spec:

mixed $value:

Return value

Message

Throws

Exception\InvalidArgumentException

Overrides MessageInterface::setMetadata

File

vendor/zendframework/zend-stdlib/src/Message.php, line 37

Class

Message

Namespace

Zend\Stdlib

Code

public function setMetadata($spec, $value = null) {
  if (is_scalar($spec)) {
    $this->metadata[$spec] = $value;
    return $this;
  }
  if (!is_array($spec) && !$spec instanceof Traversable) {
    throw new Exception\InvalidArgumentException(sprintf('Expected a string, array, or Traversable argument in first position; received "%s"', is_object($spec) ? get_class($spec) : gettype($spec)));
  }
  foreach ($spec as $key => $value) {
    $this->metadata[$key] = $value;
  }
  return $this;
}