百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

php-jsonpatch

> 编程语言
开源

适用于 PHP 的 JSON Patch 实现

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

适用于 PHP 的 JSON Patch 实现

JSON Patch for PHP

This is an implementation of JSON Patch written in PHP.

Installation via Composer

bash
composer require php-jsonpatch/php-jsonpatch

Usage

Now you can use JSON Patch for PHP via the available Composer autoload file.

Patch operations are defined in JSON and bundled in an array. Available JSON Patch operations are add, remove, replace, move, copy, and test; if their mandatory properties are not set a Rs\Json\Patch\InvalidOperationException will be thrown.

If necessary you can disable some patch operations by setting a whitelist bitmask in the constructor e.g. $patch = new Patch($targetDocument, $patchDocument, Add::APPLY | Copy::APPLY | Replace::APPLY | Remove::APPLY);. This will not allow the usage of the move and test patch operation from the patch document. If used these operations are ignored. The default is to allow all patch operations.

php
apply(); // {"a":{"b":["c","d","e"],"c":["a","b"],"e":["a"]}}
} catch (InvalidPatchDocumentJsonException $e) {
    // Will be thrown when using invalid JSON in a patch document
} catch (InvalidTargetDocumentJsonException $e) {
    // Will be thrown when using invalid JSON in a target document
} catch (InvalidOperationException $e) {
    // Will be thrown when using an invalid JSON Pointer operation (i.e. missing property)
}

For some more usage examples of JSON Patch operations have a look at the integration tests located under tests/integration/*.

Running tests

bash
composer test

License

This library is licensed under the MIT License. Please see LICENSE for more information.

Changelog

Please see CHANGELOG for more information.

Contributing

Please see CONTRIBUTING for more information.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言