1. Go to this page and download the library: Download widefocus/feed-writer 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/ */
widefocus / feed-writer example snippets
use WideFocus\Feed\Writer\WriterInterface;
use WideFocus\Feed\Writer\WriterFieldInterface;
use WideFocus\Feed\Writer\WriterTrait;
class DebugWriter implements WriterInterface
{
use WriterTrait;
/**
* @var WriterFieldInterface[]
*/
private $fields;
/**
* Constructor.
*
* @param WriterFieldInterface[] $fields
*/
public function __construct(array $fields)
{
$this->fields = $fields;
}
/**
* Write an item to the feed.
*
* @param ArrayAccess $item
*
* @return void
*/
protected function writeItem(ArrayAccess $item)
{
foreach ($this->fields as $field) {
echo sprintf(
"%s: %s\n",
$field->getLabel(),
$field->getValue($item)
);
}
}
/**
* Initialize the feed.
*
* @return void
*/
protected function initialize()
{
}
/**
* Finish the feed.
*
* @return void
*/
protected function finish()
{
}
}
use WideFocus\Feed\Writer\WriterField;
$items = new ArrayIterator(
[
new ArrayObject(['foo' => 'FooValue', 'bar' => 'BarValue']),
new ArrayObject(['foo' => 'AnotherFooValue', 'bar' => 'AnotherBarValue'])
]
);
$fields = [
new WriterField('foo', 'Foo'),
new WriterField('bar', 'Bar', 'strtoupper')
];
$writer = new DebugWriter($fields);
$writer->write($items);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.