sauls/options-resolver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sauls/options-resolver

Composer 安装命令:

composer require sauls/options-resolver

包简介

Symfony options resolver with multi dimensional array support

README 文档

README

Build Status Packagist Total Downloads Coverage Status Scrutinizer Code Quality License

Symfony OptionsResolver with multi dimensional array support

Requirements

PHP >= 7.2

Installation

Using composer

$ composer require sauls/options-resolver

Apppend the composer.json file manually

{
    "require": {
        "sauls/options-resolver": "^1.0"
    }
}

Usage

Standard usage can be found at Symfony OptionsResolver official documentation.

The associative array support is added by using a dot notation array indexes.

Defining options

To define the associative options, use dot notated array indexes.

$resolver->setDefined['nested.name', 'nested.value', 'nested.deep.type'];

Adding allowed types

Allowed types are added using dot notation index.

$resolver->addAllowedType('nested.name', ['string']);
$resolver->addAllowedType('nested.value', ['int']);

Adding allowed values

Allowed values are added using dot notation index.

$resolver->addAllowedValues('nested.deep.type', ['one', 'two', 'three']);

Default option values

Default options can be added as dot notation index or associative array.

$resolver->setDefaults(
    [
        'nested.name' => 'Hello world!',
        'nested.value' => 100,
        'nested.deep.type' => 'one',
    ]
);

// Or

$resolver->setDefaults(
    [
        'nested' => [
            'name' => 'Hello world!',
            'value' => 100,
            'deep' => [
                'type' => 'one',
            ],
        ],
    ]
);

Resolving options

Passing array to resolve options can contain either the dot notation indexes or associative array.

$resolver->resolve(
    [
        'nested.name' => 'Resolve me!',
        'nested.value' => 500,
        'nested.deep.type' => 'two',
    ]
);

// Or

$resolver->resolve(
    [
        'nested' => [
            'name' => 'Resolve me!',
            'value' => 500,
            'deep' => [
                'type' => 'two',
            ],
        ]
    ]
);

Exceptions

All exceptions will return what is wrong with your associative option using dot notation. For example:

The option "nested.deep.type" with value "four" is invalid. Accepted values are: "one", "two", "three".

The option "nested.value" with value "wrong" is expected to be of type "int", but is of type "string".

The required option "nested.value" is missing.

The option "nested.deep.nmae" does not exist. Defined options are: "nested.deep.name", "nested.name", "nested.type", "nested.value", "text", "type".

统计信息

  • 总下载量: 6.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固