Skip to content

Commit 4f664b0

Browse files
committed
Update loaders documentation
1 parent 78f6be4 commit 4f664b0

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

docs/Loaders/README.md

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Loaders are the data outputs of etl. They can be used multiple times in the same
66
$etl->load('type', $destination, $options);
77
```
88

9+
910
## Available loaders types
1011

1112
* [Insert](Insert.md)
@@ -14,52 +15,42 @@ $etl->load('type', $destination, $options);
1415

1516
## Custom loader
1617

17-
If you want to make your own custom loader, you need to create a class that implements the `LoaderInterface`.
18+
To make a custom loader, you need to create a class that extends the base loader `Marquine\Etl\Loaders\Loader`.
19+
20+
The `load` method must return a callback that will handle the data load when the ETL process run. For each iteration, the callback will receive the current row to perform the load process and then return the row.
21+
22+
Properties that can be configured as options must be in the `availableOptions` array.
23+
1824
```php
19-
use Marquine\Etl\Loaders\LoaderInterface;
25+
use Marquine\Etl\Loaders\Loader;
2026

21-
class CustomLoader implements LoaderInterface
27+
class CustomLoader extends Loader
2228
{
29+
/**
30+
* Properties that can be set via the options method.
31+
*
32+
* @var array
33+
*/
34+
protected $availableOptions = [
35+
//
36+
];
37+
2338
/**
2439
* Get the loader handler.
2540
*
26-
* @param \Marquine\Etl\Pipeline $pipeline
27-
* @param string $destination
41+
* @param mixed $destination
2842
* @return callable
2943
*/
30-
public function handler(Pipeline $pipeline, $destination);
44+
public function load($destination)
45+
{
46+
//
47+
}
3148
}
3249
```
3350

34-
### Loader handler
35-
The `handler` method will receive the `Pipeline` instance and the `destination`. The method must return a callback that will receive a `$row` and a `$metadata` variable. This callback will execute the load process for each row at a time.
36-
```php
37-
/**
38-
* Get the loader handler.
39-
*
40-
* @param \Marquine\Etl\Pipeline $pipeline
41-
* @param string $destination
42-
* @return callable
43-
*/
44-
public function handler(Pipeline $pipeline, $destination)
45-
{
46-
// ...
47-
48-
return function ($row, $metada) {
49-
// load data to destination
50-
};
51-
}
52-
```
53-
54-
### Setting options
55-
Any pulic property can be set by the options argument of the step. For example, to set the `columns` public property of the loader to `['name', 'email']`:
56-
```php
57-
$options = ['columns' => ['name', 'email']];
58-
```
59-
6051
### Using the loader
61-
You can create a new instance of the loader or provide its class string and we will try to resolve any possible dependency:
52+
You can make a new instance of the loader or provide its class string and we will try to resolve any possible dependency:
6253
```php
63-
$etl->load(new CustomLoader, 'destination', $options);
64-
$etl->load(CustomLoader::class, 'destination', $options);
54+
$etl->transform(new CustomLoader, $options);
55+
$etl->transform(CustomLoader::class, $options);
6556
```

0 commit comments

Comments
 (0)