2 Commits

Author SHA1 Message Date
70701bb8f1 allowed header Authorization 2026-04-02 08:23:39 +02:00
8f9c744134 added documentation for return 2026-04-01 07:26:06 +02:00
2 changed files with 16 additions and 1 deletions

View File

@ -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();
@ -279,7 +293,7 @@ class APIlite
header('Access-Control-Allow-Origin: ' . $origin);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization');
echo json_encode($arr);
exit;
}

View File

@ -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>