larablocks / highway by emitkowski

15
0
2
Package Data
Maintainer Username: emitkowski
Maintainer Contact: eric@soaringtech.com (Eric Mitkowski)
Package Create Date: 2016-07-18
Package Last Update: 2016-08-05
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:14:02
Package Statistics
Total Downloads: 15
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Highway (Beta)

A Laravel 5.0+ package that facilitates easy and simple transferring of data between different data storage and format types (CSV, Databases)

Coming Soon - (XML, JSON, YAML, Eloquent Models)

Note: All Larablocks packages will have releases in line with the major Laravel framework version release. (Ex. Highway 5.2.* is tested to work with Laravel 5.2.* while Highway 5.1.* is tested to worked with Laravel 5.1.*)

Installation

Add larablocks/highway as a requirement to composer.json:

{
    "require": {
        "larablocks/highway": "~0.1"
    }
}

Update your packages with composer update or install with composer install.

Laravel Integration

To wire this up in your Laravel project you need to add the service provider. Open app.php, and add a new item to the providers array.

Larablocks\Highway\HighwayServiceProvider::class,

Then you may add a Facade for more convenient usage. In your app.php config file add the following line to the aliases array.

'Highway' => Larablocks\Highway\Highway::class,

Note: The Highway facade will load automatically, so you don't have to add it to the app.php file but you may still want to keep record of the alias.

To publish the default config file config/highway.php use the artisan command:

php artisan vendor:publish --provider="Larablocks\Highway\HighwayServiceProvider"

Usage as a Facade

Highway::

Format Readers

Highway allows for you to read from one content format. First add the content format type and configuration for the format you would like Highway to read from.

Highway::addReader($type, $config_options[])

CSV Reader


$configs = [
    'file_path' => 'path_to_csv_file')] // required
    'delimiter' => 'delimter string')]  // optional, defaults to ','
    'enclosure' => 'enclosure string')] // optional, defaults to '"'
]


Highway::addReader('csv', $configs)

Database Reader


$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)

Format Writers

Highway allows for you to write to multiple content formats. After you have set up your one reader you may include multiple writers. Add these content format types and their configurations.

Highway::addWriter($type, $config_options[])

CSV Writer


$configs = [
    'file_path' => 'path_to_csv_file')] // required
    'delimiter' => 'delimter string')]  // optional, defaults to ','
    'enclosure' => 'enclosure string')] // optional, defaults to '"'
]


Highway::addWriter('csv', $configs)

Database Writer


$configs = [
    'table' => 'table_to_write_to')] // required 
]

Highway::addWriter('database', $configs)

Run the Process

Once at least one reader and writer have been added you may run the process of transferring the data.

Highway::run()

Examples

Single Writer Example

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

Multiple Writer Example

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

License

Highway is open-sourced software licensed under the MIT license