diegogonda/stream-converter

此包最新版本(dev-master)没有可用的许可信息。

一个库,允许我们在不同格式中读取和写入文件,以管理其信息

dev-master 2019-04-28 12:00 UTC

This package is auto-updated.

Last update: 2024-09-29 00:13:06 UTC


README

这个库允许我们管理不同格式的文件内容。

安装

composer require diegogonda/stream-converter

如何使用

读取

让我们以CSV为例看看

include 'vendor/autoload.php';

use handler\CSV as CSVHandler;

$csvHandler = new CSVHandler();
$usuario = $csvHandler->read("./files/csv/usuario.csv");

var_dump($usuario);

写入

让我们以JSON为例看看

include 'vendor/autoload.php';

use handler\JSON as JSONHandler;

$data = [
    'dato1' => 1,
    'dato2' => 2,
    'dato3' => '3'
];

$jsonHandler = new JSONHandler();
$usuario = $jsonHandler->write("./files/json/data.json", $data);

读取/写入文件,转换格式

include 'vendor/autoload.php';

use handler\CSV as CSVHandler;
use handler\JSON as JSONHandler;
use converter\Manager;

$manager = new Manager();
$manager->convert(
    new CSVConverter(),
    new JSONHandler(),
    "./files/csv/ejemplo.csv",
    "./files/json/usuario.json"
);