定制 lindelius/php-json-patch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lindelius/php-json-patch

Composer 安装命令:

composer require lindelius/php-json-patch

包简介

A zero-dependency PHP implementation of JSON Patch

README 文档

README

CircleCI Coverage Status

A zero-dependency PHP implementation of JSON Patch (RFC 6902).

Table of Contents

Requirements

  • PHP 7.4, or higher

Installation

If you are using Composer, you may install the latest version of this library by running the following command from your project's root folder:

composer require lindelius/php-json-patch

You may also manually download the library by navigating to the "Releases" page and then expanding the "Assets" section of the latest release.

Usage

Given a set of JSON Patch operations...

[
    { "op": "test", "path": "/name", "value": "Anakin Skywalker" },
    { "op": "replace", "path": "/name", "value": "Darth Vader" },
    { "op": "add", "path": "/order", "value": "Sith" },
    { "op": "move", "from": "/friends", "path": "/foes" }
]

And a document...

{
    "name": "Anakin Skywalker",
    "friends": ["Obi-Wan Kenobi", "Ahsoka Tano"],
    "order": "Jedi"
}

You can (atomically) apply the patches through one of the PatcherInterface methods...

// Option 1: Provide the raw JSON string
$newDocument = $patcher->patchFromJson($documentAsArray, $operationsAsJson);

// Option 2: Provide the JSON Patch operations in array format
$newDocument = $patcher->patch($documentAsArray, $operationsAsArray);

And get a new document back :)

{
    "name": "Darth Vader",
    "foes": ["Obi-Wan Kenobi", "Ahsoka Tano"],
    "order": "Sith"
}

Protected Paths

This library has built-in support for registering "protected paths", which are paths that may not be modified by any patch operation. Protected paths will indirectly also block modifications to their parent path(s) and any child paths.

$patcher->addProtectedPath("/id");
$patcher->addProtectedPath("/created_at");
$patcher->addProtectedPath("/some/nested/path");

Please note that "test" operations can still operate on a protected path since they are not actually modifying the document.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-05-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固