aayinde/json-office
Composer 安装命令:
composer require aayinde/json-office
包简介
Modern & Simplified Json Reader and Writer
README 文档
README
A Simple easy to use Json File Reader and Writer with minimal setup.
Installation
composer require aayinde/json-office
Usage
JsonArrayWriter
Return to steam reader
<?php
use Aayinde\JsonOffice\Writer\JsonArrayWriter;
$objJsonWriter = new JsonWriter();
$objJsonWriter->getInstanceJsonWriter()
->setInput($array)
->resultOutput();
Input:
$array = [
'default' => [
'config' => [
'host' => 'localhost',
'port' => 3306,
'username' => "root",
'password' => "root",
'schema' => "test",
'prefix' => "test",
'socket' => null,
'engine' => 'InnoDB',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'timezone' => '+00:00',
'ssl' => [
'enabled' => false,
'verify' => true,
'key' => null,
'cert' => null,
'ca' => null,
'capath' => null,
'cipher' => null
],
'failover' => [],
'options' => [
MYSQLI_OPT_CONNECT_TIMEOUT => 10,
MYSQLI_OPT_INT_AND_FLOAT_NATIVE => true,
MYSQLI_OPT_LOCAL_INFILE => 1
],
'report' => MYSQLI_REPORT_ALL & ~ MYSQLI_REPORT_INDEX
],
'logger_instance' => 'default'
]
];
Output:
{"default":{"config":{"host":"localhost","port":3306,"username":"root","password":"root","schema":"test","prefix":"test","socket":null,"engine":"InnoDB","charset":"utf8mb4","collation":"utf8mb4_general_ci","timezone":"+00:00","ssl":{"enabled":false,"verify":true,"key":null,"cert":null,"ca":null,"capath":null,"cipher":null},"failover":[],"options":{"0":10,"201":true,"8":1},"report":251},"logger_instance":"default"}}
JsonArrayWriter
Save to File.
<?php
use Aayinde\JsonOffice\Writer\JsonArrayWriter;
$objJsonWriter = new JsonWriter();
$objJsonWriter->getInstanceJsonWriter()
->setInput($array)
->saveToFile("test"));
Output:
test.json
Additional Parameters
Pretty Output
usage
<?php
$objJsonWriter = new JsonWriter();
$objJsonWriter->getInstanceJsonWriter()
->setInput($array)->useToPrettyPrint()
->resultOutput();
Output:
{
"default": {
"config": {
"host": "localhost",
"port": 3306,
"username": "root",
"password": "root",
"schema": "test",
"prefix": "test",
"socket": null,
"engine": "InnoDB",
"charset": "utf8mb4",
"collation": "utf8mb4_general_ci",
"timezone": "+00:00",
"ssl": {
"enabled": false,
"verify": true,
"key": null,
"cert": null,
"ca": null,
"capath": null,
"cipher": null
},
"failover": [],
"options": {
"0": 10,
"201": true,
"8": 1
},
"report": 251
},
"logger_instance": "default"
}
}
Additional Methods
->useToPrettyPrint()
->useConvertAmpsToHexValue()
->useConvertAposToHexValue()
->useConvertForceObject()
->useConvertNumericCheck()
->useConvertQuoteToHexValue()
->useConvertTagsToHexValue()
->usePreserveZeroFraction()
->usePartialOutputOnError()
->useUnescapedLineTerminators()
->useUnescapedSlashes()
->useUnescapedUnitcode()
JsonReader
JsonFileReader
Read a Json file
<?php
use Aayinde\JsonOffice\JsonReader;
$objJsonReader = new JsonReader();
$objJsonReader->getInstanceJsonFileReader()
->setReader("test.json")
->result();
Output
object(stdClass)[75]
public 'default' =>
object(stdClass)[76]
public 'config' =>
object(stdClass)[78]
public 'host' => string 'localhost' (length=9)
public 'port' => int 3306
public 'username' => string 'root' (length=4)
public 'password' => string 'root' (length=4)
public 'schema' => string 'test' (length=4)
public 'prefix' => string 'test' (length=4)
public 'socket' => null
public 'engine' => string 'InnoDB' (length=6)
public 'charset' => string 'utf8mb4' (length=7)
public 'collation' => string 'utf8mb4_general_ci' (length=18)
public 'timezone' => string '+00:00' (length=6)
public 'ssl' =>
object(stdClass)[77]
public 'enabled' => boolean false
public 'verify' => boolean true
public 'key' => null
public 'cert' => null
public 'ca' => null
public 'capath' => null
public 'cipher' => null
public 'failover' =>
array (size=0)
empty
public 'options' =>
object(stdClass)[74]
public '0' => int 10
public '201' => boolean true
public '8' => int 1
public 'report' => int 251
public 'logger_instance' => string 'default' (length=7)
JsonStringReader
Read a Json String
Usage
<?php
use Aayinde\JsonOffice\JsonReader;
$objJsonReader = new JsonReader();
$objJsonReader->getInstanceJsonStringReader()
->setReader($readerInput)
->result();
Input
{"default":{"config":{"host":"localhost","port":3306,"username":"root","password":"root","schema":"test","prefix":"test","socket":null,"engine":"InnoDB","charset":"utf8mb4","collation":"utf8mb4_general_ci","timezone":"+00:00","ssl":{"enabled":false,"verify":true,"key":null,"cert":null,"ca":null,"capath":null,"cipher":null},"failover":[],"options":{"0":10,"201":true,"8":1},"report":251},"logger_instance":"default"}}
Output
object(stdClass)[75]
public 'default' =>
object(stdClass)[76]
public 'config' =>
object(stdClass)[78]
public 'host' => string 'localhost' (length=9)
public 'port' => int 3306
public 'username' => string 'root' (length=4)
public 'password' => string 'root' (length=4)
public 'schema' => string 'test' (length=4)
public 'prefix' => string 'test' (length=4)
public 'socket' => null
public 'engine' => string 'InnoDB' (length=6)
public 'charset' => string 'utf8mb4' (length=7)
public 'collation' => string 'utf8mb4_general_ci' (length=18)
public 'timezone' => string '+00:00' (length=6)
public 'ssl' =>
object(stdClass)[77]
public 'enabled' => boolean false
public 'verify' => boolean true
public 'key' => null
public 'cert' => null
public 'ca' => null
public 'capath' => null
public 'cipher' => null
public 'failover' =>
array (size=0)
empty
public 'options' =>
object(stdClass)[74]
public '0' => int 10
public '201' => boolean true
public '8' => int 1
public 'report' => int 251
public 'logger_instance' => string 'default' (length=7)
Additional Methods
->useObjectAsArray()
->useBigIntAsString()
->useIgnoreInvalidUtf8()
->useInvalidUtf8Substitute()
aayinde/json-office 适用场景与选型建议
aayinde/json-office 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json」 「file」 「library」 「array」 「writer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aayinde/json-office 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aayinde/json-office 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aayinde/json-office 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-13