PHPackages                             coolephp/options-resolver - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. coolephp/options-resolver

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

coolephp/options-resolver
=========================

Elegant verification class initialization options and configuration. - 优雅的校验类初始化选项、配置。

v1.0.0(5y ago)18MITPHPPHP &gt;=7.2

Since Feb 24Pushed 5y agoCompare

[ Source](https://github.com/coolephp/options-resolver)[ Packagist](https://packagist.org/packages/coolephp/options-resolver)[ Docs](https://github.com/coolephp/options-resolver)[ Fund](https://www.guanguans.cn/images/wechat.jpeg)[ RSS](/packages/coolephp-options-resolver/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

options-resolver
================

[](#options-resolver)

> Elegant verification class initialization options and configuration. - 优雅的校验类初始化选项、配置。

[![Tests](https://github.com/coolephp/options-resolver/workflows/Tests/badge.svg)](https://github.com/coolephp/options-resolver/actions)[![Check & fix styling](https://github.com/coolephp/options-resolver/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/coolephp/options-resolver/actions)[![codecov](https://camo.githubusercontent.com/f4f9ce9c8fe6de54e4086617c266c19bc216f48fcfdcc696e4167f852c78e074/68747470733a2f2f636f6465636f762e696f2f67682f636f6f6c657068702f6f7074696f6e732d7265736f6c7665722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d55524746415753365334)](https://codecov.io/gh/coolephp/options-resolver)[![Latest Stable Version](https://camo.githubusercontent.com/f06832755fcc9b33caee6394bc1c67da73914c58565b5c124c0ce463af2bc268/68747470733a2f2f706f7365722e707567782e6f72672f636f6f6c657068702f6f7074696f6e732d7265736f6c7665722f76)](//packagist.org/packages/coolephp/options-resolver)[![Total Downloads](https://camo.githubusercontent.com/2e3bb228e13f35f6f527bba81cbad7e5b27bc8d829186b6c44f46bf257155f1d/68747470733a2f2f706f7365722e707567782e6f72672f636f6f6c657068702f6f7074696f6e732d7265736f6c7665722f646f776e6c6f616473)](//packagist.org/packages/coolephp/options-resolver)[![License](https://camo.githubusercontent.com/a3ffc6c72180d1fadc15e6f050cef6e26a768176fe72398fc6f0c7eab3b03fe6/68747470733a2f2f706f7365722e707567782e6f72672f636f6f6c657068702f6f7074696f6e732d7265736f6c7665722f6c6963656e7365)](//packagist.org/packages/coolephp/options-resolver)

Requirement
-----------

[](#requirement)

- PHP &gt;= 7.2

Installation
------------

[](#installation)

```
$ composer require coolephp/options-resolver -vvv
```

Usage
-----

[](#usage)

### Example class

[](#example-class)

```
use Symfony\Component\OptionsResolver\OptionsResolver;

class Email
{
    private $options;

    /**
     * Email constructor.
     *
     * @param  array  $options
     */
    public function __construct(array $options = [])
    {
        $this->setOptions($options);
    }

    /**
     * @return mixed
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * @param  array  $options
     */
    public function setOptions(array $options): void
    {
        $this->options = configure_options($options, function (OptionsResolver $resolver) {
            $resolver->setDefaults([
                'host' => 'smtp.example.org',
                'username' => 'user',
                'password' => 'password',
                'port' => 25,
            ]);
            $resolver->setRequired(['host', 'username', 'password', 'port']);
            $resolver->setAllowedTypes('host', 'string');
            $resolver->setAllowedTypes('username', 'string');
            $resolver->setAllowedTypes('password', 'string');
            $resolver->setAllowedTypes('port', 'int');
        });
    }
}
```

### Initialization

[](#initialization)

#### All options passed verification

[](#all-options-passed-verification)

```
$options = [
    'host'     => 'smtp.example.org',
    'username' => 'user',
    'password' => 'password',
    'port'     => 25,
];
$email = new Email($options);
var_export($email);
```

```
Email::__set_state(array(
   'options' =>
  array (
    'host' => 'smtp.example.org',
    'username' => 'user',
    'password' => 'password',
    'port' => 25,
  ),
))
```

#### Option failed verification

[](#option-failed-verification)

```
$options = [
    'host'     => 'smtp.example.org',
    'username' => 'user',
    'password' => 'password',
    'port'     => '25',
];
$email = new Email($options);
var_export($email);
```

```
PHP Fatal error:  Uncaught Symfony\Component\OptionsResolver\Exception\InvalidOptionsException: The option "port" with value "25" is expected to be of type "int", but is of type "string". in /Users/yaozm/Downloads/options-resolver/vendor/symfony/options-resolver/OptionsResolver.php:1030
```

Testing
-------

[](#testing)

```
$ composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [guanguans](https://github.com/guanguans)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1909d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a49e4a0625bdf47c4e2924dcf07a053538d0c3a1e9287e8d6bfe68ed4017aa6f?d=identicon)[guanguans](/maintainers/guanguans)

---

Top Contributors

[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (6 commits)")

---

Tags

configconfigurationinitinitializationinitializeroptionoptionsconfigurationconfigoptions

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/coolephp-options-resolver/health.svg)

```
[![Health](https://phpackages.com/badges/coolephp-options-resolver/health.svg)](https://phpackages.com/packages/coolephp-options-resolver)
```

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[dflydev/dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.

13414.5M4](/packages/dflydev-dot-access-configuration)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

115254.9k1](/packages/dmishh-settings-bundle)[caseyamcl/configula

A simple, but versatile, PHP config loader

42146.6k6](/packages/caseyamcl-configula)[illuminatech/array-factory

Allows DI aware object creation from array definition

2159.6k6](/packages/illuminatech-array-factory)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
