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
|
|
@ -68,9 +68,11 @@ class ResourceReference extends ElementReference
|
|||
return [$readResult->resource];
|
||||
}
|
||||
|
||||
$meta = $this->schema->meta;
|
||||
|
||||
if (\is_array($readResult)) {
|
||||
if (empty($readResult)) {
|
||||
return [new TextResourceContents($uri, 'application/json', '[]')];
|
||||
return [new TextResourceContents($uri, 'application/json', '[]', $meta)];
|
||||
}
|
||||
|
||||
$allAreResourceContents = true;
|
||||
|
|
@ -118,14 +120,15 @@ class ResourceReference 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);
|
||||
|
|
@ -136,21 +139,21 @@ class ResourceReference 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)) {
|
||||
|
|
@ -159,7 +162,7 @@ class ResourceReference 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(\sprintf('Failed to encode array as JSON for URI "%s": %s', $uri, $e->getMessage()));
|
||||
}
|
||||
|
|
@ -169,7 +172,7 @@ class ResourceReference 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(\sprintf('Failed to encode array as JSON for URI "%s": %s', $uri, $e->getMessage()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue