Roll out meta properties in attributes and more schema classes (#129)
This commit is contained in:
parent
09596c0382
commit
d3a07912b0
1 changed files with 178 additions and 88 deletions
|
|
@ -101,9 +101,11 @@ class ResourceTemplateReference extends ElementReference
|
|||
return [$readResult->resource];
|
||||
}
|
||||
|
||||
$meta = $this->resourceTemplate->meta;
|
||||
|
||||
if (\is_array($readResult)) {
|
||||
if (empty($readResult)) {
|
||||
return [new TextResourceContents($uri, 'application/json', '[]')];
|
||||
return [new TextResourceContents($uri, 'application/json', '[]', $meta)];
|
||||
}
|
||||
|
||||
$allAreResourceContents = true;
|
||||
|
|
@ -151,14 +153,15 @@ class ResourceTemplateReference extends ElementReference
|
|||
if (\is_string($readResult)) {
|
||||
$mimeType = $mimeType ?? $this->guessMimeTypeFromString($readResult);
|
||||
|
||||
return [new TextResourceContents($uri, $mimeType, $readResult)];
|
||||
return [new TextResourceContents($uri, $mimeType, $readResult, $meta)];
|
||||
}
|
||||
|
||||
if (\is_resource($readResult) && 'stream' === get_resource_type($readResult)) {
|
||||
$result = BlobResourceContents::fromStream(
|
||||
$uri,
|
||||
$readResult,
|
||||
$mimeType ?? 'application/octet-stream'
|
||||
$mimeType ?? 'application/octet-stream',
|
||||
$meta
|
||||
);
|
||||
|
||||
@fclose($readResult);
|
||||
|
|
@ -169,21 +172,21 @@ class ResourceTemplateReference extends ElementReference
|
|||
if (\is_array($readResult) && isset($readResult['blob']) && \is_string($readResult['blob'])) {
|
||||
$mimeType = $readResult['mimeType'] ?? $mimeType ?? 'application/octet-stream';
|
||||
|
||||
return [new BlobResourceContents($uri, $mimeType, $readResult['blob'])];
|
||||
return [new BlobResourceContents($uri, $mimeType, $readResult['blob'], $meta)];
|
||||
}
|
||||
|
||||
if (\is_array($readResult) && isset($readResult['text']) && \is_string($readResult['text'])) {
|
||||
$mimeType = $readResult['mimeType'] ?? $mimeType ?? 'text/plain';
|
||||
|
||||
return [new TextResourceContents($uri, $mimeType, $readResult['text'])];
|
||||
return [new TextResourceContents($uri, $mimeType, $readResult['text'], $meta)];
|
||||
}
|
||||
|
||||
if ($readResult instanceof \SplFileInfo && $readResult->isFile() && $readResult->isReadable()) {
|
||||
if ($mimeType && str_contains(strtolower($mimeType), 'text')) {
|
||||
return [new TextResourceContents($uri, $mimeType, file_get_contents($readResult->getPathname()))];
|
||||
return [new TextResourceContents($uri, $mimeType, file_get_contents($readResult->getPathname()), $meta)];
|
||||
}
|
||||
|
||||
return [BlobResourceContents::fromSplFileInfo($uri, $readResult, $mimeType)];
|
||||
return [BlobResourceContents::fromSplFileInfo($uri, $readResult, $mimeType, $meta)];
|
||||
}
|
||||
|
||||
if (\is_array($readResult)) {
|
||||
|
|
@ -192,7 +195,7 @@ class ResourceTemplateReference extends ElementReference
|
|||
try {
|
||||
$jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT);
|
||||
|
||||
return [new TextResourceContents($uri, $mimeType, $jsonString)];
|
||||
return [new TextResourceContents($uri, $mimeType, $jsonString, $meta)];
|
||||
} catch (\JsonException $e) {
|
||||
throw new RuntimeException("Failed to encode array as JSON for URI '{$uri}': {$e->getMessage()}");
|
||||
}
|
||||
|
|
@ -202,7 +205,7 @@ class ResourceTemplateReference extends ElementReference
|
|||
$jsonString = json_encode($readResult, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT);
|
||||
$mimeType = $mimeType ?? 'application/json';
|
||||
|
||||
return [new TextResourceContents($uri, $mimeType, $jsonString)];
|
||||
return [new TextResourceContents($uri, $mimeType, $jsonString, $meta)];
|
||||
} catch (\JsonException $e) {
|
||||
throw new RuntimeException("Failed to encode array as JSON for URI '{$uri}': {$e->getMessage()}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue