php-alchemist/json
Composer 安装命令:
composer require php-alchemist/json
包简介
Collection of services for JSON functionality
README 文档
README
Package: php-alchemist/json
Current Version: v1.x -- (2025/06)
What?
A basic library for working with json and being able to map json objects to a particular class
Usage
The PHP Alchemist JSON library consists of two parts that can be used together or separately.
JsonHydratorTrait
The first is a trait PHPAlchemist\Json\Trait\JsonHydratorTrait which has a single function called
hydrateFromJson() which accepts a string called $json which is expected to be a JSON object. It
then will loop through the object and looks for setter functions or if the property exists for each
key and then sets the data appropriately on the object.
JsonMapper
The second is PHPAlchemist\Json\Service\JsonMapper which has a map() functino which will accept
a JSON string ($json) and a classname ($class). This will validate the JSON and throw a
PHPAlchemist\Json\Exception\BadJsonException if it is invalid. It will then instantiate a new class
of the given type, check to see if the hydrateFromJson() exists. If it does, then it will use that
otherwise it will then go through the same process to set the JSON keys via setter or public access.
Example
class Demo { public string $test; public string $doSomething; } $json = '{"test":"blah","doSomething":"asdf"}'; $mapper = new PHPAlchemist\Json\Service\JsonMapper(); $asdf = $mapper->map($json, Demo::class); var_dump($asdf);
OUTPUT:
object(Demo)#1 (2) { ["test"]=> string(4) "blah" ["doSomething"]=> string(4) "asdf" }
php-alchemist/json 适用场景与选型建议
php-alchemist/json 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 php-alchemist/json 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-alchemist/json 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-06-25