| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Server\Validation; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | final readonly class SchemaViolation |
| 24: | { |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function __construct( |
| 30: | public string $pointer, |
| 31: | public string $message, |
| 32: | ) { |
| 33: | Assert::that($pointer)->matchesRegularExpression( |
| 34: | '#\A(?:/(?:[^/~]|~[01])*)*\z#', |
| 35: | 'Schema violation pointer must be an RFC 6901 JSON pointer, {value} given.', |
| 36: | ); |
| 37: | Assert::that($message)->isNonEmptyString('Schema violation message must be a non-empty string, {type} given.'); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function toArray(): array |
| 44: | { |
| 45: | return ['pointer' => $this->pointer, 'message' => $this->message]; |
| 46: | } |
| 47: | } |
| 48: | |