承接 runopencode/sax 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

runopencode/sax

Composer 安装命令:

composer require runopencode/sax

包简介

XML SAX (JAVA like) parser

README 文档

README

Packagist Scrutinizer Code Quality Code Coverage Build Status Build Status

SensioLabsInsight

This library enables you to parse XML documents with SAX in Java style: instead of handling events by using these nasty functions and callbacks (see official PHP documentation example here), you can just inherit provided abstract class RunOpenCode\Sax\Handler\AbstractSaxHandler and implement all of its abstract methods.

Major benefit of using this library is clean, human-readable code.

Example:

class MySaxHandler extends RunOpenCode\Sax\Handler\AbstractSaxHandler {
    // ... your implementation 
}

$result = RunOpenCode\Sax\SaxParser::factory()->parse(new MySaxHandler(), $myXmlDocumentResource);

List of methods which you ought to implement:

  • onDocumentStart: executed when parsing started of XML document.
  • onElementStart: executed when parser stumbled upon new XML tag.
  • onElementData: executed when parser stumbled upon CDATA of some XML tag.
  • onElementEnd: executed when parser stumbled upon closed already opened XML tag.
  • onDocumentEnd: executed when parsing of XML document is done.
  • onParseError: executed when parsing error is triggered.
  • getResult: executed at very end of parsing process where you should provide a invoker with parsing results.

Since common usage of Sax parser is to have a stack of currently working elements, there is a prototype implementation of that as well in class RunOpenCode\Sax\Handler\AbstractStackedSaxHandler. It extends RunOpenCode\Sax\Handler\AbstractSaxHandler and provides you with possibility to get current working element via getCurrentElementName() as well as with stack size via getStackSize().

Important notes

  • Due to underlying implementation of PHP XML parser, all tag names in relevant event calls are provided uppercase. Per example, if you have tag <tag></tag>, in relevant event methods your check for tag name should be if ($name === 'TAG').
  • Event onParseError is due to unrecoverable parsing error, however, it is up to you and your use case weather you are going to trigger error continue with execution.
  • Event onElementData will trigger even if you have blank spaces only between tags in XML document.

SaxParser and StreamAdapterInterface

RunOpenCode\Sax\SaxParser is provided as utility class which ought to ease up your usage of your SaxHandler implementation. SaxHandler uses Psr\Http\Message\StreamInterface implementation as source of XML document for parsing, however, StreamAdapters can help you to work with various XML document sources, such as:

  • Resources (file resources or PHP native streams)
  • DOMDocument
  • SimpleXMLElement

If you need any other type of XML document source, you can provide it by implementing RunOpenCode\Sax\Contract\StreamAdapterInterface, and you can register it to RunOpenCode\Sax\SaxParser instance via SaxParser::addStreamAdapter() method call.

When you invoke SaxParser::parse(), before parsing, source of provided XML document will be checked against available adapters and converted to Psr\Http\Message\StreamInterface implementation.

This library recommends guzzlehttp/psr7 and uses it as default StreamInterface implementation, but you can use any other implementation that suits your need.

Changelog

February 21th, 2017.

  • BC break: Changed api, no more callback, invocation of parse() method should return parsing result.

February 10th, 2017.

  • Dropped support for PHP 5.x
  • Added PHPUnit 6.x as requirement
  • Added lib exceptions

runopencode/sax 适用场景与选型建议

runopencode/sax 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.44k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「xml」 「sax」 「xml parser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 runopencode/sax 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 runopencode/sax 我们能提供哪些服务?
定制开发 / 二次开发

基于 runopencode/sax 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-12