assad2008/dump-r
Composer 安装命令:
composer require assad2008/dump-r
包简介
a cleaner, leaner mix of print_r() and var_dump()
README 文档
README
a cleaner, leaner mix of print_r() and var_dump() (MIT Licensed)
Demo: http://o-0.me/dump_r/
Installing
Composer
https://packagist.org/packages/leeoniya/dump-r
{
"require": {
"leeoniya/dump-r": "dev-master"
}
}
Require
require 'dump_r.php';
Using & Config
Use dump_r() as a drop-in replacement for print_r() and var_dump(). It has some additional arguments that control output. The full signature of the function is:
function dump_r($value, $return = false, $html = true, $depth = 1e3, $expand = 1e3);
$valueis the thing you want to dump$returndetermines whether to return the dump rather than output to screen$htmlcontrols whether the output is text or html$depthsets the recursion limit for the dump$expandsets the auto-expanded child node depth
There are also two modifier keys that can be used to control how the node expanding/collapsing works:
- Holding
Shiftwhile toggling will expand/collapse the full depth of the node. - Hold
Ctrlwhile toggling will expand/collapse all siblings after that node also. This is useful if you have an array of objects/arrays and want to expand all of them to one level simultaneously by clicking just the first one in the group. It works well for deep, complex objects. ShiftandCtrlcan be used together.
Double-clicking binary strings will toggle them between mixed hex/ascii and hex-only representations:
Some types of strings can be pretty-printed and additonal rendering options can be tweaked (shown with defaults):
dump_r\Rend::$xml_pretty = false; // pretty-print xml strings dump_r\Rend::$json_pretty = false; // pretty-print json strings dump_r\Rend::$sql_pretty = false; // pretty-print sql strings (requires https://github.com/jdorn/sql-formatter) dump_r\Rend::$recset_tbls = true; // recordset detection & table-style output dump_r\Rend::$trace_info = true; // show file & line where dump_r was invoked dump_r\Rend::$val_space = 4; // number of spaces between key and value columns (affects text output only, not html)
Circular reference (recursion) detection and duplicate output is indicated like this for arrays, objects, closures and resources respectively: [*],{*},(*),<*>.
You can re-style all aspects of the html output using CSS, everything is class-tagged.
Extending
Adding your own classifiers & parsers is extremely easy. Here are instructions and two concrete examples of how the String base type can be subtyped. First for displaying EXIF data of jpeg and tiff image paths and then showing row data from CSV file paths.
This array
$stuff = [ 'imgs/img_1771.jpg', 'data/people.csv', ];
Which would normally dump like this:
Can be dumped like this with subtyping:
To do this, hook the correct core type and provide a function that classifies and processes the raw value, then modifies and returns an instance of Type. Here are the properties that can be modified/augmented:
$type->types- Array of subtype string(s) of your choice. These get appended as CSS classes and are also displayed inline.$type->nodes- Array of expandable subnodes to display. Providenullif no subnodes are needed or to retain any subnodes extracted by the core type.$type->length- A string to be displayed at the end of the line, indicating length of subnodes. You can also abuse this param to display other length-esque information (the EXIF example below uses it to display image dimensions inline). Providenullto retain the default length display for the hooked core type.
use dump_r\Type; // Example 1: dump EXIF data with image filepath strings Type::hook('_String', function($raw, Type $type, $path) { // match path-esque strings (containing '/' or '\') trailed by an // EXIF-capable image extension, then verify this file actually exists if (preg_match('#[\/]+.+\.(jpe?g|tiff?)$#', $raw) && is_file($raw)) { $nodes = $exif = exif_read_data($raw, 0, true); $len = $exif['COMPUTED']['Width'] . 'x' . $exif['COMPUTED']['Height']; $type->types = ['image']; $type->nodes = ['EXIF' => $nodes['EXIF']]; $type->length = $len; return $type; } }); // Example 2: dump CSV records with csv filepath strings Type::hook('_String', function($raw, Type $type, $path) { if (preg_match('#[\/]+.+\.csv$#', $raw) && is_file($raw)) { $type->types = ['csv']; $type->nodes = csv2array($raw); $type->length = count($type->nodes); return $type; } }); function csv2array($file) { $csv = []; $rows = array_map('str_getcsv', file($file)); $header = array_shift($rows); foreach ($rows as $row) $csv[] = array_combine($header, $row); return $csv; }
All core types (see src/dump_r/Node dir) can be hooked by their fully namespaced names. For example, if you wanted to further subtype a JSON object string, you would use
Type::hook('_String\\_JSON\\_Object', function($raw, Type $type, $path) { // code here });
Filtering, Marking & Recursion Control
Using the same Type hooks (introduced above) allows you to modify additional aspects of the renderer and iterator.
Skip specific nodes based on their properties or path in the hierarchy
// prevent anything keyd under 'xxx' from dumping Type::hook('*', function($raw, Type $type, $path) { if (end($path) === 'xxx') return false; });
Stop recursion of specific nodes
// prevent arrays keyed under 'c' from dumping sub-nodes Type::hook('_Array', function($raw, Type $type, $path) { if (end($path) === 'c') $type->depth = 1; return $type; });
CSS-tag nodes via classes
// tag nodes keyed under `yyy` with addl CSS classes Type::hook('*', function($raw, Type $type, $path) { if (end($path) === 'yyy') { $type->classes[] = 'marked'; } return $type; });
assad2008/dump-r 适用场景与选型建议
assad2008/dump-r 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 156 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「dump」 「pretty」 「print」 「print_r」 「var_dump」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 assad2008/dump-r 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 assad2008/dump-r 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 assad2008/dump-r 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package will add the `dd` and `dump` helpers to your Phalcon application.
HTML Formatter pritifies HTML content by applying proper intendation (no tidy, purification, etc.).
Debug your SimpleBus EventBus and CommandBus
Simple Twig extension improving templates debugging
nice output for debug functions for PHP 5.3
The extension of JsonFormatter of Monolog, which pretty prints json and supports unicode. Does not escape slashes.
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-22



