2017 © Pedro Peláez
 

library lib-import

Import library of the Ride framework

image

ride/lib-import

Import library of the Ride framework

  • Thursday, October 13, 2016
  • by ride-user
  • Repository
  • 9 Watchers
  • 0 Stars
  • 2,238 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 2 % Grown

The README.md

Ride: Import Library

Import library of the PHP Ride framework., (*1)

This module can perform imports from one source to another., (*2)

Code Sample

Check this code sample to see the possibilities of this library:, (*3)

<?php

use ride\library\decorator\BooleanDecorator;
use ride\library\import\mapper\GenericMapper;
use ride\library\import\provider\csv\CsvSourceProvider;
use ride\library\import\provider\csv\CsvDestinationProvider;
use ride\library\import\GenericImporter;
use ride\library\system\file\File;

function importFile(File $sourceFile, File $destinationFile) {
    // initialize source provider
    $sourceProvider = new CsvSourceProvider($sourceFile);
    // column index 0 shall be called name
    $sourceProvider->setColumnName(0, 'name');
    // column index 1 shall be called firstname
    $sourceProvider->setColumnName(1, 'firstname');
    $sourceProvider->setColumnName(2, 'street');
    $sourceProvider->setColumnName(3, 'number');
    $sourceProvider->setColumnName(4, 'box');
    $sourceProvider->setColumnName(5, 'postalCode');
    $sourceProvider->setColumnName(6, 'city');
    $sourceProvider->setColumnName(7, 'subscribe_newsletter');
    // if the first row has the column names, you can use those instead of mapping everything manually
    $sourceProvider->readColumnNames();

    // initialize destination provider
    $destinationProvider = new CsvDestinationProvider($destinationFile);
    // column index 0 shall be called fullName
    $destinationProvider->setColumnName(0, 'fullName');
    $destinationProvider->setColumnName(1, 'address');
    $destinationProvider->setColumnName(3, 'postalCode');
    $destinationProvider->setColumnName(4, 'city');
    $destinationProvider->setColumnName(5, 'isNewsletter');

    // create a mapping to translate values from the source to the destination
    $mapper = new GenericMapper();
    $mapper->mapColumn(array('name', 'firstname'), 'fullName');
    // glue street, number and box together; use a space between street and number, then use a slash to add the box
    $mapper->mapColumn(array('street', 'number', 'box'), 'address', array(' ', '/'));
    $mapper->mapColumn('postalCode', 'postalCode');
    $mapper->mapColumn('city', 'city');
    $mapper->mapColumn('subscribe_newsletter', 'isNewsletter');
    // you can add decorators to process the resulting value
    $mapper->addDecorator('isNewsletter', new BooleanDecorator());

    // initialize importer with providers and mapper
    $importer = new GenericImporter();
    $importer->setSourceProvider($sourceProvider);
    $importer->setDestinationProvider($destinationProvider);
    $importer->addMapper($mapper);

    $importer->import();
}

Installation

You can use Composer to install this library., (*4)

composer require ride/lib-import

The Versions

13/10 2016

dev-master

9999999-dev

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

13/10 2016

dev-develop

dev-develop

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

13/10 2016

1.0.0

1.0.0.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

11/12 2015

0.4.0

0.4.0.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

24/07 2015

0.3.1

0.3.1.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

24/06 2015

0.3.0

0.3.0.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

20/12 2014

0.2.5

0.2.5.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

26/11 2014

0.2.4

0.2.4.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

25/11 2014

0.2.3

0.2.3.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

07/11 2014

0.2.2

0.2.2.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

07/11 2014

0.2.1

0.2.1.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

07/11 2014

0.2.0

0.2.0.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

06/11 2014

0.1.0

0.1.0.0

Import library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd