widefocus/feed-writer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

widefocus/feed-writer

Composer 安装命令:

composer require widefocus/feed-writer

包简介

This package contains models to write a feed.

README 文档

README

Build Status Latest Stable Version License

This package contains models to write a feed.

Installation

Use composer to install the package.

$ composer require widefocus/feed-writer

Usage

This package is meant to be used as basis for feed writer implementations. To do so a writer needs to be implemented.

Writer

The writer processes feed data.

<?php

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()
    {
    }
}

Writing the feed

The writer expects an iterator as it's input. The iterator is expected to contain items that implement the ArrayAccess interface.

<?php

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

This would result in the following output:

Foo: FooValue
Bar: BARVALUE
Foo: AnotherFooValue
Bar: ANOTHERBARVALUE

统计信息

  • 总下载量: 75
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固