1 Commits

Author SHA1 Message Date
8f9c744134 added documentation for return 2026-04-01 07:26:06 +02:00
2 changed files with 15 additions and 0 deletions

View File

@ -118,6 +118,7 @@ class APIlite
$ref_type = $ref_method->getReturnType(); $ref_type = $ref_method->getReturnType();
$method['return'] = $this->reflectionTypeToNames($ref_type, $ref_method->getDeclaringClass()); $method['return'] = $this->reflectionTypeToNames($ref_type, $ref_method->getDeclaringClass());
$method['return_structure'] = $this->reflectionTypeToStructure($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; $this->methods[] = $method;
} }
@ -271,6 +272,19 @@ class APIlite
return null; 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 private function response(array $arr): void
{ {
ob_clean(); ob_clean();

View File

@ -827,6 +827,7 @@ $renderParamControl = function (string $methodName, array $param) use ($formatDe
<h3 style="margin-bottom: 1rem; color: #2c3e50;">Return:</h3> <h3 style="margin-bottom: 1rem; color: #2c3e50;">Return:</h3>
<?php if (is_string($method['return'])) { ?> <?php if (is_string($method['return'])) { ?>
<code class="parameter-type"><?php echo htmlspecialchars($method['return']); ?></code> <code class="parameter-type"><?php echo htmlspecialchars($method['return']); ?></code>
<?php echo htmlspecialchars((string) $method['return_doc']); ?>
<?php } ?> <?php } ?>
<?php if (is_array($method['return'])) foreach ($method['return'] as $return) { ?> <?php if (is_array($method['return'])) foreach ($method['return'] as $return) { ?>
<code class="parameter-type"><?php echo htmlspecialchars((string) $return); ?></code> <code class="parameter-type"><?php echo htmlspecialchars((string) $return); ?></code>