widefocus/feed-csv-writer
Composer 安装命令:
composer require widefocus/feed-csv-writer
包简介
This package contains the implementation to write a CSV feed.
README 文档
README
This package contains models to write a CSV feed.
Installation
Use composer to install the package.
$ composer require widefocus/feed-csv-writer
Usage
First create a writer factory:
<?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:
<?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:
<?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:
Foo,Bar
FooValue,BARVALUE
AnotherFooValue,ANOTHERBARVALUE
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-19