lithium\net\http\Message::body()

public method

Add data to and compile the HTTP message body, optionally encoding or decoding its parts according to content type.

Parameters

  • mixed $data
  • array $options
    • 'buffer' integer: split the body string
    • 'encode' boolean: encode the body based on the content type
    • 'decode' boolean: decode the body based on the content type

Returns

array

Source

	public function body($data = null, $options = []) {
		$default = ['buffer' => null, 'encode' => false, 'decode' => false];
		$options += $default;

		if ($data !== null) {
			$this->body = array_merge((array) $this->body, (array) $data);
		}
		$body = $this->body;

		if (empty($options['buffer']) && $body === null) {
			return "";
		}
		if ($options['encode']) {
			$body = $this->_encode($body);
		}
		$body = is_string($body) ? $body : join("\r\n", (array) $body);

		if ($options['decode']) {
			$body = $this->_decode($body);
		}
		return ($options['buffer']) ? str_split($body, $options['buffer']) : $body;
	}