You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We aim to enhance Var-Dumper by allowing developers to specify the language for syntax highlighting within their dumps. This enhancement will streamline the debugging process and improve the readability of dumped content, particularly in cases involving multiple programming languages.
Introduce a new parameter or method within Var-Dumper that enables developers to specify the language for syntax highlighting. This parameter could accept standard language identifiers or aliases, such as those commonly used in code editors or highlighting libraries (e.g., "php", "javascript", "python", etc.).
The current method for adding additional context to a VarDumper involves complex and verbose code, which can be cumbersome and error-prone. This proposal aims to enhance the Symfony VarDumper API to provide a more intuitive and concise way of adding context information.
<?phpuseSymfony\Component\VarDumper\Caster\ReflectionCaster;
useSymfony\Component\VarDumper\Cloner\VarCloner;
useSymfony\Component\VarDumper\Dumper\ContextProvider\CliContextProvider;
useSymfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
useSymfony\Component\VarDumper\Dumper\ContextualizedDumper;
useSymfony\Component\VarDumper\Dumper\HtmlDumper;
useSymfony\Component\VarDumper\Dumper\ServerDumper;
\Symfony\Component\VarDumper\VarDumper::setHandler(function ($var, ?string$label = null) {
$dumper = newServerDumper('127.0.0.1', newHtmlDumper(), [
'language' => 'php', // <===== this is the line that you need to add to your code'cli' => newCliContextProvider(),
'source' => newSourceContextProvider(),
]);
$dumper = newContextualizedDumper($dumper, [newSourceContextProvider()]);
$cloner = newVarCloner();
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
}
$dumper->dump($var);
});
Proposed Solutions:
Static Method in VarDumper Class: Introduce a static method in the VarDumper class, such as addContext(), which accepts an array of default context settings. Developers can then call this method to set default context options, including the language for syntax highlighting. See https://github.com/symfony/var-dumper/blob/7.0/VarDumper.php#L101
Named Argument in dump() function: Extend the dump() function to accept a named argument context, allowing developers to specify default context settings directly when calling dump().
We aim to enhance Var-Dumper by allowing developers to specify the language for syntax highlighting within their dumps. This enhancement will streamline the debugging process and improve the readability of dumped content, particularly in cases involving multiple programming languages.
Introduce a new parameter or method within Var-Dumper that enables developers to specify the language for syntax highlighting. This parameter could accept standard language identifiers or aliases, such as those commonly used in code editors or highlighting libraries (e.g., "php", "javascript", "python", etc.).
The current method for adding additional context to a VarDumper involves complex and verbose code, which can be cumbersome and error-prone. This proposal aims to enhance the Symfony VarDumper API to provide a more intuitive and concise way of adding context information.
Proposed Solutions:
VarDumper
class, such asaddContext()
, which accepts an array of default context settings. Developers can then call this method to set default context options, including the language for syntax highlighting. See https://github.com/symfony/var-dumper/blob/7.0/VarDumper.php#L101dump()
function: Extend thedump()
function to accept a named argumentcontext
, allowing developers to specify default context settings directly when callingdump()
.UPD: as I can see there is a PR in symfony repository symfony/symfony#48667 that can solve our problem.
The text was updated successfully, but these errors were encountered: