phprs\apis\ApiExporter::exportApiHtml PHP Method

exportApiHtml() public method

导出API信息 简陋的html形式
public exportApiHtml ( $class_name ) : ({"header",
return ({"header",
    public function exportApiHtml($class_name)
    {
        if (is_array($class_name)) {
            $class_name = implode('\\', $class_name);
        }
        // TODO: html+js重写吧
        $body = self::$css;
        $body .= '<html>';
        $body .= '<body>';
        $info = $this->exportJson();
        $apis = $info[$class_name];
        // 类名
        $body .= '<h1>';
        $body .= htmlentities($class_name);
        $body .= '</h1>';
        $body .= '<p>';
        $body .= nl2br(htmlentities($apis['doc']));
        $body .= '</p>';
        $body .= '<ol>';
        // 接口
        foreach ($apis['apis'] as $api) {
            $body .= '<h2>';
            $body .= '<li>';
            $body .= htmlentities($api['uri'][0] . ' ' . $api['uri'][1]);
            $body .= '</li>';
            $body .= '</h2>';
            // 说明
            $body .= '<p>';
            $body .= nl2br(htmlentities($api['doc']));
            $body .= '</p>';
            // 请求
            list($sample, $doc) = $this->createRequestDoc($api);
            $body .= '<h3>>>Request</h3>';
            $body .= '<pre>';
            $body .= $sample;
            $body .= '</pre>';
            $body .= '<p>';
            $body .= nl2br(htmlentities($doc));
            $body .= '</p>';
            // 响应
            list($sample, $doc) = $this->createResponseDoc($api, $api['type'] === 'api');
            $body .= '<h3>>>Response(OK)</h3>';
            $body .= '<pre>';
            $body .= $sample;
            $body .= '</pre>';
            $body .= '<p>';
            $body .= nl2br(htmlentities($doc));
            $body .= '</p>';
            // 异常
            $fails = $this->createExceptionDoc($api);
            foreach ($fails as $name => $info) {
                $body .= '<h3>>>Response (Fail: ' . $name . ')</h3>';
                $body .= '<pre>';
                $body .= $info[0];
                $body .= '</pre>';
                $body .= '<p>';
                $body .= nl2br(htmlentities($info[1]));
                $body .= '</p>';
            }
            $body .= '<h3>>>Response (Fail: unknown)</h3>';
            $body .= '<pre>';
            $body .= "HTTP/1.1 500 Internal Server Error\r\n\r\n";
            $body .= '</pre>';
        }
        $body .= '</ol>';
        $body .= '</body>';
        $body .= '</html>';
        return $body;
    }