lithium\net\http\Message::body PHP Method

body() public method

Add data to and compile the HTTP message body, optionally encoding or decoding its parts according to content type.
public body ( mixed $data = null, array $options = [] ) : array
$data mixed
$options array - `'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
return array
    public function body($data = null, $options = array())
    {
        $default = array('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;
    }

Usage Example

Beispiel #1
0
 /**
  * Compile the HTTP message body, optionally encoding its parts according to content type.
  *
  * @see lithium\net\http\Message::body()
  * @see lithium\net\http\Message::_encode()
  * @param mixed $data
  * @param 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
  * @return array
  */
 public function body($data = null, $options = array())
 {
     $defaults = array('encode' => true);
     return parent::body($data, $options + $defaults);
 }