serendipity_hq/component-var-dumper-f

Adds functions dumpf() and ddf() to Symfony's VarDumper component to be used in CLI scripts to dump to a file.

2.1.2 2022-01-08 18:24 UTC

This package is auto-updated.

Last update: 2022-05-10 12:05:47 UTC


README

687474703a2f2f7777772e736572656e64697069747968712e636f6d2f6173736574732f6f70656e2d736f757263652d70726f6a656374732f4c6f676f2d536572656e64697069747948512d49636f6e2d546578742d507572706c652e706e67

Serendipity HQ VarDumper F

Adds functions `dumpf()` and `ddf()` to [Symfony's VarDumper component](https://symfony.com/doc/current/components/var_dumper.html) that write the dump to a file.

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736572656e6469706974795f68712f636f6d706f6e656e742d7661722d64756d7065722d662e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736572656e6469706974795f68712f636f6d706f6e656e742d7661722d64756d7065722d663f636f6c6f723d253233383839324246267374796c653d666c61742d737175617265266c6f676f3d706870

Supports: 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Tested with: 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Current Status

Coverage Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

Phan PHPStan PSalm PHPUnit Composer PHP CS Fixer Rector

Do you like this library?
LEAVE A ★

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!

Install VarDumper CLI to HTML via Composer

$ composer require serendipity_hq/component-var-dumper-f --dev

This library follows the http://semver.org/ versioning conventions.

Usage

The library provides two functions: dumpf() and ddf().

They work exactly like the Symfony's VarDumper built ones dump() and dd(), with those specifities:

  1. Both dumpf() and ddf() can be used only in scripts that run in the command line;
  2. Both requires the first parameter is null or an array with some options.

The simplest usage is this:

$var = [
    'a simple string' => "in an array of 5 elements",
    'a float' => 1.0,
    'an integer' => 1,
    'a boolean' => true,
    'an empty array' => [],
];
dumpf(null, $var);
ddf(null, $var);

The result will be an HTML file with a random name that contains the dump of $var.

Opening the file you will see

For more examples of outputs, consult the Symfony's VarDumper documentation about Dump Examples and Output.

Specifying the dumped file

You can specify the file of the dump passing its full path name as first argument:

dumpf('~/path/to/your/folder/filename', $var);
ddf('~/path/to/your/folder/filename', $var);

You can use a name like filename or like filename.html: the resulting file will always have one .html extension (filename.html).

Passing options

Both functions accepts as first argument an array.

The passed array can contain any of the options that you can pass to a Symfony's VarDumper Cloner (reference).

The only additional option you can pass is the file, whit which you can specify the name of the dumped file:

dumpf(['file' => 'dump_var', 'maxDepth' => 2], $var);
ddf(['file' => 'dump_var.html', 'maxDepth' => 5], $var);

In both cases, the file dump_var.html will be generated.

What happens if the file already exists

The new dump will be added to the already existing file.

So, if you call dumpf() three times in your CLI script, then the resulting file dump will have three dumps in it.

If you run again the script, the resulting file dump will now contain six dumps in it: the three from the first run and the three from the second run.

To get a fresh dump, simply remove the dumped files.

Do you like this library?
LEAVE A ★

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!