init
This commit is contained in:
parent
5b9df1e550
commit
4170aca3be
24
LICENSE
Normal file
24
LICENSE
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
Copyright (c) 2014
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
120
README.md
120
README.md
|
@ -1,2 +1,120 @@
|
||||||
# droneio-test
|
CSV parser/generator
|
||||||
|
====================
|
||||||
|
|
||||||
|
<a href="https://phpci.gitnet.fr/build-status/view/2">![](https://phpci.gitnet.fr/build-status/image/2?branch=master&label=PHPCensor&style=flat-square)</a>
|
||||||
|
|
||||||
|
A simple PHP library to:
|
||||||
|
|
||||||
|
* parse a CSV file
|
||||||
|
* parse a stream as CSV datas
|
||||||
|
* generate CSV files.
|
||||||
|
|
||||||
|
PHP >= 7.1 required.
|
||||||
|
|
||||||
|
## Composer installation
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require deblan/csv "~3"
|
||||||
|
```
|
||||||
|
|
||||||
|
Or in your composer.json:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"deblan/csv": "~3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usages
|
||||||
|
|
||||||
|
### Generator
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Deblan\Csv\Csv;
|
||||||
|
|
||||||
|
$csv = new Csv();
|
||||||
|
|
||||||
|
// Defines the delimiter (default is ;)
|
||||||
|
$csv->setDelimiter(";");
|
||||||
|
|
||||||
|
// Defines the enclosure (default is ")
|
||||||
|
$csv->setEnclosure('"');
|
||||||
|
|
||||||
|
// Defines the end of line (default is \n)
|
||||||
|
$csv->setEndOfLine("\n");
|
||||||
|
|
||||||
|
// Defines the charset (default is UTF-8)
|
||||||
|
$csv->setCharset("UTF-8");
|
||||||
|
|
||||||
|
// Add a new line at the end
|
||||||
|
$csv->addData(['Foo', '$1000'));
|
||||||
|
|
||||||
|
// Add a new line at the end
|
||||||
|
$csv->appendData(['Bar', '$600']);
|
||||||
|
|
||||||
|
// Add a new line at the beginning
|
||||||
|
$csv->prependData(['Boo', '$3000']);
|
||||||
|
|
||||||
|
// Defines all the datas
|
||||||
|
$csv->setDatas([[...], [...]]);
|
||||||
|
|
||||||
|
// Defines the header
|
||||||
|
$csv->setHeaders(['Product', 'Price']);
|
||||||
|
|
||||||
|
// Rendering
|
||||||
|
$result = $csv->render();
|
||||||
|
|
||||||
|
// Rendering to a file
|
||||||
|
$result = $csv->render('products.csv');
|
||||||
|
|
||||||
|
// Appending to a file
|
||||||
|
$result = $csv->render('products.csv', FILE_APPEND);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parse a file
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Deblan\Csv\CsvParser;
|
||||||
|
|
||||||
|
$csv = new CsvParser();
|
||||||
|
|
||||||
|
// Defines the delimiter (default is ;)
|
||||||
|
$csv->setDelimiter(";");
|
||||||
|
|
||||||
|
// Defines the enclosure (default is ")
|
||||||
|
$csv->setEnclosure('"');
|
||||||
|
|
||||||
|
// Defines the end of line (default is \n)
|
||||||
|
$csv->setEndOfLine("\n");
|
||||||
|
|
||||||
|
// Headers?
|
||||||
|
$csv->setHasHeaders(true);
|
||||||
|
|
||||||
|
// Parse a file
|
||||||
|
$csv->parseFile('products.csv');
|
||||||
|
|
||||||
|
// Parse a string
|
||||||
|
$csv->parseString($myString);
|
||||||
|
|
||||||
|
// Headers and datas
|
||||||
|
$headers = $csv->getHeaders();
|
||||||
|
$products = $csv->getDatas();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parse a stram
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Deblan\Csv\CsvStreamParser;
|
||||||
|
|
||||||
|
// CsvStreamParser is a CsvParser
|
||||||
|
$csv = new CsvStreamParser();
|
||||||
|
|
||||||
|
// Parse a stream
|
||||||
|
$csv->parseStream(fopen('products.csv', 'r'));
|
||||||
|
|
||||||
|
while ($data = $csv->getData()) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
16
composer.json
Normal file
16
composer.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "deblan/csv",
|
||||||
|
"description": "A simple PHP library to parse and generate CSV files.",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Simon Vieille",
|
||||||
|
"email": "simon@deblan.fr"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Deblan\\Csv\\": "src/Deblan/Csv/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
phpunit.xml
Normal file
17
phpunit.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<phpunit
|
||||||
|
backupGlobals = "false"
|
||||||
|
backupStaticAttributes = "false"
|
||||||
|
colors = "true"
|
||||||
|
convertErrorsToExceptions = "true"
|
||||||
|
convertNoticesToExceptions = "true"
|
||||||
|
convertWarningsToExceptions = "true"
|
||||||
|
processIsolation = "false"
|
||||||
|
stopOnFailure = "false"
|
||||||
|
bootstrap = "vendor/autoload.php" >
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Deblan CSV Test Suite">
|
||||||
|
<directory>tests/</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
Loading…
Reference in a new issue