/array-dumper

Dump constant arrays into its source PHP code keeping pretty print

Primary LanguagePHPMIT LicenseMIT

array-dumper

Latest Stable Version Latest Dev Version Build Status License

Dumps PHP array into pretty printed PHP code. Only constant data can be dumped, t.i. data, which can be used in const declaration since PHP 7.

Synopsis

use \VovanVE\array_dumper\ArrayDumper;

$dumper = new ArrayDumper();

$data = [
    'foo' => 42,
    'bar' => 'string',
    'list' => [10, 20, 30],
    'hash' => [
        'lorem' => 23,
        'ipsum' => true,
    ],
];

echo $dumper->dump($data);

Output:

[
    'foo' => 42,
    'bar' => 'string',
    'list' => [10, 20, 30],
    'hash' => [
        'lorem' => 23,
        'ipsum' => true,
    ],
]

Description

Simple array with sequential zero-based integer keys (aka lists) will be dumped in single line, unless the line became too long with indention, or lists nesting level became to deep (both are configurable).

An optional outer indent string can be supplied to dump() method. It is used internally for nested arrays. It can be anything you want including comment prefix // .

Notice: The library works only with UTF-8 strings. A string which is not valid UTF-8 in source data will encode invalid octets with \xFF escape codes. So, output dump always should be valid UTF-8 code.

Installation

Install through composer:

composer require vovan-ve/array-dumper

or add to require section in your composer.json:

"vovan-ve/array-dumper": "~1.0.0"

License

This package is under MIT License