PHPackages                             kuria/options - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. kuria/options

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

kuria/options
=============

Resolve structured arrays according to the specified set of options

v2.1.0(3y ago)24.3k↓50%12MITPHPPHP &gt;=7.1

Since Sep 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kuria/options)[ Packagist](https://packagist.org/packages/kuria/options)[ RSS](/packages/kuria-options/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (2)

Options
=======

[](#options)

Resolve structured arrays (e.g. configuration) according to the specified set of options.

[![https://travis-ci.com/kuria/options.svg?branch=master](https://camo.githubusercontent.com/eea02597fc61c054e43e20879d5aa8add8d5b10d74180648499b5cdd895207f4/68747470733a2f2f7472617669732d63692e636f6d2f6b757269612f6f7074696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/kuria/options)Contents

- [Features](#features)
- [Requirements](#requirements)
- [Usage](#usage)
    - [Resolving options](#resolving-options)
        - [Working with `Node` instances](#working-with-node-instances)
        - [Resolver context](#resolver-context)
    - [Defining options](#defining-options)
        - [Terminology](#terminology)
        - [Option factories](#option-factories)
        - [Option configuration](#option-configuration)
            - [`required()`](#required)
            - [`default($default)`](#default-default)
            - [`nullable()`](#nullable)
            - [`notNullable()`](#notnullable)
            - [`allowEmpty()`](#allowempty)
            - [`notEmpty()`](#notempty)
            - [`normalize(callable $normalizer)`](#normalize-callable-normalizer)
            - [`validate(callable $validator)`](#validate-callable-validator)
        - [Supported types](#supported-types)
        - [Normalizer and validator value types](#normalizer-and-validator-value-types)
        - [Node options](#node-options)
    - [Handling validation errors](#handling-validation-errors)
    - [Ignoring unknown keys](#ignoring-unknown-keys)
    - [Integrating the options resolver](#integrating-the-options-resolver)

[Features](#id1)
----------------

[](#features)

- type validation
- typed lists
- nullable options
- choices
- default values
- lazy defaults (that may depend on other options)
- custom validators and normalizers
- nested options (multi-dimensional arrays)
- custom resolver context

[Requirements](#id2)
--------------------

[](#requirements)

- PHP 7.1+

[Usage](#id3)
-------------

[](#usage)

### [Resolving options](#id4)

[](#resolving-options)

Use `Resolver` to resolve arrays according to the specified options.

The `resolve()` method returns an instance of `Node`, which can be accessed as an array. See [Working with Node instances](#working-with-node-instances).

If the passed value is invalid, `ResolverException` will be thrown. See [Handling validation errors](#handling-validation-errors).

```
