rodnaph/edhen
Composer 安装命令:
composer require rodnaph/edhen
包简介
Encode/Decode EDN
README 文档
README
A tool to encode/decode between EDN and PHP data structures.
Note
When converting from EDN to PHP the conversion is lossy as the richness of datatypes supported by EDN is not available in PHP. So a conversion from EDN to PHP and back to EDN would not lose you data, but it would lose type information.
Usage
The interface is via some static functions on the Edhen class. To decode an EDN element...
$element = Edhen::decode('(1 :foo [2])'); // array(1, ':foo', array(2))
If you have EDN with multiple elements, you can use decodeAll
$elements = Edhen::decodeAll(':foo :bar :baz'); // array(':foo', ':bar', ':baz')
Then for encoding use the encode function, passing it the data to encode...
$ednString = Edhen::encode(array(1, 2)); // '[1 2]'
Data Type Translations
When decoding EDN to PHP...
| EDN | PHP |
|---|---|
| nil | null |
| true | true |
| false | false |
| strings | string |
| characters | string |
| symbols | string |
| keywords | string |
| integer | integer |
| floating-point | double |
| lists | array |
| vectors | array |
| maps | array |
| sets | array |
Builtin Tags
| EDN | PHP |
|---|---|
| inst | DateTime |
| uuid | string |
When encoding PHP to EDN...
| PHP | EDN |
|---|---|
| null | nil |
| boolean | boolean |
| integer | integer |
| double | float |
| array | vector |
| array (assoc) | hashmap |
| object | hashmap |
| resource | nil |
| callable | nil |
The decision on if an array is to be converted to a vector or hashmap is done by checking its keys. If any of the keys are non-numeric then a hashmap is used.
EDN is generated as a single string, no pretty-printing is currently supported. Another tool should be used for this.
Custom Tag Handlers
To implement your own tag handlers, create a class which implements the Edhen\TagHandler interface and pass it in an array as the second argument to decode/decodeAll
$myHandler = new MyCustomTagHandler(); $element = Edhen::decode($edn, array($myHandler));
You can see an example in the tests.
Installation
Edhen can be installed via Composer.
rodnaph/edhen 适用场景与选型建议
rodnaph/edhen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125.26k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2013 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rodnaph/edhen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rodnaph/edhen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 125.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2013-12-30