PHP code example of jackal / copycat

1. Go to this page and download the library: Download jackal/copycat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jackal / copycat example snippets



$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');

$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);


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

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