Download the PHP package ilsenem/matcher without Composer
On this page you can find all versions of the php package ilsenem/matcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ilsenem/matcher
More information about ilsenem/matcher
Files in ilsenem/matcher
Package matcher
Short Description Array schema matcher
License MIT
Homepage https://github.com/ilsenem/matcher
Informations about the package matcher
Matcher\Schema
Simple schema matcher for arrays.
- Installation
- Usage
- Type matching
- Nullable values
- Skip keys
- Composite arrays
- Array nesting and collections
- Errors
Installation
Install as Composer dependency:
In your code:
Usage
Type matching
Supported types for values are:
- boolean
- integer
- double
- string
Nullable values
Add ?
before type declaration to mark value as nullable.
Skip keys
Add ?
before key to skip matching if key is not present in data.
Composite arrays
If an array have no strict schema but follow typings for key and value, you could
set composite key => value
type for it:
Array nesting and collections
You could nest schema one into another to match complex structures and match array collections:
Errors
With $matcher->getErrors()
after matching you could get array of errors:
Types of errors:
Schema::ERR_COLLECTION_DEFINITION
- Definition of the collection must be the only definition of the level.Schema::ERR_KEY_NOT_FOUND
- The key defined in the schema is not found in the data.Schema::ERR_TYPE_UNKNOWN
- Unknown type given in schema.Schema::ERR_TYPE_MISMATCH
- Type mismatch for any type of declaration.
License
MIT.