承接 gamringer/php-json-patch 相关项目开发

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

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

gamringer/php-json-patch

最新稳定版本:1.0

Composer 安装命令:

composer require gamringer/php-json-patch

包简介

PHP JSON Patch (RFC6902) implementation

README 文档

README

License Latest Stable Version Latest Unstable Version Total Downloads

SensioLabsInsight

Build Status

Build Status Code Coverage Scrutinizer Code Quality

A RFC6902 compliant JSON Patch PHP implementation

#License JSONPatch is licensed under the MIT license.

#Installation

composer require gamringer/php-json-patch

##Tests

composer install
phpunit

#Documentation

##Operations can be constructed and applied independently

<?php

$target = ['1', '2', '3'];
$operation = new \gamringer\JSONPatch\Operation\Test('/foo', 'bar');
$operation->apply($target);

##Operations can also be constructed from a JSON string

<?php

$operation = \gamringer\JSONPatch\Operation\Test::fromDecodedJSON(json_decode('{"path":"/foo","value":"bar"}'));

##A patch can be constructed from a set of operations

<?php

$patch = new \gamringer\JSONPatch\Patch();

$patch->addOperation(new \gamringer\JSONPatch\Operation\Add('/foo', 'bar'));
$patch->addOperation(new \gamringer\JSONPatch\Operation\Test('/foo', 'bar'));

##A patch can also be constructed from a JSON string

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"bar"}]');

##A patch can be applied

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"bar"}]');

$target = [];
$patch->apply($target);

var_dump($target);

/* Results:

array(1) {
  'foo' =>
  string(3) "bar"
}

*/

If the patch fails, it gets completely reverted and an exception is thrown.

<?php

$patch = \gamringer\JSONPatch\Patch::fromJSON('[{"op":"add","path":"/foo","value":"bar"},{"op":"test","path":"/foo","value":"baz"}]');

$target = [];

try {
    $patch->apply($target);
} catch (\gamringer\JSONPatch\Exception $e) {
    var_dump($target);
}

/* Results:

array(0) {}

*/

统计信息

  • 总下载量: 12.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-16