cyve / etl
Extract-Transform-Load service
3.1.1
2024-08-17 14:17 UTC
Requires
- php: >=8.1
- psr/event-dispatcher: ^1.0
- psr/log: ^1|^2|^3
Requires (Dev)
- phpunit/phpunit: ^10.0
- symfony/var-dumper: ^6.0
README
Installation:
With Composer:
composer require cyve/etl
Usage
Use case: convert CSV to JSON
$etl = new ETL( new CsvFileExtractor('users.csv'), new NullTransformer(), new JsonFileLoader('users.json') ); $etl->start();
Use an event dispatcher
Use the 4th argument of the constructor to inject an instance of Psr\EventDispatcher\EventDispatcherInterface
.
At each step of each iteration, the ETL will dispatch an event containing the result if the operation succeeded, or an exception if the operation failed
$eventDispatcher = new Symfony\Component\EventDispatcher\EventDispatcher(); $etl = new ETL( $extractor, $transformer, $loader, $eventDispatcher, ); $etl->start();
Example: progress bar
$eventDispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addListener(LoadSuccessEvent::class, function (LoadSuccessEvent $event): void {
echo '#';
});
$eventDispatcher->addListener(LoadFailureEvent::class, function (LoadFailureEvent $event): void {
echo 'E';
});