Download the PHP package m1x0n/opis-json-schema-error-presenter without Composer
On this page you can find all versions of the php package m1x0n/opis-json-schema-error-presenter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download m1x0n/opis-json-schema-error-presenter
More information about m1x0n/opis-json-schema-error-presenter
Files in m1x0n/opis-json-schema-error-presenter
Package opis-json-schema-error-presenter
Short Description JSON schema error presenter for opis library
License MIT
Informations about the package opis-json-schema-error-presenter
opis-json-schema-error-presenter
Warning
⚠️This library might become obsolote since new major version (2.0.0) of opis/json-schema already supports Error formating.
Customizable error presenter for json schema validation errors produced by opis/json-schema library: JSON schema implementation.
In other words it's a raw attempt to represent Opis\JsonSchema\ValidationError
collection in
human readable way.
Requirements
- php >= 7.1
- opis/json-schema
Installation
Usage example
Output result example
Presenting Strategies
AllErrors
- shows all available presented errorsFirstError
- picks the first of the presented errorsBestMatchError
- evaluates best matching error
In order to specify strategy simply pass selected one to
PresentedValidationErrorFactory
, e.g:
Custom translations
There is a possibility to have custom translations.
Currently there is only DefaultTranslator
which exposes some generic messages like:
The attribute length should be at least 3 characters
In order to replace or extend or come up with new translations MessageTranslator
interface
must be implemented.
For example:
Locale resolving
For better experience with different localizations custom translator could be used alongside with automatic locale resolution.
Currently next locale resolvers are implemented:
NullLocaleResolver
as fallback to generic messages.HttpLocaleResolver
tries to detect locale based onHTTP_ACCEPT_LANGUAGE
header and requiresext-intl
to be installed.
It's also possible to implement custom locale resolver by implementing LocaleResolver
interface.
To set up HttpLocaleResolver
or custom-crafted one:
Locale support
Currently there is a possibility to use locales defined in php arrays
via ArrayLocaleLoader
. See lang/en.php
.
In order to load more languages ValidationErrorPresenter
might be configured in following way:
However it's possible to load locale strings from anywhere by implementing
LocaleLoader
interface.
Also presenter could be configured with single locale.
For doing that FixedLocaleResolver
will be helpful.
For example:
All the configurations might be slightly simplified by using DI-container.