Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Improve recipes documentation #22

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,50 @@ $etl = (new EtlExecutor())

This will basically listen to all events and fire log entries.

### Creating your own recipes
You can create your own recipes by implementing `BenTools\ETL\Recipe\Recipe` or using a callable with the same signature.

Example for displaying a progress bar when using the Symfony framework:

```php
use BenTools\ETL\EtlExecutor;
use BenTools\ETL\EventDispatcher\Event\Event;
use BenTools\ETL\Recipe\Recipe;
use Symfony\Component\Console\Helper\ProgressBar;

final class ProgressBarRecipe extends Recipe
{
public function __construct(
public readonly ProgressBar $progressBar,
) {
}

public function decorate(EtlExecutor $executor): EtlExecutor
{
return $executor
->onStart(function (Event $event) {
if (!$event->state->nbTotalItems) {
return;
}
$this->progressBar->setMaxSteps($event->state->nbTotalItems);
})
->onExtract(fn () => $this->progressBar->advance())
->onEnd(fn () => $this->progressBar->finish());
}
}
```

Usage:

```php
use BenTools\ETL\EtlExecutor;
use Symfony\Component\Console\Style\SymfonyStyle;

$output = new SymfonyStyle($input, $output);
$progressBar = $output->createProgressBar();
$executor = (new EtlExecutor())->withRecipe(new ProgressBarRecipe());
```

Contribute
----------

Expand Down
Loading