get-zen/json-patch-php
Composer 安装命令:
composer require get-zen/json-patch-php
包简介
Produce and apply json-patch objects. Forked from mikemccabe/json-patch-php (https://github.com/mikemccabe/json-patch-php). THIS FORK adds an `ensure` operation that sets a value at a given path, creating any missing intermediate structure (deep upsert semantics). Just set the damned field!
README 文档
README
Forked from mikemccabe/json-patch-php.
Produce and apply json-patch objects.
Implements IETF JSON-patch (RFC 6902) and JSON-pointer (RFC 6901):
http://tools.ietf.org/html/rfc6902 http://tools.ietf.org/html/rfc6901
Extensions
Adds custom ensure operation (op) that replaces the value at target
path or creates it if the path does not exist. (alpha!!! works in
production, no angry customers so far)
Using with Composer
composer require get-zen/json-patch-php
Then, in your project's code, use the JsonPatch class definition from
the GetZen namespace like so:
use GetZen\JsonPatch;
Entry points
- JsonPatch::get($doc, $pointer) - get a value from a json document
- JsonPatch::patch($doc, $patches) - apply patches to $doc and return result
- JsonPatch::diff($src, $dst) - return patches to create $dst from $src
Arguments are PHP arrays, i.e. the output of json_decode($json_string, 1)
(Note that you MUST pass 1 as the second argument to json_decode to get an array. This library does not work with stdClass objects.)
All structures are implemented directly as PHP arrays. An array is considered to be 'associative' (e.g. like a JSON 'object') if it contains at least one non-numeric key.
Because of this, empty arrays ([]) and empty objects ({}) compare the same, and (for instance) an 'add' of a string key to an empty array will succeed in this implementation where it might fail in others.
$simplexml_mode is provided to help with working with arrays produced from XML in the style of simplexml - e.g. repeated XML elements are expressed as arrays. When $simplexml_mode is enabled, leaves with scalar values are implicitly treated as length-1 arrays, so this test will succeed:
{ "comment": "basic simplexml array promotion",
"doc": { "foo":1 },
"patch": [ { "op":"add", "path":"/foo/1", "value":2 } ],
"expected": { "foo":[1, 2] } },
Also, when $simplexml_mode is true, 1-length arrays are converted to scalars on return from patch().
Tests (!!!! Not maintained)
Some tests are in a submodule (https://github.com/json-patch/json-patch-tests). Do 'git submodule init' to pull these, then 'php runtests.php' to run them.
get-zen/json-patch-php 适用场景与选型建议
get-zen/json-patch-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 get-zen/json-patch-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 get-zen/json-patch-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 105
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2022-11-03