1. Go to this page and download the library: Download rasuvaeff/schema library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$result = $user->parse($payload);
if (!$result->ok) {
foreach ($result->errors as $error) {
// '$.tags[2]' / RFC 6901 '/tags/2' — the segments are the source of truth
$error->toPath();
$error->toJsonPointer();
$error->message; // kinds and sizes only, never the offending value
}
}
$value = $user->parseOrThrow($payload); // SchemaException carries every error
// SchemaException extends InvalidArgumentException — an invalid input,
// not a runtime failure. Consumers with an InvalidArgumentException
// contract can let it propagate as is.
use Rasuvaeff\PropertyTesting\Random;
$random = new Random(42);
$value = $user->arbitrary()->generate($random)->value; // always parses
#[Property(runs: 300)]
public function queuePayloadIsHandled(SchemaInterface $payload): void
{
$value = Gen::draw($payload->arbitrary());
// ...
}
$export = $user->toJsonSchema(); // strict (default): a transform
// without a declared codec throws
$export->schema; // pure draft 2020-12 fragment
$export->nonRepresentable; // list<NonRepresentable>: what
// was dropped, with paths
$export->assertFullyRepresentable(); // throws listing every entry
$user->toJsonSchema(lenient: true); // a codec-less transform exports
// as {} + an entry instead