ridvanaltun / json-patch-generator
创建 JSON Patch (IETF RFC-6902)。
v1.1.0
2020-02-03 13:27 UTC
This package is auto-updated.
Last update: 2024-08-29 05:16:13 UTC
README
生成 JSON Patch (IETF RFC-6902)。
这个库允许你在 PHP 中生成 json-patch。
安装
$ composer require ridvanaltun/json-patch-generator
用法
<?php require_once __DIR__ . '/vendor/autoload.php'; use ridvanaltun\JsonPatchGenerator\Utils; $utils = new Utils(); $oldSnap = [ 'name' => 'foo', 'surname' => 'bar', 'skils' => [ 'computer_science' => true, 'algorithm' => true, 'math' => false, ], 'specs' => [ 'a', 'b', 'c', ] ]; $currSnap = [ 'name' => 'foo', 'age' => 23, 'skils' => [ 'computer_science' => true, 'algorithm' => false, ], 'specs' => [ 'a', 'b', 'd', 'e', ] ]; $jsonPatch = $utils->generateJsonPatch($currSnap, $oldSnap); var_dump($jsonPatch);
输出
array(7) {
[0]=>
array(3) {
["op"]=>
string(3) "add"
["path"]=>
string(4) "/age"
["value"]=>
int(23)
}
[1]=>
array(3) {
["op"]=>
string(7) "replace"
["path"]=>
string(16) "/skils/algorithm"
["value"]=>
bool(false)
}
[2]=>
array(3) {
["op"]=>
string(3) "add"
["path"]=>
string(6) "/specs"
["value"]=>
string(1) "d"
}
[3]=>
array(3) {
["op"]=>
string(3) "add"
["path"]=>
string(6) "/specs"
["value"]=>
string(1) "e"
}
[4]=>
array(2) {
["op"]=>
string(6) "remove"
["path"]=>
string(8) "/surname"
}
[5]=>
array(2) {
["op"]=>
string(6) "remove"
["path"]=>
string(11) "/skils/math"
}
[6]=>
array(3) {
["op"]=>
string(6) "remove"
["path"]=>
string(6) "/specs"
["value"]=>
string(1) "c"
}
}