webnium/json-pointer
Composer 安装命令:
composer require webnium/json-pointer
包简介
Accessor implement based on JSON Pointer (RFC6901)
README 文档
README
Installation
This library distributed via packagist.org.
Execute:
$ wget http://getcomposer.org/composer.phar $ php composer.phar require webnium/json-pointer:dev-master
or add following to your composer.json
{
"require": {
"webnium/json-pointer": "dev-master"
}
}
Usage
ArrayAccessor
<?php $array = [ 'foo' => ['bar' => 1], 'list' => ['item0', 'item1'], ]; $accessor = new Webnium\JsonPointer\ArrayAccessor(new Webnium\JsonPointer\Parser); $accessor->set('/fizz/buzz', $array, 2); $accessor->set('/list/-', $array, 'item2'); echo '/foo/bar: ', var_export($accessor->get('/foo/bar', $array), true), PHP_EOL; echo '/fizz/buzz: ', var_export($accessor->get('/fizz/buzz', $array), true), PHP_EOL; echo '/list/0: ', var_export($accessor->get('/list/0', $array), true), PHP_EOL; echo '/list/2: ', var_export($accessor->get('/list/2', $array), true), PHP_EOL; echo 'root: ', var_export($accessor->get('', $array), true), PHP_EOL;
Output:
/foo/bar: 1
/fizz/buzz: 2
/list/0: 'item0'
/list/2: 'item2'
root: array (
'foo' =>
array (
'bar' => 1,
),
'list' =>
array (
0 => 'item0',
1 => 'item1',
2 => 'item2',
),
'fizz' =>
array (
'buzz' => 2,
),
)
Parser
<?php use Webnium\JsonPointer\Parser; use Webnium\JsonPointer\Exception\ExceptionInterface as JsonPointerException; $parser = new Parser; $pointers = [ '/foo/bar', '/', '', '/foo/~01/~1', '/~a/aaa', 'foo' ]; foreach ($pointers as $pointer) { try { $parsed = $parser->parse($pointer); echo "$pointer: ", var_export($parsed, true), PHP_EOL; } catch (JsonPointerException $e) { echo "$pointer: ", 'thrown \'' . get_class($e) . '\' with message \'' . $e->getMessage() . '\'', PHP_EOL; } }
Output:
/foo/bar: array (
0 => 'foo',
1 => 'bar',
)
/: array (
0 => '',
)
: array (
)
/foo/~01/~1: array (
0 => 'foo',
1 => '~1',
2 => '/',
)
/~a/aaa: thrown 'Webnium\JsonPointer\Exception\SyntaxError' with message 'unknown escape sequence "~a" detected.'
foo: thrown 'Webnium\JsonPointer\Exception\SyntaxError' with message 'pointer start with "f", "/" expected.'
LICENSE
This library destributed under MIT license. See LICENSE file for more infomation.
webnium/json-pointer 适用场景与选型建议
webnium/json-pointer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.79k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2013 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「array」 「json pointer」 「array accessor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webnium/json-pointer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webnium/json-pointer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webnium/json-pointer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Kinikit - PHP Application development framework MVC component
Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Trait providing methods to set class properties with an array.
统计信息
- 总下载量: 12.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-11-26