aedart/array-option
最新稳定版本:1.1.0
Composer 安装命令:
composer require aedart/array-option
包简介
Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)
README 文档
README
Allows you to defined a set of options (array key-value pair), which must follow a set of predefined rules (allowed options)
Official website (https://bitbucket.org/aedart/array-option)
Contents
[TOC]
When to use this
If your component, class or method accepts options, in the form of an array (key-value pair) and you need to perform some kind of basic validation of those options, e.g. are required, data-type check and eventually also have a predefined default value.
Warning I advise you NOT to use this component, unless you really cannot specify method arguments in any other way, than in the form of an associative array.
How to install
#!console
composer require aedart/array-option 1.*
This package uses composer. If you do not know what that is or how it works, I recommend that you read a little about, before attempting to use this package.
Quick start
The blow stated example show how to build a component, which accepts 3 options, each having a default value and a specific data-type.
#!php
<?php
use Aedart\ArrayOption\Traits\ArrayOptionsListTrait;
use Aedart\ArrayOption\AllowedOptionsList;
use Aedart\ArrayOption\Interfaces\IOptionType;
class MyComponent {
use ArrayOptionsListTrait;
public function __construct(){
// Specify the allowed options
// See Aedart\ArrayOption\Interfaces\IAllowedOption
$allowedOptions = new AllowedOptionsList([
[
'name' => 'myOption',
'type' => IOptionType::TYPE_STRING,
'required' => true,
'defaultValue' => 'doIt',
'description' => 'A single option with do-it'
],
[
'name' => 'myOtherOption',
'type' => IOptionType::TYPE_INTEGER,
'required' => false,
'defaultValue' => 27,
'description' => 'Another custom option'
],
[
'name' => 'LastOption',
'type' => IOptionType::TYPE_ARRAY,
'required' => false,
'defaultValue' => [1, 2, 3],
'description' => 'Special...'
],
]);
// Set the allowed-options-list
$this->getArrayOptionsList()->setAllowedOptionsList($allowedOptions);
}
public function doSomeThing(array $options){
// Set the given options in the "options-list"
$optionsList = $this->getArrayOptionsList();
$optionsList->setArrayOptions($options); // Validates input, throws exceptions if something is wrong
// Get the value OR default value for a given option
$myOption = $optionsList->getValue('myOption');
return $myOption;
}
}
For additional information, please review this package’s interfaces as well as the unit tests.
License
BSD-3-Clause, Read the LICENSE file included in this package
aedart/array-option 适用场景与选型建议
aedart/array-option 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「options」 「array」 「method parameters」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aedart/array-option 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aedart/array-option 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aedart/array-option 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Lightweight configuration interfaces and utilities
Trunkrs Shipping Method Plugin for Magento 2
This extension provide application configuration support stored in database.
paysafecard PHP REST API Library
Array wrapper that eases the retrieval of values. Has parameters, options and settings and traits for inclusion in other libraries.
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-03-22