2017 © Pedro Peláez
 

library copycat

image

jackal/copycat

  • Saturday, July 28, 2018
  • by lucajackal85
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

CopyCat

A simple PHP to "copy" data from one source to another, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Scrutinizer Code Quality codecov, (*2)

Requirement

PHP >= 5.6, (*3)

Getting Started

Install library with composer, (*4)

composer require jackal/copycat

Usage

Basic example: from array to sql insert statement

require_once __DIR__.'/vendor/autoload.php';
$reader = new \Jackal\Copycat\Reader\ArrayReader([
    ['col1' => 'value1','col2' => 'value2'],
    ['col1' => 'value3','col2' => 'value4'],
    /*...*/
]);

$workflow = new \Jackal\Copycat\Workflow($reader);
$workflow->addWriter(new \Jackal\Copycat\Writer\SQLFileWriter('test_table','test_table.sql'));
$workflow->process();

echo file_get_contents(__DIR__.'/test_table.sql');

From array to array

$reader = new \Jackal\Copycat\Reader\ArrayReader([
    ['value1'],
    ['value2'],
    /*...*/
]);

$workflow = new \Jackal\Copycat\Workflow($reader);
$workflow->addWriter(new \Jackal\Copycat\Writer\ArrayWriter($outputArray));

$workflow->process();

var_dump($outputArray);

Filters

With Filters you can apply logic to exclude certain values from the output., (*5)

/*[...]*/
/*Define wich column to apply filter*/
$workflow->addFilter(new NotBlankFilter('col1'));
/*[...]*/

Filters are callable objects, you can define your own filter, (*6)

/*[...]*/
/*Define custom filter*/
$workflow->addFilter(function($values){
    return $values['col1'] > 0;
});
/*[...]*/

Converter

With Converter you can modify values to the output., (*7)

/*[...]*/
/*Define custom filter*/
$workflow->addConverter(new DatetimeToStringConverter('col1'));
/*[...]*/

You can set your own converter, (*8)

/*[...]*/
//apply custom converter
$workflow->addConverter(function ($values){
    foreach ($values as &$value) {
        if ($value == 'to convert') {
            $value = 'converted';
        }
    }
    return $values;
});
/*[...]*/

Sorting

Is it possible to sort output values, (*9)

/*[...]*/
//add sorter
$workflow->addSorter(new AscendingSorter('col1'));
/*[...]*/

If you want to sort values basing on multiple columns, you can just add multiple params. Use with care! this method could create performance issues on large input data, (*10)

/*[...]*/
//add sorter
$workflow->addSorter(new AscendingSorter('col1','col2','col3',/*...*/));
/*[...]*/

Authors

  • Luca Giacalone (AKA JackalOne)

License

This project is licensed under the MIT License, (*11)

The Versions

28/07 2018

dev-master

9999999-dev

  Sources   Download

The Development Requires

by Luca

28/07 2018

0.1.1

0.1.1.0

  Sources   Download

The Development Requires

by Luca

19/07 2018

0.1

0.1.0.0

  Sources   Download

The Development Requires

by Luca