datatable/core
Composer 安装命令:
composer require datatable/core
包简介
DataTable core and command-line tools
README 文档
README
Represents in-memory table data such as:
- Database tables
- Database result sets
- CSV files
- Excel files
- Data grids
- ... etc
Why use the DataTable library?
- Do you need to import end-user data from different formats into your system?
- Do you need to export data from your system into different formats?
- Did you ever import csv data into a database, then import from excel, yaml, xml, etc?
- Did you ever export data from a database into csv, then export to excel, yaml, xml, pdf, etc?
This is where a "DataTable" comes in. It sits in between your importers, exporters and your application data.
It allows you to write really awesome:
- Importers, based on DataTables
- Exporters, based on DataTables
If you write your importer based on a DataTable (instead of .csv, .xls, .yaml, etc directly), then you can write your importer once, and support all import formats that DataTable supports.
If you write your exporter based on a DataTable (instead of .csv, .xls, .yaml, etc directly), then you can write your exporter once, and support all export formats that DataTable supports.
How to load data into a Table from code:
use DataTable\Core\Table; use DataTable\Core\Writer\Csv as CsvWriter; $table = new Table(); $table->setName("My data"); // Give it a user-friendly name $namecolumn = $table->getColumnByName("name"); $emailcolumn = $table->getColumnByName("email"); // get the first row (index 0) $row = $table->getRowByIndex(0); // get a cell by columnname: $cell = $row->getCellByColumnName("name"); // assign value to the cell $cell->setValue("Joe Johnson"); // do the same for the second cell (email) $cell = $row->getCellByColumnName("email"); $cell->setValue("joe@johnson.web"); // do the same for a second row (index 1) $row = $table->getRowByIndex(1); $cell = $row->getCellByColumnName("name"); $cell->setValue("John Jackson"); $cell = $row->getCellByColumnName("email"); $cell->setValue("john@jackson.web"); // use a writer to export the datatable to a .csv file $writer = new CsvWriter(); $output = $writer->write($table); echo $output;
How to read data from code:
use DataTable\Core\Table; use DataTable\Core\Reader\Csv as CsvReader; // Create the DataTable\Core\Table object $table = new Table(); $table->setName("My user data"); // Give it a user-friendly name $reader->loadFile($table, "users.csv"); // Loop through all the rows in $table foreach($table->getRows() as $row) { // Read field contents from the row by columnname $name = $row->getValueByColumnName("name"); $email = $row->getValueByColumnName("email"); // use the data, for example: // ensure database record for user with name+email }
How to use the readers and writers for importing/exporting data
use DataTable\Core\Table; use DataTable\Core\Reader\Csv as CsvReader; use DataTable\Core\Writer\AsciiTable as AsciiTableWriter; // Create the DataTable\Core\Table object $table = new Table(); $table->setName(basename($inputfile)); // Give it a user-friendly name // Instantiate a Reader, in this case a .csv file reader $reader = new CsvReader(); $reader->setSeperator(','); $reader->loadFile($table, $inputfile); // The $table now contains data from the .csv file // Instantiate a Writer, in this case an Ascii table writer $writer = new AsciiTableWriter(); $output = $writer->write($table); echo $output;
As you can see, the DataTable\Core\Table object is used to load, and then export data.
If you need to export data from your system into different formats, then all you need to do is
- Load the data from your system into a DataTable
- Use one of the many Writers to export the data into different formats
If you need to import data into your system from diffent formats, then all you need to do is:
- Use one of the many Readers to import the data from any supported format into a DataTable
- Write an importer for data from a DataTable into your system
datatable/core 适用场景与选型建议
datatable/core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.58k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「data」 「import」 「export」 「core」 「datatable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 datatable/core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 datatable/core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 datatable/core 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Parse use statements for a reflection object
Tool for copying data from a production database to a dev database. Also useful for making backups of production databases.
A fork of konnco/filament-import with support of Laravel 11 since the default importer of Filament 3 is nonsense for basic use case.
统计信息
- 总下载量: 7.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-04