承接 initphp/parameterbag 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

initphp/parameterbag

Composer 安装命令:

composer require initphp/parameterbag

包简介

Single and multi-dimensional parameter bag with dot-path access for PHP.

README 文档

README

A small, dependency-free parameter container for PHP that handles both flat and nested (dotted-path) data with the same API.

Latest Stable Version Total Downloads CI License PHP Version Require

parameterbag

Features

  • Single API for flat and nested data; nesting is auto-detected from the constructor payload or toggled explicitly.
  • Dotted-path access ($bag->get('database.user')) with a configurable separator.
  • Optional, opt-in case-insensitive key handling.
  • Implements PHP's standard collection contracts: ArrayAccess, Countable, IteratorAggregate.
  • Strict validation of constructor options (typos throw instead of being silently ignored).
  • Zero runtime dependencies; PHPStan level 8 clean.

Requirements

  • PHP 7.4 or later (including 8.0–8.4)

Installation

composer require initphp/parameterbag

Quick start

use InitPHP\ParameterBag\ParameterBag;

$bag = new ParameterBag($_GET);

// GET /?user=alice
echo $bag->get('user', 'guest'); // 'alice'

$bag->set('locale', 'en_US')->set('debug', true);
$bag->has('debug');              // true
$bag->remove('debug');

Nested data (multi mode)

Pass a nested array (or set isMulti => true explicitly) and the bag will treat the separator (. by default) as a path delimiter:

$config = new ParameterBag([
    'database' => [
        'dsn'      => 'mysql:host=localhost',
        'username' => 'root',
        'password' => 'secret',
    ],
]);

$config->get('database.username');   // 'root'
$config->has('database.charset');    // false
$config->set('database.charset', 'utf8mb4');
$config->remove('database.password');

Use a custom separator if dots are part of your keys:

$bag = new ParameterBag($data, ['separator' => '|']);
$bag->get('database|username');

Native PHP idioms

$bag = new ParameterBag(['a' => 1, 'b' => 2]);

count($bag);          // 2
$bag['c'] = 3;        // ArrayAccess write
isset($bag['c']);     // true
foreach ($bag as $key => $value) { /* ... */ }

Public API

Method Purpose Docs
get(string $key, mixed $default = null): mixed Look up a value (dotted paths in multi mode). usage/basic-usage
has(string $key): bool Existence check (null values count as present). usage/basic-usage
set(string $key, mixed $value): self Assign or replace a value. usage/basic-usage
remove(string ...$keys): self Delete one or more keys. usage/basic-usage
merge(array|ParameterBagInterface ...$payloads): self Shallow merge (flat) or recursive replace (multi). usage/merging
replace(array $data): self Swap the entire stack. api-reference
all(): array Return the current stack as a plain array. api-reference
keys(): array / values(): array Top-level keys / values in insertion order. api-reference
count(): int Top-level entry count (also via count($bag)). usage/iteration-and-counting
getIterator(): ArrayIterator Iterates top-level entries. usage/iteration-and-counting
isEmpty(): bool True when the stack has no entries. api-reference
clear(): void Empty the stack, keep options. api-reference
close(): void Empty the stack and reset options to defaults. api-reference

Configuration options

The constructor accepts a second array of options. Unknown keys raise ParameterBagInvalidArgumentException.

Key Type Default Description
isMulti bool auto-detected from $data Enables dotted-path semantics.
separator non-empty-string '.' Delimiter for dotted paths. Ignored in flat mode.
caseInsensitive bool false When true, every key (constructor payload, set/get/has/remove arguments, merge input) is folded to lower-case. Matches the legacy v1 behaviour.

See docs/configuration.md and docs/usage/case-sensitivity.md.

Exceptions

Exception Raised when
InitPHP\ParameterBag\Exception\ParameterBagInvalidArgumentException Unknown option key, non-array/non-ParameterBag argument to merge(), or $bag[] = $v ArrayAccess append. Extends \InvalidArgumentException.

See docs/exceptions.md.

Development

composer install
composer test         # PHPUnit
composer analyse      # PHPStan (level 8)
composer cs:check     # PHP-CS-Fixer dry-run
composer cs:fix       # PHP-CS-Fixer apply

CI runs the matrix across PHP 7.4, 8.0, 8.1, 8.2, 8.3, and 8.4.

Upgrading from v1

v2 introduces a small set of intentional behaviour changes (cache removed, isMulti auto-detect inverted, value-trim bug fixed, case-sensitive by default, strict option validation, new methods). A full migration guide lives at docs/upgrading-from-v1.md.

Contributing & Security

Credits

License

Released under the MIT License.

initphp/parameterbag 适用场景与选型建议

initphp/parameterbag 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 261 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「container」 「config」 「dot-notation」 「parameter-bag」 「initphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 initphp/parameterbag 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 initphp/parameterbag 我们能提供哪些服务?
定制开发 / 二次开发

基于 initphp/parameterbag 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 261
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-14