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.
Installs: 287 832
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- symfony/var-dumper: ^4.4|^5.4|^6.4|^7.0
- thecodingmachine/safe: ^1.3|^2.0
Requires (Dev)
- ext-ast: *
- bamarni/composer-bin-plugin: ^1.4
- phpstan/phpstan: 1.10.59
- phpstan/phpstan-phpunit: 1.3.16
- rector/rector: 1.0.1
- roave/security-advisories: dev-master
- serendipity_hq/rector-config: ^1.0
- thecodingmachine/phpstan-safe-rule: 1.2.0
README
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.
Current Status
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:
- Both
dumpf()
andddf()
can be used only in scripts that run in the command line; - 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!