fudge/parsi

CSV操作和查询

dev-master 2014-12-10 15:25 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:46:11 UTC


README

轻松编辑和阅读您的CSV文件。也可以查询它们!

项目设置

在终端/命令行中

composer require fudge/parsi [dev-master]

或者您可以将其添加到您的composer.json

"require": {
    "fudge/parsi": "dev-master"
}

单元测试

我很自豪地说,Fudge\Parsi的单元测试覆盖率达到了100%。使用的PHPUnit版本是~2.7.33

  1. ./vendor/bin/phpunit

如果您想修改phpunit.xml.dist,请创建自己的phpunit.xml以覆盖当前在dist文件中使用的设置。

示例

读取CSV

<?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

写入CSV

<?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.

查询CSV

<?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();

文档

待续...

贡献更改

请随时为新的功能/错误打开pull请求。

如果您发现错误但没有时间自己修复,请打开一个issue。