remorhaz/php-json-patch 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

remorhaz/php-json-patch

最新稳定版本:v0.6.1

Composer 安装命令:

composer require remorhaz/php-json-patch

包简介

JSON Patch (RFC-6902) PHP implementation

README 文档

README

Latest Stable Version Build Scrutinizer Code Quality codecov Mutation testing badgeTotal Downloads License

This library implements RFC6902-compliant JSON patch tool.

Requirements

Installation

You will need composer to perform install.

composer require remorhaz/php-json-patch

Documentation

Accessing JSON document

You can create accessible JSON document either from encoded JSON string or from decoded JSON data using corresponding node value factory:

use Remorhaz\JSON\Data\Value\EncodedJson;
use Remorhaz\JSON\Data\Value\DecodedJson;

// Creating document from JSON-encoded string:
$encodedValueFactory = EncodedJson\NodeValueFactory::create();
$encodedJson = '{"a":1}';
$document1 = $encodedValueFactory->createValue($encodedJson);

// Creating document from decoded JSON data:
$decodedValueFactory = DecodedJson\NodeValueFactory::create();
$decodedJson = (object) ['a' => 1];
$document2 = $decodedValueFactory->createValue($decodedJson);

Creating and processing query

You should use query factory to create query from JSON Patch document. Then you should use processor to apply that query:

<?php
use Remorhaz\JSON\Data\Value\EncodedJson;
use Remorhaz\JSON\Patch\Processor\Processor;
use Remorhaz\JSON\Patch\Query\QueryFactory;

$encodedValueFactory = EncodedJson\NodeValueFactory::create();
$queryFactory = QueryFactory::create();
$processor = Processor::create();

$patch = $encodedValueFactory->createValue('[{"op":"remove","path":"/0"}]');
$query = $queryFactory->createQuery($patch);

$document = $encodedValueFactory->createValue('[1,2]');
$result = $processor->apply($query, $document);

var_dump($result->encode()); // string: '[2]'
var_dump($result->decode()); // array: [2]

Note that result can be exported either to JSON-encoded string or to raw PHP value.

License

PHP JSON Patch is licensed under MIT license.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-10