Skip to content

Commit

Permalink
Added some documentation about settings validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Jan 9, 2024
1 parent 69ba4bb commit 55486fd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/usage/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class ResettableSettings implements ResettableSettings
}
```

## Settings validation

Settings-bundle integrates with `symfony/validator`, so you can use the normal validation constraints at parameter properties to validate the values. The validation is performed, when the settings are saved via the `SettingsManagerInterface::save()` method. If the validation fails, an `SettingsNotValidExcpetion` is thrown and the settings are not saved.

**Attention:** Please note that the validation is only performed, when the settings are saved. That means that you can set an invalid value to a parameter, and other parts of your application might already use this invalid value, before the validation is performed. Therefore you should always validate the settings after changing them in a way, so that they could have become invalid.

You can pass the settings instance to the `validate` method of the `SettingsValidatorInterface` service to check if the settings are valid. If the method returns an empty array the settings are valid, otherwise the array contains the validation errors.

## Attributes reference

### #[Settings]
Expand Down

0 comments on commit 55486fd

Please sign in to comment.