You are here

class Message in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/zendframework/zend-stdlib/src/Message.php \Zend\Stdlib\Message
  2. 8.0 vendor/symfony/psr-http-message-bridge/Tests/Fixtures/Message.php \Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Message
  3. 8.0 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-stdlib/src/Message.php \Zend\Stdlib\Message

Hierarchy

Expanded class hierarchy of Message

17 string references to 'Message'
Abstract2Dot5ApiTest::testNoDuplicateValidationIfClassConstraintInMultipleGroups in vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php
Abstract2Dot5ApiTest::testNoDuplicateValidationIfPropertyConstraintInMultipleGroups in vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php
Abstract2Dot5ApiTest::testTraversalEnabledOnClass in vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php
AbstractValidatorTest::testValidateDifferentObjectsSeparately in vendor/symfony/validator/Tests/Validator/AbstractValidatorTest.php
AbstractValidatorTest::testValidateMultipleGroups in vendor/symfony/validator/Tests/Validator/AbstractValidatorTest.php

... See full list

File

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

Namespace

Zend\Stdlib
View source
class Message implements MessageInterface {

  /**
   * @var array
   */
  protected $metadata = [];

  /**
   * @var string
   */
  protected $content = '';

  /**
   * Set message metadata
   *
   * Non-destructive setting of message metadata; always adds to the metadata, never overwrites
   * the entire metadata container.
   *
   * @param  string|int|array|Traversable $spec
   * @param  mixed $value
   * @throws Exception\InvalidArgumentException
   * @return Message
   */
  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;
  }

  /**
   * Retrieve all metadata or a single metadatum as specified by key
   *
   * @param  null|string|int $key
   * @param  null|mixed $default
   * @throws Exception\InvalidArgumentException
   * @return mixed
   */
  public function getMetadata($key = null, $default = null) {
    if (null === $key) {
      return $this->metadata;
    }
    if (!is_scalar($key)) {
      throw new Exception\InvalidArgumentException('Non-scalar argument provided for key');
    }
    if (array_key_exists($key, $this->metadata)) {
      return $this->metadata[$key];
    }
    return $default;
  }

  /**
   * Set message content
   *
   * @param  mixed $value
   * @return Message
   */
  public function setContent($value) {
    $this->content = $value;
    return $this;
  }

  /**
   * Get message content
   *
   * @return mixed
   */
  public function getContent() {
    return $this->content;
  }

  /**
   * @return string
   */
  public function toString() {
    $request = '';
    foreach ($this
      ->getMetadata() as $key => $value) {
      $request .= sprintf("%s: %s\r\n", (string) $key, (string) $value);
    }
    $request .= "\r\n" . $this
      ->getContent();
    return $request;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Message::$content protected property
Message::$metadata protected property
Message::getContent public function Get message content Overrides MessageInterface::getContent
Message::getMetadata public function Retrieve all metadata or a single metadatum as specified by key Overrides MessageInterface::getMetadata
Message::setContent public function Set message content Overrides MessageInterface::setContent
Message::setMetadata public function Set message metadata Overrides MessageInterface::setMetadata
Message::toString public function