ergebnis/json-pointer
Composer 安装命令:
composer require ergebnis/json-pointer
包简介
Provides an abstraction of a JSON pointer.
README 文档
README
This project provides a composer package with an abstraction of a JSON pointer.
Installation
Run
composer require ergebnis/json-pointer
Usage
ReferenceToken
You can create a ReferenceToken from a string value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $referenceToken = Pointer\ReferenceToken::fromString('foo/9000/😆'); $referenceToken->toJsonString(); // 'foo~19000~😆' $referenceToken->toString(); // 'foo/9000/😆' $referenceToken->toUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'
You can create a ReferenceToken from a JSON string value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $referenceToken = Pointer\ReferenceToken::fromJsonString('foo~19000~😆'); $referenceToken->toJsonString(); // 'foo~19000~😆' $referenceToken->toString(); // 'foo/9000/😆' $referenceToken->toUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'
You can create a ReferenceToken from a URI fragment identifier string value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $referenceToken = Pointer\ReferenceToken::fromUriFragmentIdentifierString('foo~19000~1%F0%9F%98%86'); $referenceToken->toJsonString(); // 'foo~19000~😆' $referenceToken->toString(); // 'foo/9000/😆' $referenceToken->toUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'
You can create a ReferenceToken from an int value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $referenceToken = Pointer\ReferenceToken::fromInt(9001); $referenceToken->toJsonString(); // '9001' $referenceToken->toString(); // '9001' $referenceToken->toUriFragmentIdentifierString(); // '9001'
You can compare ReferenceTokens:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $one = Pointer\ReferenceToken::fromString('foo/bar'); $two = Pointer\ReferenceToken::fromJsonString('foo~1bar'); $three = Pointer\ReferenceToken::fromString('foo/9000'); $one->equals($two); // true $one->equals($three); // false
JsonPointer
You can create a JsonPointer referencing a document:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $jsonPointer = Pointer\JsonPointer::document(); $jsonPointer->toJsonString(); // '' $jsonPointer->toUriFragmentIdentifierString(); // '#'
You can create a JsonPointer from a JSON string representation value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $jsonPointer = Pointer\JsonPointer::fromJsonString('/foo/bar/😆'); $jsonPointer->toJsonString(); // '/foo/bar/😆' $jsonPointer->toUriFragmentIdentifierString(); // '#/foo/bar/%F0%9F%98%86'
You can create a JsonPointer from a URI fragment identifier string representation value:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $jsonPointer = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/foo/bar/%F0%9F%98%86'); $jsonPointer->toJsonString(); // '/foo/bar/😆' $jsonPointer->toUriFragmentIdentifierString(); // '#/foo/bar/%F0%9F%98%86'
You can create a JsonPointer from ReferenceTokens:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $referenceTokens = [ Pointer\ReferenceToken::fromString('foo'), Pointer\ReferenceToken::fromString('bar'), ]; $jsonPointer = Pointer\JsonPointer::fromReferenceTokens(...$referenceTokens); $jsonPointer->toJsonString(); // '/foo/bar' $jsonPointer->toUriFragmentIdentifierString(); // '#/foo/bar'
You can compare JsonPointers:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $one = Pointer\JsonPointer::fromJsonString('/foo/bar'); $two = Pointer\JsonPointer::fromJsonString('/foo~1bar'); $three = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/foo/bar'); $one->equals($two); // false $one->equals($three); // true
You can append a ReferenceToken to a JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $jsonPointer = Pointer\JsonPointer::fromJsonString('/foo/bar'); $referenceToken = Pointer\ReferenceToken::fromString('baz'); $newJsonPointer = $jsonPointer->append($referenceToken); $newJsonPointer->toJsonString(); // '/foo/bar/baz' $newJsonPointer->toUriFragmentIdentifierString(); // '#foo/bar/baz'
Specification
You can create a Specification that is always satisfied by a JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::always(); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // true $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // true
You can create a Specification that is satisfied when a closure returns true for a JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::closure(static function (Pointer\JsonPointer $jsonPointer) { return $jsonPointer->toJsonString() === '/foo/bar'; }); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // false $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // true
You can create a Specification that is satisfied when a JsonPointer equals another JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::equals(Pointer\JsonPointer::fromJsonString('/foo/bar')); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // false $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // true
You can create a Specification that is never satisfied by a JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::never(); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // false $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // false
You can create a Specification that is satisfied when another Specification is not satisfied by a JsonPointer:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::not(Pointer\Specification::equals(Pointer\JsonPointer::fromJsonString('/foo/bar'))); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // true $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // false
You can compose Specifications to find out if a JsonPointer satisfies any of them:
<?php declare(strict_types=1); use Ergebnis\Json\Pointer; $specification = Pointer\Specification::anyOf( Pointer\Specification::closure(static function(Pointer\JsonPointer $jsonPointer) { return $jsonPointer->toJsonString() === '/foo/bar'; }), Pointer\Specification::equals(Pointer\JsonPointer::fromJsonString('/foo/baz')), Pointer\Specification::never(), ); $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo')); // false $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/bar')); // true $specification->isSatisfiedBy(Pointer\JsonPointer::fromJsonString('/foo/baz')); // true
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @ergebnis.
PHP Version Support Policy
This project supports PHP versions with active and security support.
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.
ergebnis/json-pointer 适用场景与选型建议
ergebnis/json-pointer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.91M 次下载、GitHub Stars 达 20, 最近一次更新时间为 2022 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「pointer」 「RFC6901」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ergebnis/json-pointer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ergebnis/json-pointer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ergebnis/json-pointer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
JSON Pointer (RFC-6901) PHP implementation
PHP JSON Pointer (RFC6901) implementation
Kinikit - PHP Application development framework MVC component
Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)
Accessor implement based on JSON Pointer (RFC6901)
ext-json wrapper with sane defaults
统计信息
- 总下载量: 24.91M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 26
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-28