-
Notifications
You must be signed in to change notification settings - Fork 0
docs: Document how custom error messages is being handled #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,4 +67,27 @@ if ($validator->isValid()) { | |
| This paragraph needs to be written, want to help out? Checkout GitHub repo! | ||
|
|
||
| ## Using custom error messages | ||
| This paragraph needs to be written, want to help out? Checkout GitHub repo! | ||
| All the errors returned from the library contain a unique constraint name. Using this constraint name you can replace the | ||
| error message with own, adjusting for your tone of voice or language. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $data = '{"age": "John Doe"}' | ||
| $jsonSchemaAsString = ' { "type": "object", "properties": { "age": { "type": "integer" } } } '; | ||
|
|
||
| $jsonSchema = json_decode($jsonSchemaAsString); | ||
| $schemaStorage = new JsonSchema\SchemaStorage(); | ||
| $schemaStorage->addSchema('internal://mySchema', $jsonSchema); | ||
| $validator = new JsonSchema\Validator( | ||
| new JsonSchema\Constraints\Factory($schemaStorage) | ||
| ); | ||
| $validator->validate($data, $jsonSchemaObject); | ||
|
|
||
| foreach ($validator->getErrors() as $error) { | ||
| echo sprintf( | ||
| customErrorMessagePatternFunction($error['constraint']['name']), | ||
| ...$error['constraint']['params'] | ||
|
Comment on lines
+89
to
+90
|
||
| ); | ||
| } | ||
| ``` | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolons at the end of these PHP statements. Both lines should end with semicolons to be valid PHP syntax.