Request Validation API: Validating Request Parameters

This API validates client request based on value of parameters and request method it came with by matching it to an XML file where validators are setup.

How does it work?

To better understand how it works, one has to imagine an interplay of following components working for the common goal of request validation:

  1. request: This is the payload sent by client to server in order to retrieve a resource owned by latter (eg: page). Following request components are relevant for validation:
  2. XML: a file where validators are defined in <routes> tag for each route based on parameter name and request method
  3. ParameterValidator: an abstract class holding recipe for parameter value validation, saving validation result into a Result object
  4. Result: object that encapsulates result of a validation along with status as ResultStatus
  5. Validator: a class that glues everything together by parsing XML and running all ParameterValidator instances found matching request.
  6. ResultsList: a list of Result objects obtained after ParameterValidator instances were ran, available via Validator's getResults() method.

All classes inside API belong to namespace Lucinda\RequestValidator!

How should developers deal with validation results?

Using components above, this API aims at functioning like a black box that expects request and XML file location being fed to Validator and latter to present global validation results. API makes no assumption how your application should behave when validation fails for one or more parameters! Instead it only provides a platform where, based on methods of ResultsList, developers can:

Moreover, on each validation, ResultsList object is passed to next ParameterValidator object constructor and become available to validate("PARAM_VALUE") method as $this->pendingResults. This feature is useful to maintain efficiency when parameters depend of each other!

How can I use it?

To learn how to install and use this API, follow this step-by-step guide!