Download the PHP package danack/params without Composer
On this page you can find all versions of the php package danack/params. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danack/params
More information about danack/params
Files in danack/params
Package params
Short Description Converts user input into correctly typed parameters
License MIT
Informations about the package params
Library renamed to TypeSpec
So won't be any activity here.
Params
A framework agnostic library for validating input parameters.
Installation
TL:DR - Using in an application
This library allows you to define a set of rules that define the expected input parameters, and then validate them.
As an example, this is what the code looks like in a controller for retrieving a list of articles:
The above example will throw a ValidationException
with a list of all the validation problems if there are any.
Alternatively you can have the parameters and list of errors returned as tuple.
Under the hood, basic usage
Given a set of rules, the library will extract the appropriate values from a 'variable map' and validate that the values meet the defined rules:
That code will extract the 'limit' and 'offset values from the variable map and check that the limit is an integer between 0 and 100, and that offset is either not set, or must be an integer between 0 and 1,000,000.
If there are any validation problems a ValidationException will be thrown. The validation problems can be retrieved from ValidationException::getValidationProblems.
Under the hood, basic usage without exceptions
Alternatively, you can avoid using exceptions for flow control:
Tests
We have several tools that are run to improve code quality. Please run sh runTests.sh
to run them all.
Pull requests should have full unit test coverage. Preferably also full mutation coverage through infection.
Related info
Json pointers - https://tools.ietf.org/html/rfc6901 JSON Patch - https://tools.ietf.org/html/rfc6902
Future work
Support Uri fragment encoding on paths
Parameter location
Some people care whether a parameter is in the query string or body. This library currently doesn't support differentiating them.
TODO
-
colors.
-
Error on unknown/invalid names. e.g. when the input include 'namme', and so the 'name' param uses default value, that sounds like an error.
- Generate OpenAPI stuff better.
All versions of params with dependencies
ext-mbstring Version *
danack/var-map Version ^0.6.1
danack/json-safe Version ^0.1.0
laminas/laminas-diactoros Version ^2.6