Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 9c09d16

Browse files
authored
Merge pull request #255 from pingcheng/dev-dump
add dump Helpers
2 parents 76b1ade + cbf0f6e commit 9c09d16

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Helpers/Dump.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
4+
namespace SwooleTW\Http\Helpers;
5+
6+
7+
class Dump
8+
{
9+
// define the dumper class
10+
protected static $dumper_class = 'Symfony\Component\VarDumper\Dumper\HtmlDumper';
11+
protected static $cloner_class = 'Symfony\Component\VarDumper\Cloner\VarCloner';
12+
13+
public static function dd(...$args) {
14+
15+
// only works when these classes are existing
16+
// otherwise return false
17+
if (!class_exists(static::$dumper_class) || !class_exists(static::$cloner_class)) {
18+
return false;
19+
}
20+
21+
// init the dumper and cloner
22+
$dumper = new static::$dumper_class();
23+
$cloner = new static::$cloner_class();
24+
25+
// dump each var in the args
26+
foreach ($args as $arg) {
27+
if (defined('IN_PHPUNIT')) {
28+
continue;
29+
}
30+
$dumper->dump($cloner->cloneVar($arg));
31+
}
32+
33+
return true;
34+
}
35+
}

0 commit comments

Comments
 (0)