2017 © Pedro Peláez
 

library feed-csv-writer

This package contains the implementation to write a CSV feed.

image

widefocus/feed-csv-writer

This package contains the implementation to write a CSV feed.

  • Saturday, April 29, 2017
  • by sjokki
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WideFocus Feed Csv Writer

Build Status Latest Stable Version License, (*1)

This package contains models to write a CSV feed., (*2)

Installation

Use composer to install the package., (*3)

$ composer require widefocus/feed-csv-writer

Usage

First create a writer factory:, (*4)

<?php

use WideFocus\Feed\CsvWriter\CsvWriterFactory;
use WideFocus\Feed\CsvWriter\LeagueCsv\LeagueCsvWriterFactory;
use League\Flysystem\MountManager;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;

$mountManager = new MountManager(
    ['local' => new Filesystem(new Local('/tmp'))]
);

$writerFactory = new CsvWriterFactory(
    new LeagueCsvWriterFactory(),
    $mountManager
);

Then create a writer based on parameters and fields:, (*5)

<?php

use WideFocus\Parameters\ParameterBag;
use WideFocus\Feed\Writer\WriterField;

$parameters = new ParameterBag([
    'destination' => 'local://my-feed.csv',
    'include_header' => true
]);

$writer = $writerFactory->create(
    $parameters,
    new WriterField('foo', 'Foo'),
    new WriterField('bar', 'Bar', 'strtoupper')
);

Then write the feed:, (*6)

<?php

use ArrayIterator;
use ArrayObject;

$items = new ArrayIterator(
    [
        new ArrayObject(['foo' => 'FooValue', 'bar' => 'BarValue']),
        new ArrayObject(['foo' => 'AnotherFooValue', 'bar' => 'AnotherBarValue'])
    ]
);

$writer->write($items);

This would result in a file /tmp/my-feed.csv with the following contents:, (*7)

Foo,Bar
FooValue,BARVALUE
AnotherFooValue,ANOTHERBARVALUE

The Versions

29/04 2017

dev-master

9999999-dev

This package contains the implementation to write a CSV feed.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ashoka de Wit

29/04 2017

1.0.0

1.0.0.0

This package contains the implementation to write a CSV feed.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ashoka de Wit