@@ -15,46 +15,96 @@ composer require camillebaronnet/php-etl
15
15
16
16
## Usage
17
17
18
+ This example extract some Github's repositories, apply some transformations
19
+
18
20
``` php
19
21
<?php
20
22
21
- namespace App;
22
-
23
+ use Camillebaronnet\ETL\Etl;
23
24
use Camillebaronnet\ETL\Extractor\Http;
24
- use Camillebaronnet\ETL\Strategy\LayerStrategy ;
25
+ use Camillebaronnet\ETL\Loader\DebugLoader ;
25
26
use Camillebaronnet\ETL\Transformer\DateTime;
26
- use Camillebaronnet\ETL\Loader\Json ;
27
+ use Camillebaronnet\ETL\Transformer\Decode ;
27
28
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
+ ]
34
48
])
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',
37
53
])
38
- ->transform(DateTime::class, ['format' => 'd/m/Y', 'fields' => ['createAt']])
39
54
;
40
55
41
- echo $etl->load(Json ::class);
56
+ $etl->process(DebugLoader ::class);
42
57
43
- //...
44
58
```
45
59
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 |
47
99
48
- <img src =" docs/diagram.svg " >
49
100
50
101
## Extendable
51
102
52
103
You can easily create your own custom Extractors,
53
104
Transformers, Loader or Strategy by implementing the corresponding interface.
54
105
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 )
59
109
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 )
0 commit comments