Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mordilion/pipeline
Pipeline is a library to transfer data quick and reliable or to create exports with any kind of interfaces like \PDO, \SplFileObject(CSV, etc.), Arrays and your own implementation.
https://github.com/mordilion/pipeline
array configurable csv database export files import reader transfer writer
Last synced: 3 months ago
JSON representation
Pipeline is a library to transfer data quick and reliable or to create exports with any kind of interfaces like \PDO, \SplFileObject(CSV, etc.), Arrays and your own implementation.
- Host: GitHub
- URL: https://github.com/mordilion/pipeline
- Owner: mordilion
- License: mit
- Created: 2019-02-11T06:55:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-29T09:24:50.000Z (8 months ago)
- Last Synced: 2024-10-05T02:21:26.200Z (4 months ago)
- Topics: array, configurable, csv, database, export, files, import, reader, transfer, writer
- Language: PHP
- Size: 36.1 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Packagist](https://img.shields.io/packagist/dt/mordilion/pipeline.svg)](https://packagist.org/packages/mordilion/pipeline)
# Pipeline
## Description
Pipeline is a library to transfer data quick and reliable or to create exports with any kind of interfaces like \PDO, \SplFileObject(CSV, etc.), Arrays and your own implementation. It uses https://github.com/mordilion/Configurable to be full configurable.
## Basic Example
```php
1, 'name' => 'John Doe', 'email' => '[email protected]'],
['id' => 2, 'name' => 'Jane Doe', 'email' => '[email protected]'],
['id' => 3, 'name' => 'Max Mustermann', 'email' => '[email protected]']
];$reader = new ArrayReader();
$reader->setData($data);$filename = __DIR__ . '/export.csv';
$writer = new SplFileObjectWriter();
$writer->setFile(new \SplFileObject($filename, 'w'))
->setMode(SplFileObjectWriter::MODE_CSV);$pipeline = new Pipeline();
$pipeline->setReader($reader)
->setWriter($writer)
->transfer();
```## Database to CSV
An example of how to export data from a database into a CSV file with additional columns.
```php
setPdo(new \PDO('sqlite:' . __DIR__ . '/sqlite.db'))
->setSql('SELECT * FROM demo');$filename = __DIR__ . '/export.csv';
$writer = new SplFileObjectWriter();
$writer->setFile(new \SplFileObject($filename, 'w'))
->setMode(SplFileObjectWriter::MODE_CSV);$pipeline = new Pipeline();
$pipeline->setReader($reader)
->setWriter($writer)
->transfer(function (array $row, ReaderAbstract $reader, WriterAbstract $writer) {
$timestamps = [
'created_at' => isset($row['created_at']) ? $row['created_at'] : date('Y-m-d H:i:s'),
'updated_at' => isset($row['updated_at']) ? $row['updated_at'] : date('Y-m-d H:i:s'),
'exported_at' => date('Y-m-d H:i:s')
];return array_merge($row, $timestamps);
});
```## Directory listing to CSV
An example of how to export data from a database into a CSV file with additional columns.
```php
setCommand('ls /');$filename = __DIR__ . '/directory-listing.csv';
$writer = new SplFileObjectWriter();
$writer->setFile(new \SplFileObject($filename, 'w'))
->setMode(SplFileObjectWriter::MODE_CSV);$pipeline = new Pipeline();
$pipeline->setReader($reader)
->setWriter($writer)
->transfer();
```