Validation Service
The validation service is again a multi-handler service with no action methods. Its purpose is to standardize validating a value against a given type and a known default before using it in your code. It provides these public methods:
  • validate_value which is just a central hub for calling the other methods
  • validate_boolean_value for turning a value into a boolean or returning the default
  • validate_integer_value for turning a value into an integer or returning the default
  • validate_float_value for turning a value into a float or returning the default
  • validate_callback_value for checking whether a value is a valid callback or returning the default
  • validate_supported_value for checking whether a value is part of a supported list of values or returning the default
As you're probably expecting by now, all of these methods simply pass on the parameters to a given handler. The handler is free to decide what to do with those values -- the only non-negotiable aspect of this all is the return type of the validation operation. A boolean validation must return a boolean value.
There is just one type of handler pre-packaged with the module and that is the so-called container validation handler. Basically this handler expects to be provided with a PSR-11-compatible container that contains exactly two 2 keys: defaults and options. Both keys should store an array. The former array is used for returning the default values and the latter for checking for supported options (for the supported value validation). The actual type validation is performed using the validation helpers from the Helpers Module.
If you need a different logic, you may use your own custom handler that implements the ValidationHandlerInterface interface.
Copy link