ahmedelzarzmony/api_importer

处理不同数据格式和来源,并将其插入到统一数据库中

dev-develop 2019-03-07 12:46 UTC

This package is auto-updated.

Last update: 2024-09-08 07:35:52 UTC


README

处理不同数据格式和来源,并将其插入到统一数据库中
支持的数据类型
  • CSV
  • JSON
  • XML

用法

JSON 类型

$obj = new Importer('demo/test.json', 'json');
echo '<pre>', print_r($obj->get(), 1), '</pre>';


// Returned Array
/*
Array
(
    [0] => Array
        (
            [product_name] => product test
            [quantity] => 20
            [price] => 55
            [extra] => Array
                (
                    [x] => 1
                    [y] => 2
                )

            [breif] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

    [1] => Array
        (
            [product_name] => product test 2
            [quantity] => 30
            [price] => 45
            [breif] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

)
*/

CSV 类型

$obj = new Importer('demo/test.csv', 'csv');
echo '<pre>', print_r($obj->get(), 1), '</pre>';


// Returned Array
/*
Array
(
    [0] => Array
        (
            [0] => product_name
            [1] => quantity
            [2] => price
            [3] => breif
        )

    [1] => Array
        (
            [0] => product test
            [1] => 20
            [2] => 55
            [3] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

    [2] => Array
        (
            [0] => product test
            [1] => 30
            [2] => 65
            [3] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

)

*/

XML 类型

$obj = new Importer('demo/test.xml', 'xml');
echo '<pre>', print_r($obj->get(), 1), '</pre>';


// Returned Array
/*
Array
(
    [0] => Array
        (
            [product_name] => product test
            [quantity] => 20
            [price] => 55
            [extra] => Array
                (
                    [x] => 1
                    [y] => 2
                )

            [breif] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

    [1] => Array
        (
            [product_name] => product test 2
            [quantity] => 30
            [price] => 45
            [breif] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        )

)
*/

安装

您可以使用 Composer 将此库添加为本地、项目级的依赖项到您的项目中

composer require ahmedelzarzmony/api_importer:dev-master

如果您只需要在开发期间使用此库,例如运行项目的测试套件,那么您应该将其添加为开发依赖项

composer require --dev ahmedelzarzmony/api_importer:dev-master