You are here

public function MessageTrait::withBody in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-diactoros/src/MessageTrait.php \Zend\Diactoros\MessageTrait::withBody()
  2. 8 vendor/guzzlehttp/psr7/src/MessageTrait.php \GuzzleHttp\Psr7\MessageTrait::withBody()
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/MessageTrait.php \Zend\Diactoros\MessageTrait::withBody()

Return an instance with the specified message body.

The body MUST be a StreamInterface object.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.

Parameters

StreamInterface $body Body.:

Return value

static

Throws

\InvalidArgumentException When the body is not valid.

File

vendor/zendframework/zend-diactoros/src/MessageTrait.php, line 306

Class

MessageTrait
Trait implementing the various methods defined in MessageInterface.

Namespace

Zend\Diactoros

Code

public function withBody(StreamInterface $body) {
  $new = clone $this;
  $new->stream = $body;
  return $new;
}