{"id":37009541,"url":"https://github.com/coolephp/options-resolver","last_synced_at":"2026-01-14T00:54:20.952Z","repository":{"id":56957770,"uuid":"341493243","full_name":"coolephp/options-resolver","owner":"coolephp","description":"Elegant verification class initialization options and configuration. - 优雅的校验类初始化选项、配置。","archived":false,"fork":false,"pushed_at":"2021-02-24T03:07:34.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-10T17:47:44.423Z","etag":null,"topics":["config","configuration","init","initialization","initializer","option","options"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coolephp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null},"funding":{"patreon":"guanguans","custom":"https://www.guanguans.cn/images/wechat.jpeg"}},"created_at":"2021-02-23T09:08:42.000Z","updated_at":"2021-02-24T10:40:59.000Z","dependencies_parsed_at":"2022-08-21T09:50:18.929Z","dependency_job_id":null,"html_url":"https://github.com/coolephp/options-resolver","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/coolephp/options-resolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolephp%2Foptions-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolephp%2Foptions-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolephp%2Foptions-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolephp%2Foptions-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coolephp","download_url":"https://codeload.github.com/coolephp/options-resolver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolephp%2Foptions-resolver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration","init","initialization","initializer","option","options"],"created_at":"2026-01-14T00:54:07.591Z","updated_at":"2026-01-14T00:54:16.841Z","avatar_url":"https://github.com/coolephp.png","language":"PHP","readme":"# options-resolver\n\n\u003e Elegant verification class initialization options and configuration. - 优雅的校验类初始化选项、配置。\n\n[![Tests](https://github.com/coolephp/options-resolver/workflows/Tests/badge.svg)](https://github.com/coolephp/options-resolver/actions)\n[![Check \u0026 fix styling](https://github.com/coolephp/options-resolver/workflows/Check%20\u0026%20fix%20styling/badge.svg)](https://github.com/coolephp/options-resolver/actions)\n[![codecov](https://codecov.io/gh/coolephp/options-resolver/branch/main/graph/badge.svg?token=URGFAWS6S4)](https://codecov.io/gh/coolephp/options-resolver)\n[![Latest Stable Version](https://poser.pugx.org/coolephp/options-resolver/v)](//packagist.org/packages/coolephp/options-resolver)\n[![Total Downloads](https://poser.pugx.org/coolephp/options-resolver/downloads)](//packagist.org/packages/coolephp/options-resolver)\n[![License](https://poser.pugx.org/coolephp/options-resolver/license)](//packagist.org/packages/coolephp/options-resolver)\n\n## Requirement\n\n* PHP \u003e= 7.2\n\n## Installation\n\n``` bash\n$ composer require coolephp/options-resolver -vvv\n```\n\n## Usage\n\n### Example class\n\n``` php\nuse Symfony\\Component\\OptionsResolver\\OptionsResolver;\n\nclass Email\n{\n    private $options;\n\n    /**\n     * Email constructor.\n     *\n     * @param  array  $options\n     */\n    public function __construct(array $options = [])\n    {\n        $this-\u003esetOptions($options);\n    }\n\n    /**\n     * @return mixed\n     */\n    public function getOptions()\n    {\n        return $this-\u003eoptions;\n    }\n\n    /**\n     * @param  array  $options\n     */\n    public function setOptions(array $options): void\n    {\n        $this-\u003eoptions = configure_options($options, function (OptionsResolver $resolver) {\n            $resolver-\u003esetDefaults([\n                'host' =\u003e 'smtp.example.org',\n                'username' =\u003e 'user',\n                'password' =\u003e 'password',\n                'port' =\u003e 25,\n            ]);\n            $resolver-\u003esetRequired(['host', 'username', 'password', 'port']);\n            $resolver-\u003esetAllowedTypes('host', 'string');\n            $resolver-\u003esetAllowedTypes('username', 'string');\n            $resolver-\u003esetAllowedTypes('password', 'string');\n            $resolver-\u003esetAllowedTypes('port', 'int');\n        });\n    }\n}\n```\n\n### Initialization\n\n#### All options passed verification\n\n``` php\n$options = [\n    'host'     =\u003e 'smtp.example.org',\n    'username' =\u003e 'user',\n    'password' =\u003e 'password',\n    'port'     =\u003e 25,\n];\n$email = new Email($options);\nvar_export($email);\n```\n\n``` bash\nEmail::__set_state(array(\n   'options' =\u003e \n  array (\n    'host' =\u003e 'smtp.example.org',\n    'username' =\u003e 'user',\n    'password' =\u003e 'password',\n    'port' =\u003e 25,\n  ),\n))\n```\n\n#### Option failed verification\n\n``` php\n$options = [\n    'host'     =\u003e 'smtp.example.org',\n    'username' =\u003e 'user',\n    'password' =\u003e 'password',\n    'port'     =\u003e '25',\n];\n$email = new Email($options);\nvar_export($email);\n```\n\n``` bash\nPHP 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\n```\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n* [guanguans](https://github.com/guanguans)\n* [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","funding_links":["https://patreon.com/guanguans","https://www.guanguans.cn/images/wechat.jpeg"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolephp%2Foptions-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoolephp%2Foptions-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolephp%2Foptions-resolver/lists"}