示例#1
0
    public function parse_api($xmlNode)
    {
        if (!$xmlNode->hasAttribute('source')) {
            throw new Exception('API node has no source');
        }
        $arrComments = $this->srcParser->parseFile(\Xily\Base::fileFormatDir($this->strSRCPath, '/') . $xmlNode->attribute('source'));
        $html = '';
        $intLevel = $xmlNode->hasAttribute('level') ? $xmlNode->attribute('level') : 2;
        foreach ($arrComments as $arrComment) {
            $strCommentBody = '';
            if (isset($arrComment['description'])) {
                $strCommentBody .= '<p>' . $arrComment['description'] . '</p>';
            }
            if (isset($arrComment['method'])) {
                $strCommentBody .= '<p><span class="subhead">Method</span>: ' . $arrComment['method'] . '</p>';
            }
            if (isset($arrComment['param'])) {
                $strCommentBody .= '
					<p><b>Parameter List</b></p>
					<table class="list">
						<tr>
							<th>Parameter</th>
							<th>Type</th>
							<th>Default</th>
							<th>Required</th>
							<th>Description</th>
						</tr>
				';
                foreach ($arrComment['param'] as $arrParam) {
                    $strCommentBody .= '
						<tr>
							<td>' . $arrParam['name'] . '</td>
							<td>' . $arrParam['type'] . '</td>
							<td>' . (isset($arrParam['default']) ? $arrParam['default'] : '-') . '</td>
							<td>' . ($arrParam['optional'] ? 'No' : 'Yes') . '</td>
							<td>' . $arrParam['description'] . '</td>
						</tr>
					';
                }
                $strCommentBody .= '</table>';
            }
            if (isset($arrComment['return'])) {
                $strCommentBody .= '<p><span class="subhead">Return value</span>: <i>' . $arrComment['return']['type'] . '</i>' . ($arrComment['return']['description'] == '' ? '' : ' &rarr; ' . $arrComment['return']['description']) . '</p>';
            }
            if (isset($arrComment['see'])) {
                if ($xmlSee = $xmlNode->getNodeByPath('see(@ref == "' . $arrComment['see'] . '")')) {
                    $strCommentBody .= $this->parse_content($xmlSee);
                }
            }
            if ($this->strDemoURL && isset($arrComment['demo'])) {
                if ($arrComment['demo'] == '') {
                    $arrComment['demo'] = $arrComment['cmd'];
                }
                if ($xmlDemo = $xmlNode->getNodeByPath('demo(@ref == "' . $arrComment['demo'] . '")')) {
                    $strCommentBody .= '<div class="demo_box"><table class="view"><tr>';
                    $strCommentBody .= '<td class="demo_title"><div>DEMO</div></td><td>';
                    $strCommentBody .= '<form action="' . $this->strDemoURL . '" method="POST" target="_blank" enctype="' . htmlentities($this->encType, ENT_QUOTES, 'UTF-8') . '">';
                    // "enctype" MUST be "multipart/form-data" to support file uploads
                    $strCommentBody .= '<table class="view demo_table">';
                    foreach ($xmlDemo->children() as $xmlParam) {
                        $strParamName = $xmlParam->attribute('name');
                        $strParamNameEscaped = htmlentities($strParamName, ENT_QUOTES, 'utf-8');
                        $xmlParamDefault = $xmlParam->attribute('default');
                        $xmlParamDefaultEscaped = htmlentities($xmlParamDefault, ENT_QUOTES, 'utf-8');
                        $strParamNameEscapedValue = $xmlParam->tag() == 'array' ? $strParamNameEscaped . '[]' : $strParamNameEscaped;
                        $strCommentBody .= '<tr>';
                        $strCommentBody .= '<td><input type="checkbox" value="' . $strParamNameEscapedValue . '" ' . ($xmlParam->isFalse('active') ? '' : 'checked ') . ($xmlParam->isTrue('optional') ? '' : ' disabled') . '/>&nbsp;</td>';
                        $strCommentBody .= '<td class="demo_label">' . $strParamNameEscaped . ':</td><td style="width:100%">';
                        switch ($xmlParam->tag()) {
                            case 'array':
                                $strCommentBody .= '<select class="demo_input" multiple="multiple" size="5" name="' . $strParamNameEscapedValue . '">';
                                foreach ($xmlParam->children('option') as $xmlOption) {
                                    $strCommentBody .= '<option' . ' value="' . htmlentities($xmlOption->value(), ENT_QUOTES, 'utf-8') . '"' . ($xmlOption->isTrue('default') ? ' selected' : '') . '>' . htmlentities($xmlOption->hasAttribute('label') ? $xmlOption->attribute('label') . ' (' . $xmlOption->value() . ')' : $xmlOption->value(), ENT_QUOTES, 'utf-8') . '</option>';
                                }
                                $strCommentBody .= '</select>';
                                break;
                            case 'bool':
                                $strCommentBody .= '<input class="demo_input" type="radio" name="' . $strParamNameEscaped . '" value="1"' . ($xmlParam->isTrue('default') ? ' checked' : '') . ' /> Yes ' . '<input class="demo_input" type="radio" name="' . $strParamNameEscaped . '" value="0" ' . ($xmlParam->isFalse('default') ? ' checked' : '') . '/> No';
                                break;
                            case 'file':
                                $strCommentBody .= '<input class="demo_input" type="file" name="' . $strParamNameEscaped . '" />';
                                break;
                            case 'text':
                                $strCommentBody .= '<textarea class="demo_input" name="' . $strParamNameEscaped . '" style="height: ' . ($xmlParam->hasAttribute('height') ? $xmlParam->attribute('height') : '80px') . '">' . $xmlParamDefaultEscaped . '</textarea>';
                                break;
                            case 'date':
                                $strCommentBody .= '<input class="demo_input date" type="text" name="' . $strParamNameEscaped . '" value="' . $xmlParamDefaultEscaped . '"' . ($xmlParam->isTrue('fixed') ? ' readonly="true"' : '') . ' />';
                                break;
                            default:
                                $xlsOptions = $xmlParam->children('option');
                                if (!$xlsOptions) {
                                    $strCommentBody .= '<input class="demo_input text" type="' . ($xmlParam->isTrue('password') ? 'password' : 'text') . '" name="' . $strParamNameEscaped . '" value="' . $xmlParamDefaultEscaped . '"' . ($xmlParam->isTrue('fixed') ? ' readonly="true"' : '') . ' />';
                                    break;
                                }
                                $strCommentBody .= '<select class="demo_input" name="' . $strParamNameEscaped . '">';
                                foreach ($xlsOptions as $xmlOption) {
                                    $strCommentBody .= '<option' . ' value="' . htmlentities($xmlOption->value(), ENT_QUOTES, 'utf-8') . '"' . ($xmlOption->isTrue('default') ? ' selected' : '') . '>' . htmlentities($xmlOption->hasAttribute('label') ? $xmlOption->attribute('label') . ' (' . $xmlOption->value() . ')' : $xmlOption->value(), ENT_QUOTES, 'utf-8') . '</option>';
                                }
                                $strCommentBody .= '</select>';
                                break;
                        }
                        $strCommentBody .= '</td></tr>';
                    }
                    $strCommentBody .= '</table>';
                    $strCommentBody .= '<div class="demo_bar"><input class="right" style="margin-left:10px" type="submit" /><select class="right"><option value="post">POST</option><option value="get">GET</option></select><div class="clear"></div></div>';
                    $strCommentBody .= '</form></td></tr></table></div>';
                }
            }
            $html .= $this->insert_section($intLevel, $arrComment['cmd'], $strCommentBody);
        }
        // $html .= '<pre>'.var_export($arrComments, 1).'</pre>';
        return $html;
    }
示例#2
0
 /**
  * Set the include path for additional XML documents
  *
  * @param string $strPath
  * @return void
  */
 public function setIncludePath($strPath)
 {
     $this->strIncludePath = \Xily\Base::fileFormatDir($strPath);
 }