-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourceWatcher1.php
35 lines (28 loc) · 1.33 KB
/
SourceWatcher1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
include __DIR__ . "/../includes/cli-execution-only.php";
require_once __DIR__ . "/../../vendor/autoload.php";
use Coco\SourceWatcher\Core\Database\Connections\MySqlConnector;
use Coco\SourceWatcher\Core\IO\Inputs\FileInput;
use Coco\SourceWatcher\Core\IO\Outputs\DatabaseOutput;
use Coco\SourceWatcher\Core\SourceWatcher;
use Coco\SourceWatcher\Core\SourceWatcherException;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable( __DIR__ . "/../../" );
$dotenv->load();
$mysqlConnector = new MySqlConnector();
$mysqlConnector->setUser( $_ENV["UNIT_TEST_MYSQL_USERNAME"] );
$mysqlConnector->setPassword( $_ENV["UNIT_TEST_MYSQL_PASSWORD"] );
$mysqlConnector->setHost( $_ENV["UNIT_TEST_MYSQL_HOST"] );
$mysqlConnector->setPort( $_ENV["UNIT_TEST_MYSQL_PORT"] );
$mysqlConnector->setDbName( $_ENV["UNIT_TEST_MYSQL_DATABASE"] );
$mysqlConnector->setTableName( "people" );
$sourceWatcher = new SourceWatcher();
try {
$sourceWatcher
->extract( "Csv", new FileInput( __DIR__ . "/../data/csv/csv1.csv" ), [ "columns" => [ "name", "email" ] ] )
->transform( "RenameColumns", [ "columns" => [ "email" => "email_address" ] ] )
->load( "Database", new DatabaseOutput( $mysqlConnector ) )
->run();
} catch ( SourceWatcherException $exception ) {
echo sprintf( "Something unexpected went wrong: %s", $exception->getMessage() );
}