SchemaChoices final readonly class
Minn\Rest\SchemaChoices · public/minn/src/Minn/Rest/SchemaChoices.php · 136 lines
anyOf and oneOf the way the REST API's validation judges them (probe rest-schema-choices): a choice's schemas without a type take the choice's own; the refusal for matching none is named from the closest schema, or lists the titles, or is plain; several matches are named by their titles. Schema::validate() asks here first, then applies the schema's own keywords.
Constants and properties
| private | readonly Minn\Rest\Schema $schema | Promoted from the constructor. |
Public
| new | __construct(Minn\Rest\Schema $schema)# | ||||
| method | matchAny(mixed $value, array $args, string $param): Minn\Runtime\Refusal|array# | The first of an anyOf's schemas the value matches, each without a type taking the choice's own, or the refusal for matching none (probe rest-media-actions). @return array<string, mixed>|Refusal | |||
| method | matchOne(mixed $value, array $args, string $param, string $settle = 'one'): Minn\Runtime\Refusal|array# | The one of a oneOf's schemas the value matches, each without a type taking the choice's own; "first" settles for the first match. Matching none is refused as matchAny() refuses it; matching several names them when every one has a title, with their positions. @return array<string, mixed>|Refusal | |||
| method | combiningError(mixed $value, string $param, array $errors): Minn\Runtime\Refusal# | The refusal for a value no schema of a choice matched (probe rest-media-actions). With one schema, its refusal is named. Otherwise the refusals that say only the value is not the schema's type are set aside, and one left is named. Of several left, when the first is an object's, the one whose properties share the most keys with the value is named (the first of a tie, none when none share). Then, when every schema has a title, they are listed; else the plain refusal.
| |||
| method | combiningFailure(string $param, ?string $title, string $reason, mixed $position): Minn\Runtime\Refusal# | The refusal for a value that matched none of a combinator's schemas, worded from the one that came closest: its title when it has one (an empty title still reads as one), and that schema's own reason. |
Internals 2
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | closestObject(mixed $value, array $errors): ?array# | Of several object schemas' refusals, the one whose properties share the most keys with the value; null when the first is not an object's or none shares a key.
@return array{0: Refusal, 1: array<string, mixed>, 2: int|string}|null | |||
| private | listed(array $names): string# | Names in a sentence: "A and B", "A, B, and C". @param list<string> $names
|
Nothing matches.