sekonda / laravel-formatter
一个格式化库,可以将数据输出格式在XML、CSV、JSON、TXT、YAML等格式之间进行转换。
3.0
2017-10-12 10:23 UTC
Requires
- php: >=5.4.0
- illuminate/support: >=4.0
- league/csv: ~6.0
- mustangostang/spyc: 0.5.*@dev
This package is auto-updated.
Last update: 2024-09-28 19:31:20 UTC
README
一个格式化包,可以帮助你轻松地在各种格式之间进行转换,如XML、JSON、CSV等...
目标
该库的目标是允许将数据格式从一个类型转换为另一个类型。查看解析器和格式以查看支持的输入/输出格式。
安装
通过命令行
composer require Sekonda/laravel-formatter
通过 composer.json
{ "require": { "Sekonda/laravel-formatter": "2.x" } }
解析器
以下所有格式都是格式化库可以读取的支持格式。
- 数组
- CSV
- JSON
- XML
- YAML
格式
以下所有格式都是支持输出的格式。
- 数组
- CSV
- JSON
- XML
- YAML
通用用法
包含格式化工具
use Sekonda\Formatter\Formatter;
支持类型
Formatter::JSON; //json Formatter::CSV; //csv Formatter::XML; //xml Formatter::ARR; //array Formatter::YAML; //yaml
创建第一个格式化工具
$formatter = Formatter::make($jsonString, Formatter::JSON); $formatter = Formatter::make($yamlString, Formatter::YAML); $formatter = Formatter::make($array, Formatter::ARR); ...
从格式化工具输出
$csv = $formatter->toCsv(); $json = $formatter->toJson(); $xml = $formatter->toXml(); $array = $formatter->toArray(); $yaml = $formatter->toYaml();
已弃用功能
以下功能已被从库中弃用,但您可以在应用程序中轻松继续使用它们
序列化数组
$serialized = serialize($formatter->toArray());
PHP 导出
$export = var_export($formatter->toArray());