Skip to content

alla1101/CSVFileHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CSV File Handler Project [A Draft]

This package is made to ease file handling with configuration and config validation.

Remaining Goals

To validate each line in the file when writing. To validate each line before writing.

Goals

To work easily with laravel framework To work with other frameworks with relative ease.

current limitations

No more limitations baby woow

Getting Started

1- create config folder in laravel main directory, add the files found in a2la1101/csvhandler/config to it. 2- add configurations to the copied files. 3- In lumen, add the following code to app.php

$app->register(a2la1101\csvhandler\Laravel\CSVHandlerServiceProvider::class);
$app->configure('CSVHandler');

everything is now set and ready to be used.

how to use :

before starting, go to a2la1101\csvhandler\config, and read how to configure csvHandler Example. 0)

if you're not using lumen or laravel

$configProvider=new ConfigurationProvider();

$configProvider->setConfigurationsDirectory($ConfigFiledirectory);

$factory=new FileHandlerFactory();

$factory->setConfigurationProvider($configProvider);

$fileHandler=$factory->createFileHandler("CommandNameHere");

if you're using Laravel or Lumen

$fileHandler=app("CSVHandlerService")->createFileHandler("READTEST");

.................

  1. to Read :
$fileHandler=app("CSVHandlerService")->createFileHandler("READTEST");

print_r($fileHandler->readByLine());

print_r($fileHandler->readAll());

  1. to write :

to call handler for writing

$fileHandler=app("CSVHandlerService")->createFileHandler("WRITETEST");

suppose you have a $DataArray

[
	["x"=>"a1","y"=>"b1","z"=>1],
	["x"=>"a2","y"=>"b2","z"=>2],
	["x"=>"a3","y"=>"b3","z"=>3],
	["x"=>"a4","y"=>"b4","z"=>4],
]

To Write By Line

$fileHandler->writeByLine($DataArray[0]) ;
.
.
.
// if you have finished writing and want to close file
$fileHandler->writeByLine(null);

To Write All

print_r($fileHandler->writeAll($DataArray));

About

Simple Package in Lumen to handle CSV Parsing a little bit smarter.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages