Closed
Description
Context
As @fabpot said in #18070 (comment), if some code is repeated in several parts, we can extract it to a new component, no matter how big or small it is.
Problem to solve
In Symfony this need is very common: "given an arbitrary variable, return its best possible representation as a string".
Current situation
Today we solve this problem at least in 6 different ways across different bundles and components:
- ValueExporter class (in
Symfony\Component\HttpKernel\DataCollector\Util
) used mostly in DataCollectors. - formatValue(), formatParameter and formatCallable in FrameworkBundle's Console descriptors.
- formatValue() method in OptionsResolver component.
- getStringRepresentation() method in DebugAccessDecisionManager class.
- varToString() method in FileLoaderLoadException class (
Symfony/Component/Config/Exception
) - sanitizeContext() method in LoggerDataCollector (
Symfony\Component\HttpKernel\DataCollector
)
Solution
Create a new ValueExporter
component to merge all this stuff.