{"id":16858017,"url":"https://github.com/leeoniya/dump_r.php","last_synced_at":"2025-04-09T16:10:21.910Z","repository":{"id":57013528,"uuid":"1926307","full_name":"leeoniya/dump_r.php","owner":"leeoniya","description":"a cleaner, leaner mix of print_r() and var_dump()","archived":false,"fork":false,"pushed_at":"2017-06-19T22:10:23.000Z","size":1093,"stargazers_count":122,"open_issues_count":15,"forks_count":18,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-09T16:09:57.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leeoniya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-06-20T22:38:08.000Z","updated_at":"2025-03-06T12:18:17.000Z","dependencies_parsed_at":"2022-08-21T14:50:37.547Z","dependency_job_id":null,"html_url":"https://github.com/leeoniya/dump_r.php","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2Fdump_r.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2Fdump_r.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2Fdump_r.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2Fdump_r.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leeoniya","download_url":"https://codeload.github.com/leeoniya/dump_r.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065283,"owners_count":21041871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T14:11:13.110Z","updated_at":"2025-04-09T16:10:21.891Z","avatar_url":"https://github.com/leeoniya.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"dump_r()\n========\na cleaner, leaner mix of `print_r()` and `var_dump()` _(MIT Licensed)_\n\n![screenshot](https://github.com/leeoniya/dump_r.php/raw/master/test/dump_r.png)\n\n### Demo: http://o-0.me/dump_r/\n\n### Installing\n\n__Composer__\n\nhttps://packagist.org/packages/leeoniya/dump-r\n\n```json\n{\n\t\"require\": {\n\t\t\"leeoniya/dump-r\": \"dev-master\"\n\t}\n}\n```\n\n__Require__\n\n```php\nrequire 'dump_r.php';\n```\n\n### Using \u0026 Config\n\nUse `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:\n\n```php\nfunction dump_r($value, $return = false, $html = true, $depth = 1e3, $expand = 1e3);\n```\n\n- `$value` is the thing you want to dump\n- `$return` determines whether to return the dump rather than output to screen\n- `$html` controls whether the output is text or html\n- `$depth` sets the recursion limit for the dump\n- `$expand` sets the auto-expanded child node depth\n\nThere are also two modifier keys that can be used to control how the node expanding/collapsing works:\n\n1. Holding `Shift` while toggling will expand/collapse the full depth of the node.\n2. Hold `Ctrl` while 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.\n3. `Shift` and `Ctrl` can be used together.\n\nDouble-clicking binary strings will toggle them between mixed hex/ascii and hex-only representations:\n\n![binary_toggle](https://github.com/leeoniya/dump_r.php/raw/master/test/binary_toggle.gif)\n\nSome types of strings can be pretty-printed and additonal rendering options can be tweaked (shown with defaults):\n\n```php\ndump_r\\Rend::$xml_pretty\t= false;\t// pretty-print xml strings\ndump_r\\Rend::$json_pretty\t= false;\t// pretty-print json strings\ndump_r\\Rend::$sql_pretty\t= false;\t// pretty-print sql strings (requires https://github.com/jdorn/sql-formatter)\ndump_r\\Rend::$recset_tbls\t= true;\t\t// recordset detection \u0026 table-style output\ndump_r\\Rend::$trace_info\t= true;\t\t// show file \u0026 line where dump_r was invoked\ndump_r\\Rend::$val_space\t\t= 4;\t\t// number of spaces between key and value columns (affects text output only, not html)\n```\n\nCircular reference (recursion) detection and duplicate output is indicated like this for arrays, objects, closures and resources respectively: `[*]`,`{*}`,`(*)`,`\u003c*\u003e`.\n\nYou can re-style all aspects of the html output using CSS, everything is class-tagged.\n\n### Extending\n\nAdding your own classifiers \u0026 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.\n\nThis array\n\n```php\n$stuff = [\n\t'imgs/img_1771.jpg',\n\t'data/people.csv',\n];\n```\n\nWhich would normally dump like this:\n\n![coretyped](https://github.com/leeoniya/dump_r.php/raw/master/test/coretyped.png)\n\nCan be dumped like this with subtyping:\n\n![usertyped](https://github.com/leeoniya/dump_r.php/raw/master/test/usertyped.png)\n\nTo 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:\n\n1. `$type-\u003etypes` - Array of subtype string(s) of your choice. These get appended as CSS classes and are also displayed inline.\n2. `$type-\u003enodes` - Array of expandable subnodes to display. Provide `null` if no subnodes are needed or to retain any subnodes extracted by the core type.\n3. `$type-\u003elength` - 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). Provide `null` to retain the default length display for the hooked core type.\n\n```php\nuse dump_r\\Type;\n\n// Example 1: dump EXIF data with image filepath strings\n\nType::hook('_String', function($raw, Type $type, $path) {\n\t// match path-esque strings (containing '/' or '\\') trailed by an\n\t// EXIF-capable image extension, then verify this file actually exists\n\tif (preg_match('#[\\/]+.+\\.(jpe?g|tiff?)$#', $raw) \u0026\u0026 is_file($raw)) {\n\t\t$nodes = $exif = exif_read_data($raw, 0, true);\n\t\t$len = $exif['COMPUTED']['Width'] . 'x' . $exif['COMPUTED']['Height'];\n\n\t\t$type-\u003etypes\t= ['image'];\n\t\t$type-\u003enodes\t= ['EXIF' =\u003e $nodes['EXIF']];\n\t\t$type-\u003elength\t= $len;\n\n\t\treturn $type;\n\t}\n});\n\n// Example 2: dump CSV records with csv filepath strings\n\nType::hook('_String', function($raw, Type $type, $path) {\n\tif (preg_match('#[\\/]+.+\\.csv$#', $raw) \u0026\u0026 is_file($raw)) {\n\n\t\t$type-\u003etypes\t= ['csv'];\n\t\t$type-\u003enodes\t= csv2array($raw);\n\t\t$type-\u003elength\t= count($type-\u003enodes);\n\n\t\treturn $type;\n\t}\n});\n\nfunction csv2array($file) {\n\t$csv = [];\n\t$rows = array_map('str_getcsv', file($file));\n\t$header = array_shift($rows);\n\tforeach ($rows as $row)\n\t\t$csv[] = array_combine($header, $row);\n\treturn $csv;\n}\n```\n\nAll 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\n\n```php\nType::hook('_String\\\\_JSON\\\\_Object', function($raw, Type $type, $path) {\n\t// code here\n});\n```\n\n### Filtering, Marking \u0026 Recursion Control\n\nUsing the same `Type` hooks (introduced above) allows you to modify additional aspects of the renderer and iterator.\n\n**Skip specific nodes based on their properties or path in the hierarchy**\n\n```php\n// prevent anything keyd under 'xxx' from dumping\nType::hook('*', function($raw, Type $type, $path) {\n\tif (end($path) === 'xxx')\n\t\treturn false;\n});\n```\n\n**Stop recursion of specific nodes**\n\n```php\n// prevent arrays keyed under 'c' from dumping sub-nodes\nType::hook('_Array', function($raw, Type $type, $path) {\n\tif (end($path) === 'c')\n\t\t$type-\u003edepth = 1;\n\n\treturn $type;\n});\n```\n\n**CSS-tag nodes via classes**\n\n```php\n// tag nodes keyed under `yyy` with addl CSS classes\nType::hook('*', function($raw, Type $type, $path) {\n\tif (end($path) === 'yyy') {\n\t\t$type-\u003eclasses[] = 'marked';\n\t}\n\n\treturn $type;\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeoniya%2Fdump_r.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleeoniya%2Fdump_r.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeoniya%2Fdump_r.php/lists"}