Skip to content

Commit c11b69f

Browse files
Create a single powerful strategy, improve documentation and split HTTP into HTTP extractor + Decode transformer
1 parent 8de6aa8 commit c11b69f

39 files changed

+515
-563
lines changed

README.md

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,96 @@ composer require camillebaronnet/php-etl
1515

1616
## Usage
1717

18+
This example extract some Github's repositories, apply some transformations
19+
1820
```php
1921
<?php
2022

21-
namespace App;
22-
23+
use Camillebaronnet\ETL\Etl;
2324
use Camillebaronnet\ETL\Extractor\Http;
24-
use Camillebaronnet\ETL\Strategy\LayerStrategy;
25+
use Camillebaronnet\ETL\Loader\DebugLoader;
2526
use Camillebaronnet\ETL\Transformer\DateTime;
26-
use Camillebaronnet\ETL\Loader\Json;
27+
use Camillebaronnet\ETL\Transformer\Decode;
2728
use Camillebaronnet\ETL\Transformer\Flatten;
28-
29-
//...
30-
31-
$etl = (new LayerStrategy)
32-
->extract(Http::class, [
33-
'url' => 'https://api.github.com/users/camillebaronnet/repos'
29+
use Camillebaronnet\ETL\Transformer\Map;
30+
use Camillebaronnet\ETL\Transformer\Sleep;
31+
32+
$etl = (new Etl)
33+
->extract(Http::class, ['url' => 'https://api.github.com/users/camillebaronnet/repos'])
34+
->add(Decode::class)
35+
->add(Sleep::class, ['seconds' => .2])
36+
->add(Flatten::class, ['glue' => '_'])
37+
->add(Map::class, [
38+
'fields' => [
39+
'id',
40+
'name',
41+
'full_name' => 'fullName',
42+
'owner_login' => 'ownerLogin',
43+
'owner_url' => 'ownerUrl',
44+
'url',
45+
'ssh_url' => 'sshUrl',
46+
'created_at' => 'createdAt'
47+
]
3448
])
35-
->transform(Flatten::class, [
36-
'glue' => '_'
49+
->add(DateTime::class, [
50+
'fields' => ['createdAt'],
51+
'from' => 'Y-m-d\TH:i:s\Z',
52+
'to' => 'd/m/Y',
3753
])
38-
->transform(DateTime::class, ['format' => 'd/m/Y', 'fields' => ['createAt']])
3954
;
4055

41-
echo $etl->load(Json::class);
56+
$etl->process(DebugLoader::class);
4257

43-
//...
4458
```
4559

46-
## The different strategies
60+
## The process explained
61+
62+
- **EXTRACT :**
63+
Extract can output one or more items
64+
65+
- **TRANFORM :**
66+
A transform step takes the result of the previous
67+
step (extractor or transformer) apply an operation and optionally
68+
split the input into several subsets of items (example with [Decode](src/Transformer/Decode.php)).
69+
70+
- **LOADER :**
71+
A loader can by placed at the end of the pipeline or between transformers.
72+
Several Loader can be setting up.
73+
74+
## Collection
75+
76+
### Extractors
77+
78+
|Name |Description|
79+
|------|------|
80+
| [HTTP](src/Extractor/Http.php) | Simple wrapper for the libCurl |
81+
82+
### Transformers
83+
84+
|Name |Description|
85+
|------|------|
86+
| [Decode](src/Transformer/Decode.php) | Decode JSON, YAML, XML, CSV and more using Symfony's DecoderInterface |
87+
| [Map](src/Transformer/Map.php) | Rename, keep and remove some fields |
88+
| [Flatten](src/Transformer/Flatten.php) | Flattens a multi-dimensional collection into a single dimension |
89+
| [Trim](src/Transformer/Trim.php) | Strip whitespace from the beginning and end of a string |
90+
| [Sleep](src/Transformer/Sleep.php) | Delay execution |
91+
| [DateTime](src/Transformer/DateTime.php) | Parse/Convert dates |
92+
93+
94+
### Loaders
95+
96+
|Name |Description|
97+
|------|------|
98+
| [Debug](src/Loader/DebugLoader.php) | Display items in output |
4799

48-
<img src="docs/diagram.svg">
49100

50101
## Extendable
51102

52103
You can easily create your own custom Extractors,
53104
Transformers, Loader or Strategy by implementing the corresponding interface.
54105

55-
- [ExtractInterface](src/Extractor/ExtractInterface.php)
56-
- [TransformInterface](src/Transformer/TransformInterface.php)
57-
- [LoaderInterface](src/Loader/LoaderInterface.php), if you're using the LayerStrategy.
58-
- [StreamLoaderInterface](src/Loader/StreamLoaderInterface.php), if you're using the StreamStrategy.
106+
- [ExtractInterface](src/ExtractInterface.php)
107+
- [TransformInterface](src/TransformInterface.php)
108+
- [LoaderInterface](src/LoaderInterface.php)
59109

60-
You also can create a custom Strategy by implementing the [ETLInterface](src/ETLInterface.php).
110+
Submit yours. Send a [pull-request](https://github.com/camillebaronnet/php-etl-framework/compare)

docs/diagram.drawio

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/diagram.svg

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/ETLInterface.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@
1111
interface ETLInterface
1212
{
1313
/**
14-
* @param string $extractorClass
15-
* @param array $context
1614
* @return ETLInterface
1715
* @throws BadInterface
1816
*/
1917
public function extract(string $extractorClass, array $context = []): self;
2018

2119
/**
22-
* @param string $transformClass
23-
* @param array $context
2420
* @return ETLInterface
2521
* @throws BadInterface
2622
*/
27-
public function transform(string $transformClass, array $context = []): self;
23+
public function add(string $transformerOrLoaderClass, array $arguments = []): self;
2824

2925
/**
30-
* @param string $loadClass
31-
* @param array|null $context
3226
* @return mixed
3327
* @throws BadInterface
3428
*/
35-
public function load(string $loadClass, array $context = []);
29+
public function process(?string $loadClass = null, ?array $context = []);
3630
}

0 commit comments

Comments
 (0)