fudge / parsi
CSV manipulation and queries
dev-master
2014-12-10 15:25 UTC
Requires
- php: >= 5.3.0
Requires (Dev)
- phpunit/phpunit: ~3.7.22
This package is not auto-updated.
Last update: 2025-01-13 14:20:03 UTC
README
Easily edit and read your CSV's. Query them too!
Project Setup
In terminal/commandline:
composer require fudge/parsi [dev-master]
Or you can add this to your composer.json
:
"require": {
"fudge/parsi": "dev-master"
}
Unit Tests
I am proud to say that Fudge\Parsi is 100% covered by unit tests. PHPUnit version used is ~2.7.33.
./vendor/bin/phpunit
If you wish to make modifications to the phpunit.xml.dist
, please create your own
phpunit.xml
to override what is currently being used in the dist file.
Examples
Reading CSVs
<?php require_once './vendor/autoload.php'; $file = new SplFileObject('path/to/csv.csv'); $csv = new \Parsi\Readers\Csv($file); // Headers may be included. // $csv->headers(true)->load(); // OR // $csv = new \Parsi\Readers\Csv($file, $headers = true); $array = $csv->data(); // Returns an array of the data found within the file
Writing CSVs
<?php require_once './vendor/autoload.php'; $data = array( array(1, 'Ben', 'Hello, World!'), array(2, 'Kev', 'Shiny Shoes!'), ); $file = new SplFileObject('path/to/creation.csv', 'w+'); // Please ensure you use 'w+' $csv = new \Parsi\Writers\Csv($file); // Data may be set during construction like so; // new \Parsi\Writers\Csv($file, $data); $csv->setData($data)->create(); // File will now be created.
Querying CSVs
<?php require_once './vendor/autoload.php'; $file = new SplFileObject('path/to/csv.csv'); $csv = new \Parsi\Readers\Csv($file); $query = \Parsi\Query::query($csv)->select(array('1', '2'))->where(1, '=', 2); // Similar syntax to Laravel Fluent/Eloquent. /** * $data will now be populated with a multi-dimensional array with keys 1, 2 * which match the where clause */ $data = $query->get();
Documentation
To Come...
Contributing changes
Please feel free to open pull requests for new features/bugs.
If you find bugs but do not have the time to fix them yourself, please open an issue.