added documentation for return
This commit is contained in:
@ -118,6 +118,7 @@ class APIlite
|
||||
$ref_type = $ref_method->getReturnType();
|
||||
$method['return'] = $this->reflectionTypeToNames($ref_type, $ref_method->getDeclaringClass());
|
||||
$method['return_structure'] = $this->reflectionTypeToStructure($ref_type, $ref_method->getDeclaringClass());
|
||||
$method['return_doc'] = $this->parseReturnDoc($method['doc']);
|
||||
}
|
||||
$this->methods[] = $method;
|
||||
}
|
||||
@ -271,6 +272,19 @@ class APIlite
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseReturnDoc(string $doc): string|null
|
||||
{
|
||||
$lines = explode("\n", $doc);
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, '@return') !== false) {
|
||||
$ret = trim(substr($line, strpos($line, '@return') + strlen('@return')));
|
||||
if (strlen($ret) <= 0) return null;
|
||||
return trim(stristr($ret, ' '));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function response(array $arr): void
|
||||
{
|
||||
ob_clean();
|
||||
|
||||
@ -827,6 +827,7 @@ $renderParamControl = function (string $methodName, array $param) use ($formatDe
|
||||
<h3 style="margin-bottom: 1rem; color: #2c3e50;">Return:</h3>
|
||||
<?php if (is_string($method['return'])) { ?>
|
||||
<code class="parameter-type"><?php echo htmlspecialchars($method['return']); ?></code>
|
||||
<?php echo htmlspecialchars((string) $method['return_doc']); ?>
|
||||
<?php } ?>
|
||||
<?php if (is_array($method['return'])) foreach ($method['return'] as $return) { ?>
|
||||
<code class="parameter-type"><?php echo htmlspecialchars((string) $return); ?></code>
|
||||
|
||||
Reference in New Issue
Block a user