larablocks / highway
Requires
- php: >=5.5.9
- illuminate/database: ~5.2
- illuminate/support: ~5.2
Requires (Dev)
- fzaninotto/faker: ~1.5
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-23 13:27:38 UTC
README
一个 Laravel 5.0+ 包,简化了不同数据存储和格式类型(CSV、数据库)之间的数据传输
即将推出 - (XML, JSON, YAML, Eloquent Models)
注意:所有 Larablocks 包将与主要 Laravel 框架版本同时发布。例如,Highway 5.2.* 已测试可与 Laravel 5.2.* 一起使用,而 Highway 5.1.* 已测试可与 Laravel 5.1.* 一起使用。
安装
将 larablocks/highway
添加到 composer.json
的依赖项中
{ "require": { "larablocks/highway": "~0.1" } }
使用 composer update
更新包或使用 composer install
安装
Laravel 集成
要在您的 Laravel 项目中设置此服务,您需要添加服务提供者。打开 app.php
文件,并将新项添加到 providers 数组中。
Larablocks\Highway\HighwayServiceProvider::class,
然后,您可以为更方便的使用添加 Facade。在您的 app.php
配置文件中,将以下行添加到 aliases
数组中。
'Highway' => Larablocks\Highway\Highway::class,
注意:Highway Facade 将自动加载,因此您无需将其添加到 app.php
文件中,但您可能仍想记录该别名。
要发布默认配置文件 config/highway.php
,请使用 artisan 命令
php artisan vendor:publish --provider="Larablocks\Highway\HighwayServiceProvider"
作为 Facade 的使用
Highway::
格式读取器
Highway 允许您从一个内容格式读取。首先,添加您想要 Highway 读取的内容格式类型和配置。
Highway::addReader($type, $config_options[])
CSV 读取器
$configs = [ 'file_path' => 'path_to_csv_file')] // required 'delimiter' => 'delimter string')] // optional, defaults to ',' 'enclosure' => 'enclosure string')] // optional, defaults to '"' ] Highway::addReader('csv', $configs)
数据库读取器
$configs = [ 'table' => 'table_to_read_from')] // required 'results' => 'query builder results from table' // optional else returns all results from table Ex. 'results' => DB::table('users')->where('first_name', 'John')->get() ] Highway::addReader('database', $configs)
格式写入器
Highway 允许您将数据写入多个内容格式。设置好一个读取器后,您可以选择多个写入器。添加这些内容格式类型及其配置。
Highway::addWriter($type, $config_options[])
CSV 写入器
$configs = [ 'file_path' => 'path_to_csv_file')] // required 'delimiter' => 'delimter string')] // optional, defaults to ',' 'enclosure' => 'enclosure string')] // optional, defaults to '"' ] Highway::addWriter('csv', $configs)
数据库写入器
$configs = [ 'table' => 'table_to_write_to')] // required ] Highway::addWriter('database', $configs)
运行进程
一旦添加了至少一个读取器和写入器,您就可以运行数据传输的进程。
Highway::run()
示例
单个写入器示例
Highway::addReader('database', ['table' => 'users', 'results' => DB::table('users')->where('first_name', 'Devin')->get()]); Highway::addWriter('csv', ['file_path' => public_path('export/users.csv')]); Highway::run();
多个写入器示例
Highway::addReader('database', ['table' => 'users']); Highway::addWriter('csv', ['file_path' => public_path('export/users.csv')]); Highway::addWriter('csv', ['file_path' => public_path('export/users-tab-delimited.csv'), 'delimiter' => "\t", 'enclosure' => "'"]); Highway::run();
许可证
Highway 是开源软件,许可协议为 MIT 许可协议