gamringer/php-json-pointer
Composer 安装命令:
composer require gamringer/php-json-pointer
包简介
PHP JSON Pointer (RFC6901) implementation
关键字:
README 文档
README
A RFC6901 compliant JSON Pointer PHP implementation
#License JSONPointer is licensed under the MIT license.
#Installation
composer require gamringer/php-json-pointer
##Tests
composer install
phpunit
#Documentation
##Testing a value for existence
<?php $target = [ "foo" => ["bar", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->has("/foo")); /* Results: bool(true) */
Retrieving a value that does not exist will return false
<?php $target = [ "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->has("/foo")); /* Results: bool(false) */
##Retrieving a value
<?php $target = [ "foo" => ["bar", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->get("/foo")); /* Results: array(2) { [0] => string(3) "bar" [1] => string(3) "baz" } */
Retrieving a value that does not exist will throw an exception
<?php $target = [ "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->get("/foo")); /* Results: Throws gamringer\JSONPointer\Exception */
##Inserting a value Inserting a value will returns a VoidValue object if used on an indexed array.
<?php $target = [ "foo" => ["bar", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); $value = "waldo"; var_dump($pointer->insert("/foo/1", $value)); var_dump($pointer->get("/foo")); /* Results: class gamringer\JSONPointer\VoidValue#6 (2) { protected $owner => array(3) { ... } protected $target => string(1) "1" } array(3) { [0] => string(3) "bar" [1] => string(5) "waldo" [2] => string(3) "baz" } */
If used on anything else, it will behave in the exact same way as get()
<?php $target = [ "foo" => ["bar", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); $value = "waldo"; var_dump($pointer->insert("/foo", $value)); var_dump($pointer->get("/foo")); /* Results: array(2) { [0] => string(3) "bar" [1] => string(3) "baz" } string(5) "waldo" */
##Setting a value Setting a value returns the content previously at that path
<?php $target = [ "foo" => ["bar", "waldo", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); $value = "corge"; var_dump($pointer->set("/foo", $value)); /* Results: array(3) { [0] => string(3) "bar" [1] => string(5) "waldo" [2] => string(3) "baz" } */
If the path was attainable, but not set, it will return a VoidValue
<?php $target = [ "foo" => ["bar", "waldo", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); $value = "garply"; var_dump($pointer->set("/grault", $value)); /* Results: class gamringer\JSONPointer\VoidValue#6 (2) { protected $owner => array(3) { ... } protected $target => string(6) "grault" } */
##Remove a value Removing a value returns the content previously at that path
<?php $target = [ "foo" => ["bar", "waldo", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->remove("/qux")); /* Results: string(4) "quux" */
Removing a value that does not exist will throw an exception
<?php $target = [ "foo" => ["bar", "waldo", "baz"], ]; $pointer = new \gamringer\JSONPointer\Pointer($target); var_dump($pointer->remove("/qux")); /* Results: Throws gamringer\JSONPointer\Exception */
##Operations affect the original object This affects Remove Operations
<?php $target = [ "foo" => ["bar", "waldo", "baz"], "qux" => "quux" ]; $pointer = new \gamringer\JSONPointer\Pointer($target); $pointer->remove("/qux"); var_dump($target); /* Results: array(1) { 'foo' => array(3) { [0] => string(3) "bar" [1] => string(5) "waldo" [2] => string(3) "baz" } } */
This also affects Add Operations
<?php $target = [ "foo" => ["bar", "waldo", "baz"], "qux" => "quux" ]; $value = "bar"; $pointer = new \gamringer\JSONPointer\Pointer($target); $pointer->set("/foo", $value); var_dump($target); /* Results: array(2) { 'foo' => string(3) "bar" 'qux' => string(4) "quux" } */
gamringer/php-json-pointer 适用场景与选型建议
gamringer/php-json-pointer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.79k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2014 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「json pointer」 「RFC6901」 「6901」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gamringer/php-json-pointer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gamringer/php-json-pointer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gamringer/php-json-pointer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides an abstraction of a JSON pointer.
JSON Pointer (RFC-6901) PHP implementation
Kinikit - PHP Application development framework MVC component
Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)
Accessor implement based on JSON Pointer (RFC6901)
ext-json wrapper with sane defaults
统计信息
- 总下载量: 39.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 16
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-19