Logo of php-etl
Getting Started
🐘 Standalone 🎵 Symfony 🦢 Sylius
Core Concepts
The Concept Execution Context Item Types Custom Operations Glossary FAQ
⛓️ Operations
Building Blocks
Split Merge Repeat Safe
Extract
File Finder CSV JSON
Transform
External File Processor Filter Data Rule Transformer Split Item HTTP Client Log Callback
Aggregation
Simple Grouping
Load
CSV JSON
🧑‍🍳 Cookbook
Without Context
Grouping / Aggregation Filtering Splitting/Forking Making your chains configurable Complex data to csv / Flatten Data Api to CSV N°1 Api to CSV N°2 Sub chains
With Context
Api to CSV Import external file
Custom Operations

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']"

Network

GitHub Repo Issues Good First Issues

Help Preserve This Project

Support for the continued development of php ETL. I maintain this project in my free time.

Support
Free & Open Source (MIT)