src/DdvRestfulApi/Lib/RestfulApiEcho.php
public function echoStr($data, $isEcho = true, $isAutoHeader = true, $isAutoSessionClose = true, $isAutoObClean = null, $isNotUnescapedUnicode = true)
    {
        // 关闭会话
        try {
            if ($isAutoSessionClose === true && function_exists('session_write_close')) {
                @session_write_close();
            }
        } catch (Exception $e) {
        }
        $isAutoObClean = !$this->isDevelopment();

        $statusCode = empty($data['statusCode']) ? (isset($data['errorId']) && $data['errorId'] !== 'OK' ? 500 : 200) : $data['statusCode'];
        $statusText = empty($data['errorId']) ? '' : $data['errorId'];
        $statusText = empty($statusText) ? (empty($data['statusText']) ? '' : $data['statusText']) : $statusText;
        $statusText = empty($statusText) ? (($statusCode >= 200 && $statusCode < 300) ? 'OK' : 'UNKNOWN_ERROR') : $statusText;
        if (function_exists('set_status_header')) {
            set_status_header($statusCode, $statusText);
        } else {
            try {
                //nginx模式
                if (strpos(PHP_SAPI, 'cgi') === 0) {
                    @header('Status: ' . $statusCode . ' ' . $statusText, TRUE);
                } else {
                    $serverProtocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
                    @header($serverProtocol . ' ' . $statusCode . ' ' . $statusText, TRUE, $statusCode);
                    unset($serverProtocol);
                }
            } catch (Exception $e) {
            }
        }
        if ($isAutoHeader === true) {
            @header('Content-Type:application/json;charset=utf-8', true);
        }
        if ($isAutoObClean === true) {
            try {
                ob_clean();
            } catch (Exception $e) {
            }
        }
        $data['data'] = empty($data['data']) ? (object)array() : $data['data'];
        $data['page'] = empty($data['page']) ? (object)array() : $data['page'];
        if ($isEcho === true) {
            echo self::toJsonString($data);
            die();
        } else {
            return self::toJsonString($data);
        }
    }
public function echoStr($data, $isEcho = true, $isAutoHeader = true, $isAutoSessionClose = true, $isAutoObClean = null, $isNotUnescapedUnicode = true)
    {
        // 关闭会话
        try {
            if ($isAutoSessionClose === true && function_exists('session_write_close')) {
                @session_write_close();
            }
        } catch (Exception $e) {
        }
        $isAutoObClean = !$this->isDevelopment();

        $statusCode = empty($data['statusCode']) ? (isset($data['errorId']) && $data['errorId'] !== 'OK' ? 500 : 200) : $data['statusCode'];
        $statusText = empty($data['errorId']) ? '' : $data['errorId'];
        $statusText = empty($statusText) ? (empty($data['statusText']) ? '' : $data['statusText']) : $statusText;
        $statusText = empty($statusText) ? (($statusCode >= 200 && $statusCode < 300) ? 'OK' : 'UNKNOWN_ERROR') : $statusText;
        if (function_exists('set_status_header')) {
            set_status_header($statusCode, $statusText);
        } else {
            try {
                //nginx模式
                if (strpos(PHP_SAPI, 'cgi') === 0) {
                    @header('Status: ' . $statusCode . ' ' . $statusText, TRUE);
                } else {
                    $serverProtocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
                    @header($serverProtocol . ' ' . $statusCode . ' ' . $statusText, TRUE, $statusCode);
                    unset($serverProtocol);
                }
            } catch (Exception $e) {
            }
        }
        if ($isAutoHeader === true) {
            @header('Content-Type:application/json;charset=utf-8', true);
        }
        if ($isAutoObClean === true) {
            try {
                ob_clean();
            } catch (Exception $e) {
            }
        }
        $data['data'] = empty($data['data']) ? (object)array() : $data['data'];
        $data['page'] = empty($data['page']) ? (object)array() : $data['page'];
        if ($isEcho === true) {
            echo self::toJsonString($data);
            die();
        } else {
            return self::toJsonString($data);
        }
    }
[setHandler 输出]
@author: 桦 <yuchonghua@163.com>
@DateTime 2017-04-26T18:56:12+0800