diff options
Diffstat (limited to 'vendor/symfony/console/Helper/Dumper.php')
-rw-r--r-- | vendor/symfony/console/Helper/Dumper.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/symfony/console/Helper/Dumper.php b/vendor/symfony/console/Helper/Dumper.php new file mode 100644 index 0000000..0cd01e6 --- /dev/null +++ b/vendor/symfony/console/Helper/Dumper.php | |||
@@ -0,0 +1,53 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Console\Helper; | ||
13 | |||
14 | use Symfony\Component\Console\Output\OutputInterface; | ||
15 | use Symfony\Component\VarDumper\Cloner\ClonerInterface; | ||
16 | use Symfony\Component\VarDumper\Cloner\VarCloner; | ||
17 | use Symfony\Component\VarDumper\Dumper\CliDumper; | ||
18 | |||
19 | /** | ||
20 | * @author Roland Franssen <franssen.roland@gmail.com> | ||
21 | */ | ||
22 | final class Dumper | ||
23 | { | ||
24 | private \Closure $handler; | ||
25 | |||
26 | public function __construct( | ||
27 | private OutputInterface $output, | ||
28 | private ?CliDumper $dumper = null, | ||
29 | private ?ClonerInterface $cloner = null, | ||
30 | ) { | ||
31 | if (class_exists(CliDumper::class)) { | ||
32 | $this->handler = function ($var): string { | ||
33 | $dumper = $this->dumper ??= new CliDumper(null, null, CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR); | ||
34 | $dumper->setColors($this->output->isDecorated()); | ||
35 | |||
36 | return rtrim($dumper->dump(($this->cloner ??= new VarCloner())->cloneVar($var)->withRefHandles(false), true)); | ||
37 | }; | ||
38 | } else { | ||
39 | $this->handler = fn ($var): string => match (true) { | ||
40 | null === $var => 'null', | ||
41 | true === $var => 'true', | ||
42 | false === $var => 'false', | ||
43 | \is_string($var) => '"'.$var.'"', | ||
44 | default => rtrim(print_r($var, true)), | ||
45 | }; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | public function __invoke(mixed $var): string | ||
50 | { | ||
51 | return ($this->handler)($var); | ||
52 | } | ||
53 | } | ||