jenwachter/data-encoder
最新稳定版本:0.3
Composer 安装命令:
composer require jenwachter/data-encoder
包简介
A PHP library to make it easier to create XML using the DOM Document object.
关键字:
README 文档
README
Eventually this library will be built out to do various types of data encoding. For now, only XML and RSS are available.
XML Example
Start out with an array of data structured the way you want the XML to be structured. Keep in mind that groups of objects should be included like the below array of "posts" where the key is the plural.
$data = array( "something" => "something", "posts" => array( array( "title" => "This is the title", "author" => array( "firstName" => "John", "lastName" => "Smith" ), "url" => "http://www.somewebsite.com/path/to/article" ), array( "title" => "This is the title of another article", "author" => array( "firstName" => "Jane", "lastName" => "Doe" ), "url" => "http://www.somewebsite.com/path/to/this/article" ) ) );
Then create a new XML Encoder object, passing it the array of data. After that, it's as easy as calling the render() method.
$xml = new \DataEncoder\XML($data); $xml->render();
RSS Example
The process for creating an RSS feed is a bit different, as RSS feeds have very specific requirements. When instantiating a new RSS Encoder, there are three required and one optional parameter. For this example, I'll show the method calls and then describe each parameter.
$xml = new \DataEncoder\RSS($channelElements, $itemElements, $data, $dataMap); $xml->render();
$channelElements
An associative array of channel elements. Please note that per RSS specification, "title," "link," and "description" elements are required. Optional elements include "lastBuildDate," "language," etc...
$channelElements = array( "title" => "The Title of my feed", "link" => "http://www.google.com", "description" => "The description of my feed", "lastBuildDate" => 1361242244 );
$itemElements
To prevent a whole lot of processing before even instantiating the RSS Encoder to only pass the fields you want to include in the feed, the second parameter allows you to pick and choose which elements you want to include. Please note that these values correspond to the $dataMap array first and then to the item keys passed in through $data.
$itemElements = array("id", "title", "description", "link", "comments", "pubDate");
$data
An array of items in the feed.
$data = array( array( "title" => "This is the title", "author" => array( "firstName" => "John", "lastName" => "Smith" ), "url" => "http://www.somewebsite.com/path/to/article" ), array( "title" => "This is the title of another article", "author" => array( "firstName" => "Jane", "lastName" => "Doe" ), "url" => "http://www.somewebsite.com/path/to/this/article" ) );
$dataMap
In further effort to prevent a lot of processing before even instantiating the RSS Encoder, the final (and optional) parameter is an associative array mapping fields in the items passed $data array to RSS-specific fields.
$dataMap = array( "headline" => "title", "body" => "description", "url" => "link", "publish_date" => "pubDate" );
jenwachter/data-encoder 适用场景与选型建议
jenwachter/data-encoder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.46k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2013 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「rss」 「dom document」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jenwachter/data-encoder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jenwachter/data-encoder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jenwachter/data-encoder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library that provides basic utilities for creating HTML documents.
A bridge between SimpleXML and the DOM extension, plus a bunch of convenience methods
BigPipe: Pipelining web pages for high performance built in PHP.
Load DOM document safety
Import an RSS-feed into blog
Added a method to Laravel response for handling xml response and also converting Eloquent return to XML.
统计信息
- 总下载量: 16.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-18