PHP-ETL - Cook Books
Making your chains configurable

You are able to configure through the input the names of the files that are being read.

$chainProcessor->process(
    new ArrayIterator([__DIR__ . "/customers.csv"]),
    []
);

But we might need to configure some operations independently from the input. For example the name of the csv output file.

write-new-file:
  operation: csv-write
  options:
    file: "output.csv"

The name “output.csv” is hardcoded here. But we can make this dynamic with symfony expression language. We will need to start our line with the ! character.

write-new-file:
  operation: csv-write
  options:
    file: "!filewriter['outputfile']['name']"

We will also need to give this informaton when the chain is being created:

🐘 Standalone

$inputOptions = ['filewriter' =>
    ['outputfile' =>
        ['name' => 'configured-output.csv']
    ]
];

$chainProcessor = $builder->buildChainProcessor(
    Yaml::parse(file_get_contents($fileName))['chain'],
    $inputOptions
);

🎵 Symfony

./bin/console etl:execute myetl "['./customers.csv']" "{'outputfile': {'name': 'configured-output.csv'}}"

Complete Code

chain:
  read-file:
    operation: csv-read
    options: [] # The default delimeter,&

  keep-only-name-and-subscription:
    operation: rule-engine-transformer
    options:
      add: false # We want to replace all existing columns with our new columns.
      columns:
        Name:
          rules:
            - implode: # Concat both firstname & lastname
                values:
                  - [{get : {field: 'FirstName'}}]
                  - [{get : {field: "LastName"}}]
                with: " "
        SubscriptionStatus:
          rules:
            - get: {field: 'IsSubscribed'}

  write-new-file:
    operation: csv-write
    options:
      file: "!filewriter['outputfile']['name']"