remorhaz/php-json-patch
Composer 安装命令:
composer require remorhaz/php-json-patch
包简介
JSON Patch (RFC-6902) PHP implementation
关键字:
README 文档
README
This library implements RFC6902-compliant JSON patch tool.
Requirements
- PHP 8.1.
- JSON extension (ext-json) - required by remorhaz/php-json-data to access JSON documents.
- Internationalization functions (ext-intl) - required by
remorhaz/php-json-datato compare Unicode strings.
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.
remorhaz/php-json-patch 适用场景与选型建议
remorhaz/php-json-patch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 80.3k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「json patch」 「RFC6902」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 remorhaz/php-json-patch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 remorhaz/php-json-patch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 remorhaz/php-json-patch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for merging source data to destination data only if destination data remains valid after that
Monkey patching for exit(), functions, methods, and constants
Kinikit - PHP Application development framework MVC component
PHP JSON Patch (RFC6902) implementation
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 80.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-10