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
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.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-09