PHP code example of macino / cli-dumper

1. Go to this page and download the library: Download macino/cli-dumper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

macino / cli-dumper example snippets


use Macino\CliDumper\CliDumper;

$dumper = new CliDumper();

$dumper->dump(
    'Dumping data example',
    ['key1' => 'value1', 'key2' => [1, 2, 3]],
    separateLeafs: true,
    separate: true
);

$dumper->d('This is a quick debug message', ['id' => 42, 'active' => true]);

$dumper->formatter = function(mixed $value, string $type) {
    switch ($type) {
        case 'null': return "\e[1;30mNULL\e[0m"; // Gray
        case 'bool': return "\e[1;33m" . ($value ? 'TRUE' : 'FALSE') . "\e[0m"; // Yellow
        case 'string': return "\e[1;34m\"$value\"\e[0m"; // Blue
        case 'num': return "\e[1;31m{$value}\e[0m"; // Red
    }
    return $value;
};

$result = $dumper->inlineDump($data, separateLeafs: true, return: true);
echo $result;

$dumper->enabled = false; // Disables all dumps

$dumper->truncate = 50; // Truncate strings longer than 50 characters

$dumper->maxDepth = 3; // Limit the output to 3 levels of nested structures
$dumper->maxDepth = -1; // No limit on nesting (default behavior)

$dumper->formatter = fn($value, $type) => strtoupper($value);