承接 stolt/json-merge-patch 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stolt/json-merge-patch

最新稳定版本:v2.0.1

Composer 安装命令:

composer require stolt/json-merge-patch

包简介

Implementation of JSON Merge Patch (https://tools.ietf.org/html/rfc7396).

README 文档

README

Test Version PHP Version

This is an(other) implementation of JSON Merge Patch written in PHP. For a PHP 5.3 compatible version please use the implementation by @clue.

Installation via Composer

composer require stolt/json-merge-patch

Usage

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

Apply a patch

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$targetDocument = json_decode('{"title":"Goodbye!","author":{"givenName":"John","familyName":"Doe"},"tags":["example","sample"],"content":"This will be unchanged"}');

$patchDocument = json_decode('{"title":"Hello!","phoneNumber":"+01-123-456-7890","author":{"familyName":null},"tags":["example"]}');

$patchedDocument = (new Patch())->apply(
    $targetDocument,
    $patchDocument
); // '{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}'

Generate a patch document

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$sourceDocument = json_decode('{"a":"b","b":"c"}');
$targetDocument = json_decode('{"b":"c"}');

$generatedPatchDocument = (new Patch())->generate(
    $sourceDocument,
    $targetDocument
); // '{"a":null}'

Merge patch documents

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$patchDocument1 = json_decode('{"a":"b"}');
$patchDocument2 = json_decode('{"b":"c"}');

$mergedPatchDocument = (new Patch())->merge(
    $patchDocument1,
    $patchDocument2
); // '{"a":"b","b":"c"}'

Running tests

composer test

License

This library is licensed under the MIT license. Please see LICENSE for more details.

Changelog

Please see CHANGELOG for more details.

Contributing

Please see CONTRIBUTING for more details.

统计信息

  • 总下载量: 218.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 3
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固