• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP ETL (Extract / Transform / Load) library with SOLID principles + almost no dependency.

Latest Stable Version License CI Workflow Coverage Total Downloads

Okay, so you heard about the Extract / Transform / Load pattern, and you're looking for a PHP library to do the stuff. Alright, let's go!

bentools/etl is a versatile PHP library for implementing the Extract, Transform, Load (ETL) pattern, designed to streamline data processing tasks.

Table of Contents

Concepts

Let's cover the basic concepts:

  • Extract: you have a source of data (a database, a CSV file, whatever) - an extractor is able to read that data and provide an iterator of items
  • Transform: apply transformation to each item. A transformer may generate 0, 1 or several items to load (for example, 1 item may generate multiple SQL queries)
  • Load: load transformed item to the destination. For example, extracted items have been transformed to SQL queries, and your loader will run those queries against your database.

Installation

composer require bentools/etl

Warning

Current version (4.0) is a complete redesign and introduces significant BC (backward compatibility) breaks. Avoid upgrading from ^2.0 or ^3.0 unless you're fully aware of the changes.

Usage

Now let's have a look on how simple it is:

use BenTools\ETL\EtlExecutor;

// Given
$singers = ['Bob Marley', 'Amy Winehouse'];

// Transform each singer's name to uppercase and process the array
$etl = (new EtlExecutor())
    ->transformWith(fn (string $name) => strtoupper($name));

// When
$report = $etl->process($singers);

// Then
var_dump($report->output); // ["BOB MARLEY", "AMY WINEHOUSE"]

OK, that wasn't really hard, here we basically don't have to extract anything (we can already iterate on $singers), and we're not loading anywhere, except into PHP's memory.

You may ask, "why don't you just array_map('strtoupper', $singers) ?" and you're totally right.

But sometimes, extracting, transforming and / or loading get a little more complex. You may want to extract from a file, a crawled content on the web, perform one to many transformations, maybe skip some items, or reuse some extraction, transformation or loading logic.

Here's another example of what you can do:

use BenTools\ETL\EventDispatcher\Event\TransformEvent;
use BenTools\ETL\Loader\JSONLoader;

use function BenTools\ETL\extractFrom;

$executor = extractFrom(function () {
    yield ['firstName' => 'Barack', 'lastName' => 'Obama'];
    yield ['firstName' => 'Donald', 'lastName' => 'Trump'];
    yield ['firstName' => 'Joe', 'lastName' => 'Biden'];
})
    ->transformWith(fn (array $item) => implode(' ', array_values($item)))
    ->loadInto(new JSONLoader())
    ->onTransform(function (TransformEvent $event) {
        if ('Donald Trump' === $event->transformResult->value) {
            $event->state->skip();
        }
    });

$report = $executor->process();

dump($report->output); // string '["Barack Obama", "Joe Biden"]'

Or:

$report = $executor->process(destination: 'file:///tmp/presidents.json');
var_dump($report->output); // string 'file:///tmp/presidents.json' - content has been written here

You get the point. Now you're up to write your own workflows!

Continue reading the Getting Started Guide.

Contribute

Contributions are welcome! Don't hesitate to suggest recipes.

This library is 100% covered with Pest tests.

Please ensure to run tests using the command below and maintain code coverage before submitting PRs.

composer ci:check

License

MIT.

More Repositories

1

freddie

A Mercure Hub, written in PHP (8.1 + ReactPHP)
PHP
94
star
2

cartesian-product

PHP - A simple, low-memory footprint function to generate all combinations from a multi-dimensionnal array.
PHP
82
star
3

webpush-bundle

Symfony Bundle: Send WebPush Notifications to your users.
PHP
65
star
4

string-combinations

A simple, low-memory footprint function to generate all string combinations from a series of characters.
PHP
29
star
5

meiliweb

A user interface for your Meilisearch instances.
Vue
27
star
6

php-iterable-functions

Provides functions for iterable variables: iterable_map(, iterable_filter(), iterable_to_array(), ...
PHP
23
star
7

mercure-php-hub

A PHP Implementation of the Mercure Hub protocol.
PHP
22
star
8

natural-cron-expression

A parser that converts natural language to a cron expression
PHP
19
star
9

guzzle-throttle-middleware

A Guzzle 6+ Middleware that can delay requests before sending them.
PHP
15
star
10

doctrine-native-enums

Support for PHP 8.1 enums in Doctrine.
PHP
14
star
11

querystring

PHP 7.1+ Query String manipulation library. No dependency, immutable, lightweight, PSR-7 compliant.
PHP
13
star
12

where

PHP7.1 Fluent, immutable SQL query builder.
PHP
12
star
13

webpush-js

Javascript WebPush Notifications client.
JavaScript
9
star
14

split-test-analyzer

Bayesian probability calculator for split testing / AB testing.
PHP
8
star
15

webpack-encore-resolver

Port of Webpack Encore's Twig functions in vanilla PHP.
PHP
5
star
16

bentools-pager

A simple pager class with delta management
PHP
5
star
17

doctrine-ulid

ULID support for Doctrine ORM
PHP
4
star
18

bentools-arraytools

Some extra functions to work with arrays.
PHP
4
star
19

uri-factory

PSR-17 compliant PSR-7 Uri factory
PHP
4
star
20

bentools-specification

PHP7.0+ implementation of the Specification Pattern.
PHP
4
star
21

rewindable-generator

Uncaught Exception: Cannot traverse an already closed generator => NOT ANYMORE.
PHP
4
star
22

currency

Easy currency management in PHP.
PHP
3
star
23

funnel-http-client

Handle Rate Limits within Symfony Http Client.
PHP
3
star
24

simple-dbal

Unified OOP API for PDO/Mysqli.
PHP
3
star
25

shh

A small package to handle secrets.
PHP
3
star
26

picker

Helps you pick a random item with weight management.
PHP
3
star
27

safe-sync-transport

Safer Symfony Messenger sync:// transport.
PHP
3
star
28

doctrine-safe-events

Fires postPersist / postUpdate / postRemove events AFTER the transaction has completed.
PHP
2
star
29

crontab-bundle

Generate a crontab based on the project directory.
PHP
2
star
30

meilisearch-filters-php

PHP
2
star
31

bentools-pusher

PHP Asynchronous Push Notification management
PHP
2
star
32

meilisearch-filters

Expression builder for Meilisearch filters.
TypeScript
2
star
33

shh-bundle

A Symfony bundle to handle secrets.
PHP
2
star
34

psr6-redis-adapter

Provides a basic PSR-6 implementation for Redis. Needs ext-redis.
PHP
2
star
35

containeraware-bundle

Symfony Bundle: A ContainerAware compiler pass to automatically inject your service container.
PHP
2
star
36

doctrine-static

Mock managers and repositories in simple arrays, without any database.
PHP
2
star
37

flatten-iterator

Flattens Traversable or arrays into one iterator.
PHP
2
star
38

helpfultraits

Some nice traits to use with Symfony.
PHP
1
star
39

sql-sorter

Use the power of SQL to sort data.
PHP
1
star
40

opencubes

PHP
1
star
41

doctrine-watcher

Watch changes in your Doctrine entities to let you trigger custom events.
PHP
1
star
42

set

PHP version of Javascript's "new Set()".
PHP
1
star
43

redis-psr6-ttl-aware-adapter

Override of Symfony PSR6 cache RedisAdapter, retrieving expiration on an existing item.
PHP
1
star
44

match-operator

Javascript port of PHP's match() control structure.
JavaScript
1
star
45

guzzle-queue-handler

A queue handler to process Guzzle 6+ requests within a work queue.
PHP
1
star
46

guzzle-duration-middleware

PHP - A GuzzleHTTP Middleware that adds a X-Request-Duration header to all responses to monitor response times.
PHP
1
star
47

oauth2-qivivo

Qivivo OAuth 2.0 Client Provider for The PHP League OAuth2-Client
PHP
1
star
48

simple-cli

A lightweight CLI helper, with almost no dependency.
PHP
1
star
49

qivivo-php

Unofficial PHP client for Qivivo Thermostat API
PHP
1
star
50

bentools-csviterator

A simple way to iterate over a CSV file.
PHP
1
star
51

doctrine-watcher-bundle

Symfony Bundle for bentools/doctrine-watcher
PHP
1
star
52

psr7-request-matcher

A PSR-7 RequestMatcher interface for use into several projects.
PHP
1
star
53

cpimport-bundle

Symfony Bundle - Use file watchers with MariaDb Columnstore CpImport utility
PHP
1
star
54

bentools-pusher-bundle

Symfony bridge for bentools/pusher
PHP
1
star
55

guzzle-queued

Queues asynchronous requests, handled by workers.
PHP
1
star
56

psr7-js

Javascript URI and Query String manipulation, inspired by PHP's PSR-7.
JavaScript
1
star
57

doctrine-popo-tracker

Track changes to your Doctrine Plain Old PHP Objects (e.g. not entities).
PHP
1
star
58

violin

Manipulate your strings with no wrong note.
PHP
1
star