joomla/registry
Composer 安装命令:
composer require joomla/registry
包简介
Joomla Registry Package
关键字:
README 文档
README
The Registry package provides an indexed key-value data store and an API for importing/exporting this data to several formats.
Load config by Registry
use Joomla\Registry\Registry; $registry = new Registry(); // Load by string $registry->loadString('{"foo" : "bar"}'); $registry->loadString('<root></root>', 'xml'); // Load by object or array $registry->loadObject($object); $registry->loadArray($array); // Load by file $registry->loadFile($root . '/config/config.json', 'json');
Accessing a Registry by getter & setter
Get value
$registry->get('foo'); // Get a non-exists value and return default $registry->get('foo', 'default'); // OR $registry->get('foo') ?: 'default';
Set value
// Set value $registry->set('bar', $value); // Sets a default value if not already assigned. $registry->def('bar', $default);
Accessing children value by path
$json = '{ "parent" : { "child" : "Foo" } }'; $registry = new Registry($json); $registry->get('parent.child'); // return 'Foo' $registry->set('parent.child', $value);
Removing values from Registry
// Set value $registry->set('bar', $value); // Remove the key $registry->remove('bar'); // Works for nested keys too $registry->set('nested.bar', $value); $registry->remove('nested.bar');
Accessing a Registry as an Array
The Registry class implements ArrayAccess so the properties of the registry can be accessed as an array. Consider the following examples:
// Set a value in the registry. $registry['foo'] = 'bar'; // Get a value from the registry; $value = $registry['foo']; // Check if a key in the registry is set. if (isset($registry['foo'])) { echo 'Say bar.'; }
Merge Registry
Using load* methods to merge two config files.
$json1 = '{ "field" : { "keyA" : "valueA", "keyB" : "valueB" } }'; $json2 = '{ "field" : { "keyB" : "a new valueB" } }'; $registry->loadString($json1); $registry->loadString($json2);
Output
Array(
field => Array(
keyA => valueA
keyB => a new valueB
)
)
Merge another Registry
$object1 = '{ "foo" : "foo value", "bar" : { "bar1" : "bar value 1", "bar2" : "bar value 2" } }'; $object2 = '{ "foo" : "foo value", "bar" : { "bar2" : "new bar value 2" } }'; $registry1 = new Registry(json_decode($object1)); $registry2 = new Registry(json_decode($object2)); $registry1->merge($registry2);
If you just want to merge first level, do not hope recursive:
$registry1->merge($registry2, false); // Set param 2 to false that Registry will only merge first level
Dump to one dimension
$array = array( 'flower' => array( 'sunflower' => 'light', 'sakura' => 'samurai' ) ); $registry = new Registry($array); // Make data to one dimension $flatted = $registry->flatten(); print_r($flatted);
The result:
Array
(
[flower.sunflower] => light
[flower.sakura] => samurai
)
Installation via Composer
Add "joomla/registry": "~3.0" to the 'require' block in your composer.json and then run composer install.
{
"require": {
"joomla/registry": "~3.0"
}
}
Alternatively, you can simply run the following from the command line:
composer require joomla/registry "~3.0"
joomla/registry 适用场景与选型建议
joomla/registry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 515.35k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2013 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「registry」 「joomla」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joomla/registry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joomla/registry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joomla/registry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Link Registry bundle for Contao Open Source CMS
Registry service.
Zend Framework 1 Registry package
Registry Component provides a fluent, object-oriented interface for storing data globally in a well managed fashion, helping to prevent global meltdown.
Joomla Preload Package
统计信息
- 总下载量: 515.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 17
- 依赖项目数: 33
- 推荐数: 7
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2013-02-24