wizaplace / php-etl
Extract, Transform and Load data using this PHP written migration library.
Installs: 59 936
Dependents: 1
Suggesters: 0
Security: 0
Stars: 69
Watchers: 6
Forks: 82
Open Issues: 7
Requires
- php: ~8.1
- softcreatr/jsonpath: ^0.7.2
Requires (Dev)
- ext-json: *
- ext-pdo: *
- ext-pdo_sqlite: *
- ext-xmlreader: *
- friendsofphp/php-cs-fixer: ^3.4
- infection/infection: >=0.15
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.100
- phpstan/phpstan-deprecation-rules: ^0.12.6
- phpstan/phpstan-strict-rules: ^0.12.11
- phpunit/phpunit: >=8
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-PDO: Required for various extractors and loaders. Most users will want this.
- ext-json: Required for JSON extractor and JSON Encode/Decode transformers.
- ext-pdo_mysql: Required to work with MySQL databases.
- ext-pdo_pgsql: Required to work with PostgreSQL databases.
- ext-pdo_sqlite: Required to work with SQLite databases.
- ext-pdo_sqlsrv: Required to work with MS SQL Server databases.
- ext-xmlreader: Required for XML extractor.
This package is auto-updated.
Last update: 2024-11-14 18:19:35 UTC
README
Extract, Transform and Load data using PHP. This library provides classes and a workflow to allow you to extract data from various sources (CSV, DB...), one or many, then transform them before saving them in another format.
You can also easily add your custom classes (Extractors, Transformers and Loaders).
Versions and compatibility
- To benefit from the latest features and if you use PHP 8.1 and above: use the 2.3 version (and above) of the library.
- If you use older versions of PHP: 7.4 or 8.0, use the 2.2 version of the library.
- If you use older versions of PHP: 7.2 <= PHP <= 7.4, use the legacy 1.3.x version.
Changelog
See the changelog here
Installation
In your application's folder, run:
composer require wizaplace/php-etl
Example 🚈
In the example below, we will extract data from a csv file, trim white spaces from the name and email columns and then insert the values into the users table:
use Wizaplace\Etl\Etl; use Wizaplace\Etl\Extractors\Csv; use Wizaplace\Etl\Transformers\Trim; use Wizaplace\Etl\Loaders\Insert; use Wizaplace\Etl\Database\Manager; use Wizaplace\Etl\Database\ConnectionFactory; // Get your database settings : $config = [ 'driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'database' => 'myDatabase', 'username' => 'foo', 'password' => 'bar', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', ]; // Instanciate all the components (manually or automatically with DI) $manager = new Manager(new ConnectionFactory()); $manager->addConnection($config); $etl = new Etl(); $extractor = new Csv(); $transformer = new Trim(); $loader = new Insert($manager); $etl->extract($extractor, '/path/to/users.csv') ->transform( $transformer, [Step::COLUMNS => ['name', 'email']] ) ->load($loader, 'users') ->run();
The library is fully compatible with any PHP project. For instance, with Symfony, you can fully benefit from the autowiring. On the following example, you enable it on the main ETL object, with the shared parameter to false in order to have the possibility to get different instance of the ETL (optional).
services.yaml
Wizaplace\Etl\Etl: shared: false
Documentation 📓
The documentation is available in a subfolder of the repo, here.
License
WP-ETL is licensed under the MIT license.
Origin of the project
This project is a fork and an improvement of the marquine/php-etl project by Leonardo Marquine.