leomarquine / php-etl

Extract, Transform and Load data using PHP.
MIT License
178 stars 81 forks source link

Can commands be PHP function callbacks? #3

Closed stevevance closed 7 years ago

stevevance commented 7 years ago

Hi, I really like php-etl! It has made it really easy for me to fetch JSON data through APIs without me having to build my own interpreter. It saved me a couple of days already!

I would like to run a PHP function as a callback when an ETL job has finished, I, instead of as a command (which is a shell command).

Is there a way to do this?

leomarquine commented 7 years ago

Hi, @stevevance.

You can make a custom utility step class that implements Marquine\Etl\Utilities\UtilityInterface.

To use your custom step, do:

$job->utility(My\Custom\Utility::class, $options);

and the handle method will be called.

Also, if you need, you can make custom extractors, transformers and loaders.

stevevance commented 7 years ago

What does $job->utility send to My\Custom\Utility::class? Would My\Custom\Utility::class have access to all of the properties of the $job class, like $job->get() for the $items?

leomarquine commented 7 years ago

The handle method in your class will be called without any parameters.

You can see what is passed to another steps here: https://github.com/leomarquine/php-etl/blob/master/src/Job.php