reactphp-x/json
最新稳定版本:v1.0.0
Composer 安装命令:
composer require reactphp-x/json
包简介
README 文档
README
install
composer require reactphp-x/json -vvv
Usage
require __DIR__ . "/vendor/autoload.php"; use ReactphpX\Json\Json; $json = new Json(); $json->registerDataSource('post', [ 'id' => 1, 'title' => 'first post', ]); $json->registerDataSource('post1', function ($json, $config) { return [ 'id' => 2, 'title' => 'second post', ]; }); $json->registerDataStructure('post', [ 'id' => ":id", ]); $json->registerDataStructure('post1', function ($json, $config) { return [ 'title' => ":title", ]; }); // output : {"id":1,"title":"first post"} echo json_encode($json->getJson([ "_data_source" => "post", ])) . PHP_EOL; // output : {"id":2,"title":"second post"} echo json_encode($json->getJson([ "_data_source" => "post1", ])) . PHP_EOL; // output : {"id":1} echo json_encode($json->getJson([ "_data_source" => "post", "_data_structure" => [ "id"=> ":id", ], ])) . PHP_EOL; // output : {"id":1} echo json_encode($json->getJson([ "_data_source" => "post", "_data_structure" => "post", ])) . PHP_EOL; // output : {"title":"second post"} echo json_encode($json->getJson([ "_data_source" => "post1", "_data_structure" => "post1", ])) . PHP_EOL; // _data_option $json->registerDataSource('test_option', function ($json, $config) { return $config['_data_option'] ?? []; }); // output : {"id":"1","title":"my is title"} echo json_encode($json->getJson([ "_data_source" => "test_option", "_data_option"=> [ "id"=> "1", "title"=> "my is title", ], "_data_structure" => ":*", ])) . PHP_EOL;
test
./vendor/bin/phpunit tests/
License
MIT
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-10