dflydev/dot-access-data
Composer 安装命令:
composer require dflydev/dot-access-data
包简介
Given a deep data structure, access data by dot notation.
README 文档
README
Given a deep data structure, access data by dot notation.
Requirements
- PHP (7.1+)
For PHP (5.3+) please refer to version
1.0.
Usage
Abstract example:
use Dflydev\DotAccessData\Data; $data = new Data; $data->set('a.b.c', 'C'); $data->set('a.b.d', 'D1'); $data->append('a.b.d', 'D2'); $data->set('a.b.e', ['E0', 'E1', 'E2']); // C $data->get('a.b.c'); // ['D1', 'D2'] $data->get('a.b.d'); // ['E0', 'E1', 'E2'] $data->get('a.b.e'); // true $data->has('a.b.c'); // false $data->has('a.b.d.j'); // 'some-default-value' $data->get('some.path.that.does.not.exist', 'some-default-value'); // throws a MissingPathException because no default was given $data->get('some.path.that.does.not.exist');
A more concrete example:
use Dflydev\DotAccessData\Data; $data = new Data([ 'hosts' => [ 'hewey' => [ 'username' => 'hman', 'password' => 'HPASS', 'roles' => ['web'], ], 'dewey' => [ 'username' => 'dman', 'password' => 'D---S', 'roles' => ['web', 'db'], 'nick' => 'dewey dman', ], 'lewey' => [ 'username' => 'lman', 'password' => 'LP@$$', 'roles' => ['db'], ], ], ]); // hman $username = $data->get('hosts.hewey.username'); // HPASS $password = $data->get('hosts.hewey.password'); // ['web'] $roles = $data->get('hosts.hewey.roles'); // dewey dman $nick = $data->get('hosts.dewey.nick'); // Unknown $nick = $data->get('hosts.lewey.nick', 'Unknown'); // DataInterface instance $dewey = $data->getData('hosts.dewey'); // dman $username = $dewey->get('username'); // D---S $password = $dewey->get('password'); // ['web', 'db'] $roles = $dewey->get('roles'); // No more lewey $data->remove('hosts.lewey'); // Add DB to hewey's roles $data->append('hosts.hewey.roles', 'db'); $data->set('hosts.april', [ 'username' => 'aman', 'password' => '@---S', 'roles' => ['web'], ]); // Check if a key exists (true to this case) $hasKey = $data->has('hosts.dewey.username');
Data may be used as an array, since it implements ArrayAccess interface:
// Get $data->get('name') === $data['name']; // true $data['name'] = 'Dewey'; // is equivalent to $data->set($name, 'Dewey'); isset($data['name']) === $data->has('name'); // Remove key unset($data['name']);
/ can also be used as a path delimiter:
$data->set('a/b/c', 'd'); echo $data->get('a/b/c'); // "d" $data->get('a/b/c') === $data->get('a.b.c'); // true
License
This library is licensed under the MIT License - see the LICENSE file for details.
Community
If you have questions or want to help out, join us in the #dflydev channel on irc.freenode.net.
dflydev/dot-access-data 适用场景与选型建议
dflydev/dot-access-data 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 396.41M 次下载、GitHub Stars 达 722, 最近一次更新时间为 2012 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「access」 「dot」 「notation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dflydev/dot-access-data 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dflydev/dot-access-data 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dflydev/dot-access-data 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Dibi is Database Abstraction Library for PHP
Adds the EDTF data type to Wikibase
Access array data quickly/easily using dot-notation and asterisk.
A simple library that allows transform any kind of data to native php data or whatever
Provide a way to secure accesses to all routes of an symfony application.
统计信息
- 总下载量: 396.41M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 730
- 点击次数: 24
- 依赖项目数: 88
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2012-04-11