You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
18
24
```php
19
-
use Marquine\Etl\Loaders\LoaderInterface;
25
+
use Marquine\Etl\Loaders\Loader;
20
26
21
-
class CustomLoader implements LoaderInterface
27
+
class CustomLoader extends Loader
22
28
{
29
+
/**
30
+
* Properties that can be set via the options method.
31
+
*
32
+
* @var array
33
+
*/
34
+
protected $availableOptions = [
35
+
//
36
+
];
37
+
23
38
/**
24
39
* Get the loader handler.
25
40
*
26
-
* @param \Marquine\Etl\Pipeline $pipeline
27
-
* @param string $destination
41
+
* @param mixed $destination
28
42
* @return callable
29
43
*/
30
-
public function handler(Pipeline $pipeline, $destination);
44
+
public function load($destination)
45
+
{
46
+
//
47
+
}
31
48
}
32
49
```
33
50
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
-
60
51
### 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:
0 commit comments