定制 imsop/simplexml_debug 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

imsop/simplexml_debug

Composer 安装命令:

composer require imsop/simplexml_debug

包简介

Tools for debugging your code when working with PHP's SimpleXML functions.

README 文档

README

PHP's SimpleXML extension is a powerfully simple way of accessing and manipulating XML documents in a "PHP-ish" way. But although using it feels like using a PHP object, there is an awful lot of magic that enables it to work that way, which is poorly documented, and poorly understood.

One of the key mistakes people make when working with SimpleXML is to reach for the familiar debug outputs: print_r, var_dump, var_export. But none of these work because a SimpleXML object isn't a real PHP object - it's just a wrapper around a lower-level XML parser.

Rule number 1 of SimpleXML: You do not print_r SimpleXML

So the obvious question is: What do I use instead when I want to inspect my SimpleXML objects? This project aims to be the answer to that question.

What?

  • The first piece of this project is a simple function - simplexml_dump() - which echoes a basic summary of any SimpleXMLElement object you give it.
  • Early feedback from users on StackOverflow was that a fully recursive function would be useful, although this would obviously need to do something different from an XML pretty-printer. The next function is therefore simplexml_tree() which shows an entire XML structure in summarised tree form. The output is designed to show exactly what operators and methods are needed to access each node shown.

Features

Read the PHPDoc, and try it out, to see exactly how it works but to give you a taste:

  • Can display any of the varieties of object produced while navigating a SimpleXML structure: single elements, lists of elements, single attributes, lists of attributes.
  • Displays the namespace alias and URI of the current element, and all its direct children.
  • Lists the total number and name of all attributes on an element (broken down by namespace).
  • Lists the total number of direct children (broken down by namespace) along with a summary of their names (e.g. the fact that there are 500 Result elements and 1 Info element).
  • Shows complete string content of a node, including CDATA.

Limitations and Warnings

  • There is currently no way of distinguishing between a single element (e.g. $sxml->Result[0]) and a list of elements (e.g. $sxml->Result or $sxml->children()) which happens to include only one item. They can however behave differently - foreach ( $sxml->Result[0] as $result ) is equivalent to foreach ( $sxml->Result[0]->children() as $result ).
  • The xpath() method doesn't return a SimpleXMLElement, but an actual array of objects. simplexml_dump() will currently return an error if you try to pass it this array.
  • Namespace handling is somewhat tricky, and there may be edge-cases which are not handled correctly.

Who?

This project was originated by Rowan Collins, AKA IMSoP. My homepage is at http://rwec.co.uk, and you can reach me by e-mail on the obvious addresses @ that domain.

The code is licensed under the MIT license, which means you can pretty much do what you like with it, other than claim you wrote it yourself. I'm happy for you to take it away, improve it, and use it for whatever you like, but I'd love to hear what you do with it, and how you've improved on it.

imsop/simplexml_debug 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 51
  • Watchers: 1
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-25