定制 nimbly/caboodle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nimbly/caboodle

Composer 安装命令:

composer require nimbly/caboodle

包简介

Configuration and settings manager with autoloading from disk or AWS Secrets Manager.

README 文档

README

Latest Stable Version GitHub Workflow Status Codecov branch License

A simple PSR-11 compliant configuration manager with lazy loading from files, AWS Secrets Manager, or any other source.

Installation

composer require nimbly/config

Usage

Instantiate the Config manager with an array of LoaderInterface instances. You may specify as many loaders as you"d like - or none at all.

$config = new Config([
	new FileLoader(__DIR__ . "/config")
]);

Get data from config.

$config->get("database.hostname");

Loaders

Loaders are responisble for accepting a key, loading, and then passing the data back.

Two loaders are provided out of the box: FileLoader and AwsLoader but a LoaderInterface is provided for implementing any other loader.

FileLoader

The FileLoader will attempt to load configuration data from the local filesystem.

Instantiate the FileLoader with a path to your configuration files.

new FileLoader("/path/to/config/files");

Configuration files should return an associative array of your configuration data.

<?php

// file: config/database.php

return [
	"host" => "localhost",
	"port" => 1234,
	"user" => "dbuser",
	"password" => "dbpassword",
];

AwsLoader

The AwsLoader will attempt to load configuration data from AWS Secrets Manager.

NOTES
  • If your AWS Secrets Manager keys include dots ("."), the loader will not be able to resolve the key name properly. It is suggested that your AWS keys be of the form prod/db/default as suggested by AWS best practices.
  • VersionId and StageVersion options are not available with this loader at this time.
  • SecretBinary values are not supported at this time. The loader will only look for values in the SecretString property.

Adding loaders dynamically

You can add loaders dynamically.

$config->addLoader(
	new FileLoader(__DIR__ . "/config")
);

Accessing values

Configuration keys can be accessed using a dot-notation syntax with the left most being the key the loaders will use to resolve and load the configuration data.

$config->get("database.host");

The above would load the contents of the file database.php from the configuration path passed into the Config manager.

Your configuration files may contain nested associative arrays that can be accessed using the same dotted notation.

$config->get("database.connections.default.host");

PSR-11 note

By default, Caboodle will return a null if an item is not found in the item store.

However, PSR-11 states that when an item is not found, it should throw an instance of NotFoundExceptionInterface.

If you would like Caboodle to throw an exception when an item is not found, you may call the setThrowIfNotFound() method.

$config->setThrowIfNotFound(true);

Key hinting

By default, the root key name is assumed to be everything before the first dot ("."). However, if the root key name includes a dot, you can hint the key name by using a single hash mark in place of a dot.

For example:

$config->get("prod.database#connections.default.hostname");

Manually adding values

You may also manually add new key / value pairs into the configuration manager.

$config->add("queue", [
	"name" => "jobs",
	"host" => "localhost",
	"port" => 1234
]);

Or you may assign the entire contents of the configuration data.

$config->setItems([
	"key1" => "value1",
	"key2" => [
		"key3" => "value3"
	]
]);

nimbly/caboodle 适用场景与选型建议

nimbly/caboodle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.67k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-07