2017 © Pedro Peláez
 

library smartdump

A smarter alternative to var_dump for PHP5.6+

image

bonemeijer/smartdump

A smarter alternative to var_dump for PHP5.6+

  • Thursday, December 7, 2017
  • by Bonemeijer
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1,206 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 113 % Grown

The README.md

SmartDump

A smarter alternative to var_dump for PHP5.6+, (*1)

The goal is to provide a friendly debug tool that is framework independent and works across multiple environments., (*2)

Build Status Latest Stable Version Total Downloads License, (*3)

Installing

This project is still in beta. Backwards incompatible changes might be introduced during this time., (*4)

composer require --dev bonemeijer/smartdump

Basic usage

By default, SmartDump is configured to detect where you are debugging from and will output either plaintext or html. For example: when you dump from the commandline, a plaintext output is used. But when you are debugging from a browser, an interactive HTML output is used., (*5)

There is a main SmartDump class, which provides a friendly global interface to debug a variable anywhere in your code. But don't worry, you can use and configure your own instances too., (*6)

\SmartDump\SmartDump::dump($variable);

Shortcut functions

Even easier are the shortcut functions. These live in the global namespace so you don't have to do any imports when you quickly want to debug a variable., (*7)

Available functions:, (*8)

  • smartdump($variable) - shortcut for \SmartDump\SmartDump::dump($variable);
  • smartdump_text($variable) - dump plaintext to output
  • smartdump_html($variable) - dump simplehtml to output
  • smartdump_text_stream - dump plaintext to a file or url
  • d($variabe) - dump a context aware format to output
  • o($variabe) - dump a context aware format to output, clear output buffer and exit()

TIP - the shortcut function smartdump() uses the global SmartDump class, so you can configure the desired behaviour through the SmartDump class., (*9)

Advanced usage

SmartDump will internally convert any passed variable to a Node using a NodeFactory. These Nodes will then be passed to a Dumper, which will accept Formatter to render an output format., (*10)

Nodes

A Node is basically an internal representation of a variable. The DefaultNodeFactory has support for all regular PHP variable types like booleans, strings, integers, floats, arrays, objects, resources and NULL values., (*11)

Formatters

A formatter formats the Node to output that can be handles by a Dumper. At this time there are only string type formatters, which will render a Node to a string., (*12)

By default, the ContextAwareStringFormatter will be used, which will return a formatter based on where you are debugging from., (*13)

Available formatters:, (*14)

  • PlainTextStringFormatter - formats to plaintext, for use in commandline and other text based environments
  • DomStringFormatter - can use a Markup document to output HTML (or someday XML or any other markup language)
  • ContextAwareStringFormatter - switches between plaintext and dom based on the current environment
  • CallBackStringFormatter - accepts callbacks to determine which formatter is used

To globally use a different formatter for all SmartDump::dump() calls:, (*15)

\SmartDump\SmartDump::setFormatter(
    new \SmartDump\Formatter\StringFormatter\PlainTextStringFormatter()
);

Dumpers

A Dumper will determine how the formatted node will be handled. By default, the OutputDumper is used, which will just echo the output to the screen., (*16)

Available dumpers:, (*17)

  • OutputDumper - simply echo's the output
  • StreamDumper - dumps the formatted output to a file or stream

To globally use a different dumper for all SmartDump::dump() calls:, (*18)

\SmartDump\SmartDump::setDumper(
    new \SmartDump\Dumper\StreamDumper('output.txt')
);

Deployment

Don't. Don't deploy debug tools. Which is why I recommend using the --dev flag during installation., (*19)

Versioning

SmartDump uses SemVer for versioning. For the versions available, see the tags on this repository., (*20)

Authors

See also the list of contributors who participated in this project., (*21)

License

This project is licensed under the MIT License - see the LICENSE file for details, (*22)

The Versions

07/12 2017

dev-master

9999999-dev https://github.com/Bonemeijer/SmartDump

A smarter alternative to var_dump for PHP5.6+

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

debug var_dump

07/12 2017

v0.2.0

0.2.0.0 https://github.com/Bonemeijer/SmartDump

A smarter alternative to var_dump for PHP5.6+

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

debug var_dump

27/10 2017

v0.1

0.1.0.0 https://github.com/Bonemeijer/SmartDump

A smarter alternative to var_dump for PHP5.6+

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

debug var_dump