Files
WP-LIT-MCP/src/Abilities/JsonMap.php
T

24 lines
489 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Abilities;
use stdClass;
/**
* PHP encodes an empty array as JSON [] – for schema type "object" the client
* must see {}. WordPress' output validation accepts stdClass for objects.
*/
final class JsonMap
{
/**
* @param array<string, mixed> $map
* @return array<string, mixed>|stdClass
*/
public static function of(array $map): array|stdClass
{
return $map === [] ? new stdClass() : $map;
}
}