PHPackages                             macino/cli-dumper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. macino/cli-dumper

ActiveLibrary[CLI &amp; Console](/categories/cli)

macino/cli-dumper
=================

Alternative for dumping vars in terminal env. Neat and compact with possible highlights.

1.2.7(10mo ago)02521MITPHPPHP &gt;=8.1

Since Sep 28Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/macino/CliDumper)[ Packagist](https://packagist.org/packages/macino/cli-dumper)[ RSS](/packages/macino-cli-dumper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (17)Used By (0)

**CliDumper Documentation**
===========================

[](#clidumper-documentation)

**Overview**
------------

[](#overview)

`CliDumper` is a compact and flexible PHP library designed for efficiently dumping PHP data structures such as arrays, objects, and scalars into a readable and customizable format. It enhances log readability, especially in scenarios involving large and complex data, by eliminating excessive verbosity and emphasizing minimalism, color, and structure.

With features like customizable output and syntax highlighting for scalar types, `CliDumper` stands out as a developer-friendly tool for debugging, logging, and real-time output processing in CLI environments.

---

**Why CliDumper?**
------------------

[](#why-clidumper)

Dealing with complex data logs can often lead to cluttered log files filled with `var_dump`, `var_export`, or `print_r` outputs. While these methods are useful, they can become cumbersome, especially when searching for specific values in lengthy or nested outputs.

`CliDumper` solves this by:

- **Reducing verbosity:** It formats output compactly and only highlights what's necessary.
- **Improving readability:** It uses color highlights to distinguish between data types (e.g., numbers, strings, nulls, etc.).
- **Customization options:** Developers can define their own formatting rules for scalar values.
- **Structured visualization:** It efficiently handles arrays, objects, and nested structures.

---

**Key Features**
----------------

[](#key-features)

1. **Compact Output**: Generates concise dumps for even the most complex data structures.
2. **Customizable Formatter**: Modify scalar type representations (e.g., color-coded outputs).
3. **Visual Highlights**:
    - Color differentiation for types (e.g., null, string, numeric, boolean).
    - Options to organize nested elements for clarity.
4. **Efficient Debugging**: Output can be directly printed to CLI or returned as a string for further processing.
5. **Truncation**: Set limits for string length to keep outputs within manageable size.
6. **Optional Separators**: Add separators in output for better log organization.

---

**Installation**
----------------

[](#installation)

### **Using Composer**

[](#using-composer)

Install the library via Composer:

```
composer require macino/clidumper
```

---

**Usage**
---------

[](#usage)

Here are the basic usage examples for the `CliDumper` class:

### **Initialization**

[](#initialization)

```
use Macino\CliDumper\CliDumper;

$dumper = new CliDumper();
```

---

### **Dump Debugging Data**

[](#dump-debugging-data)

The `dump` method outputs a message and variable data to the CLI. Customize the output with optional flags.

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

#### **Parameters**

[](#parameters)

- **`$msg`**: (string) A message or title displayed before the dump.
- **`$data`**: (mixed) The data to be dumped.
- **`$separateLeafs`**: (bool) Breaks scalar members onto new lines and organizes them by key.
- **`$separate`**: (bool) Adds a separator line (e.g., `------`) before the output.

---

### **Alias for Dump**

[](#alias-for-dump)

The `d` method is an alias for the `dump` method.

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

---

### **Custom Formatting**

[](#custom-formatting)

You can define your own formatter callback to modify scalar type representations. Use the `$formatter` property to define a custom formatting function.

#### Example:

[](#example)

```
$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;
};
```

---

### **Inline Dump**

[](#inline-dump)

Use `inlineDump` to output or retrieve a serialized version of a variable without the heading message.

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

#### **Parameters**:

[](#parameters-1)

- **`$var`**: (mixed) The variable to be dumped.
- **`$separateLeafs`**: (bool) Breaks scalar members onto new lines and organizes them by key.
- **`$return`**: (bool) If `true`, the method returns the dump as a string instead of printing it.

---

**Configuration Options**
-------------------------

[](#configuration-options)

### **Public Properties**

[](#public-properties)

1. **`$enabled`**:

    - *Type*: `bool`
    - *Default*: `true`
    - Enables or disables dumping.

    #### Example:

    [](#example-1)

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

2. **`$truncate`**:

    - *Type*: `int`
    - *Default*: `80`
    - Limits the length of strings in the dump. Set `0` for no limit.

    #### Example:

    [](#example-2)

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

4. **`$maxDepth`**:

    - *Type*: `int`
    - *Default*: `-1` (no limit)
    - Specifies the maximum depth for nested data structures. If set, the dumper will truncate any nesting deeper than the specified level.

    #### Example:

    [](#example-3)

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

3. **`$formatter`**:

    - *Type*: `callable`
    - *Default*: A simple formatter that outputs unaltered scalars.
    - Provides custom display formatting for different scalar types.

    #### Example:

    [](#example-4)

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

---

**Methods**
-----------

[](#methods)

### **`dump`**

[](#dump)

Outputs formatted data to the CLI with an optional message.

### **`d`**

[](#d)

Alias for `dump`.

### **`inlineDump`**

[](#inlinedump)

Returns a formatted string of the provided data or prints it directly.

---

**Use Cases**
-------------

[](#use-cases)

1. **Debugging**:
    - Quickly visualize complex data structures in developer-friendly formats.
    - Highlight and differentiate key elements in the output using colors.
2. **Logging**:
    - Write cleaner, compact logs for later analysis.
3. **Real-time Data Processing**:
    - Print readable information from live CLI applications.

---

**Limitations**
---------------

[](#limitations)

- Primarily suited for CLI-based debugging and logs; not meant to replace JSON, XML, or other structured formats for storage.

---

**Conclusion**
--------------

[](#conclusion)

`CliDumper` is a lightweight solution for PHP developers looking to improve debugging experiences, enhance log readability, and cleanly process real-time data in CLI environments. With its color coding, formatting flexibility, and compact outputs, `CliDumper` simplifies viewing intricate data structures without sacrificing detail.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance53

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~22 days

Total

16

Last Release

327d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.2

1.2.6PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/89e6e63d8bc1955654dbd1036ae7e5d59ec356544779c7f43b1ffbd3c295b421?d=identicon)[tomas.macik](/maintainers/tomas.macik)

---

Top Contributors

[![macino](https://avatars.githubusercontent.com/u/522323?v=4)](https://github.com/macino "macino (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/macino-cli-dumper/health.svg)

```
[![Health](https://phpackages.com/badges/macino-cli-dumper/health.svg)](https://phpackages.com/packages/macino-cli-dumper)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.1k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)[codedungeon/php-cli-colors

Liven up you PHP Console Apps with standard colors

10210.1M26](/packages/codedungeon-php-cli-colors)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
