Skip to content

Commit f53e63f

Browse files
author
Andrew Boyton
committed
Add docs about calling reset
Ref jsonrainbow/issues/385
1 parent a4bf903 commit f53e63f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ if ($validator->isValid()) {
4545
}
4646
```
4747

48+
If you are validating multiple things then you should call `$$validator->reset();` between calls to `$validator->validate()`. See https://github.com/justinrainbow/json-schema/issues/385
49+
4850
### Type coercion
4951

5052
If you're validating data passed to your application via HTTP, you can cast strings and booleans to
@@ -83,6 +85,7 @@ is_int($request->refundAmount); // true
8385
```
8486

8587
A shorthand method is also available:
88+
8689
```PHP
8790
$validator->coerce($request, $schema);
8891
// equivalent to $validator->validate($data, $schema, Constraint::CHECK_MODE_COERCE_TYPES);
@@ -177,21 +180,22 @@ $jsonValidator->validate($jsonToValidateObject, $jsonSchemaObject);
177180
```
178181

179182
### Configuration Options
183+
180184
A number of flags are available to alter the behavior of the validator. These can be passed as the
181185
third argument to `Validator::validate()`, or can be provided as the third argument to
182186
`Factory::__construct()` if you wish to persist them across multiple `validate()` calls.
183187

184-
| Flag | Description |
185-
|------|-------------|
186-
| `Constraint::CHECK_MODE_NORMAL` | Validate in 'normal' mode - this is the default |
187-
| `Constraint::CHECK_MODE_TYPE_CAST` | Enable fuzzy type checking for associative arrays and objects |
188-
| `Constraint::CHECK_MODE_COERCE_TYPES` | Convert data types to match the schema where possible |
189-
| `Constraint::CHECK_MODE_EARLY_COERCE` | Apply type coercion as soon as possible |
190-
| `Constraint::CHECK_MODE_APPLY_DEFAULTS` | Apply default values from the schema if not set |
191-
| `Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS` | When applying defaults, only set values that are required |
192-
| `Constraint::CHECK_MODE_EXCEPTIONS` | Throw an exception immediately if validation fails |
193-
| `Constraint::CHECK_MODE_DISABLE_FORMAT` | Do not validate "format" constraints |
194-
| `Constraint::CHECK_MODE_VALIDATE_SCHEMA` | Validate the schema as well as the provided document |
188+
| Flag | Description |
189+
| ----------------------------------------------- | ------------------------------------------------------------- |
190+
| `Constraint::CHECK_MODE_NORMAL` | Validate in 'normal' mode - this is the default |
191+
| `Constraint::CHECK_MODE_TYPE_CAST` | Enable fuzzy type checking for associative arrays and objects |
192+
| `Constraint::CHECK_MODE_COERCE_TYPES` | Convert data types to match the schema where possible |
193+
| `Constraint::CHECK_MODE_EARLY_COERCE` | Apply type coercion as soon as possible |
194+
| `Constraint::CHECK_MODE_APPLY_DEFAULTS` | Apply default values from the schema if not set |
195+
| `Constraint::CHECK_MODE_ONLY_REQUIRED_DEFAULTS` | When applying defaults, only set values that are required |
196+
| `Constraint::CHECK_MODE_EXCEPTIONS` | Throw an exception immediately if validation fails |
197+
| `Constraint::CHECK_MODE_DISABLE_FORMAT` | Do not validate "format" constraints |
198+
| `Constraint::CHECK_MODE_VALIDATE_SCHEMA` | Validate the schema as well as the provided document |
195199

196200
Please note that using `CHECK_MODE_COERCE_TYPES` or `CHECK_MODE_APPLY_DEFAULTS` will modify your
197201
original data.

0 commit comments

Comments
 (0)