fbizi/import-export-files

Import-Export-Files - A simple library to work with Import and Export files as CSV, JSON and XML.

v2.0.0 2022-11-06 18:04 UTC

This package is auto-updated.

Last update: 2024-05-07 00:47:05 UTC


README

Downloads Last Stable Version v2.0

A light library to work with Import and Export files (requires PHP 7.4 +). The implementation is based on the current draft. CSV, JSON and XML are the files extensions that supported for the library.

Installation

Package is available on Packagist, you can install it using Composer.

composer require fbizi/import-export-files or download the zip file

Dependencies

  • PHP 7.4+
  • PHPUnit 9+

Basic usage

Importing & Exporting

Just use the Importer/Exporter class for work with:

define("DIR_PATH", "_DIR_./../uploads/");
require __DIR__ .'/../vendor/autoload.php';

use FBIZI\IE\{Importer, Exporter}; // you can use only one of them depends of your needs
use FBIZI\IE\Importers\{ // you can use only one of them depends of your needs
    ImportCsv,
    ImportJson,
    ImportXml
};
use FBIZI\IE\Exporters\{ // you can use only one of them depends of your needs
    ExportCsv,
    ExportJson,
    ExportXml
};

// Import xml file example
$obj = new Importer(
    //new ImportCsv(DIR_PATH . "testes.csv")
    //new ImportJson(DIR_PATH . "testes.json")
    new ImportXml(DIR_PATH . "testes.xml")
);
$data = $obj->importer->import();

foreach ($data['users'] as $user) {
    echo "{$user->fname} {$user->lname}\n"; 
}

// Export xml file example
$data = [
 	[ 'name' => 'John Deor', 'age' => '34', 'role' => 'Developer' ],
 	[ 'name' => 'John Deep', 'age' => '37', 'role' => 'Seller' ],
 	[ 'name' => 'John Walker', 'age' => '37', 'role' => 'Manager' ]
 ];

$obj = new Exporter(
    //new ExportCsv($data, DIR_PATH . "downloads/testes.csv")
    //new ExportJson($data, DIR_PATH . "downloads/testes.json")
    new ExportXml($data, DIR_PATH . "downloads/testes1.xml")
);
$res = $obj->exporter->export();
echo $res;

Donation

Methods :

If this project help you reduce time to develop, you can give me a cup of coffee :)