public function setBody($body)
    {
        if (!empty($body) && !HttpCode::isBodyAllowed($this->code)) {
            throw new LogicException('You cannot set non-empty body for currently set code');
        }

        $this->body = (string)$body;
        $this->setHeader('Content-Length', strlen($this->body));
        $this->messageCache = null;
    }
public function setBody($body)
    {
        if (!empty($body) && !HttpCode::isBodyAllowed($this->code)) {
            throw new LogicException('You cannot set non-empty body for currently set code');
        }

        $this->body = (string)$body;
        $this->setHeader('Content-Length', strlen($this->body));
        $this->messageCache = null;
    }
public function setBody ( $ body ) { if ( ! empty ( $ body ) && ! HttpCode :: isBodyAllowed ( $ this -> code ) ) { throw new LogicException ( 'You cannot set non-empty body for currently set code' ) ; } $ this -> body = ( string ) $ body ; $ this -> setHeader ( 'Content-Length' , strlen ( $ this -> body ) ) ; $ this -> messageCache = null ; }
Sets body for response.
It also automatically sets correct Content-Length header.

@param string $body

@throws LogicException Thrown when you try to set body, but request code (eg. 204) denotes that no body is
allowed.
Sets body for response . It also automatically sets correct Content - Length header .