1 | <?php |
||||
2 | |||||
3 | namespace EightPoints\Bundle\GuzzleBundle\Twig\Extension; |
||||
4 | |||||
5 | use Symfony\Component\VarDumper\Cloner\VarCloner; |
||||
6 | use Symfony\Component\VarDumper\Dumper\HtmlDumper; |
||||
7 | use Twig\Environment; |
||||
8 | use Twig\Extension\AbstractExtension; |
||||
9 | use Twig\TwigFunction; |
||||
10 | |||||
11 | class DebugExtension extends AbstractExtension |
||||
12 | { |
||||
13 | /** |
||||
14 | * @return array |
||||
15 | */ |
||||
16 | public function getFunctions() : array |
||||
17 | { |
||||
18 | return [ |
||||
19 | new TwigFunction( |
||||
20 | 'eight_points_guzzle_dump', |
||||
21 | [$this, 'dump'], |
||||
22 | ['is_safe' => ['html'], 'needs_environment' => true] |
||||
23 | ), |
||||
24 | ]; |
||||
25 | } |
||||
26 | |||||
27 | /** |
||||
28 | * @param Environment $env |
||||
29 | * @param $value |
||||
30 | * |
||||
31 | * @throws \Exception |
||||
32 | * |
||||
33 | * @return bool|string |
||||
34 | */ |
||||
35 | public function dump(Environment $env, $value) |
||||
36 | { |
||||
37 | $cloner = new VarCloner(); |
||||
38 | |||||
39 | $dump = fopen('php://memory', 'r+b'); |
||||
40 | $dumper = new HtmlDumper($dump, $env->getCharset()); |
||||
41 | |||||
42 | $dumper->dump($cloner->cloneVar($value)); |
||||
43 | rewind($dump); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
44 | |||||
45 | return stream_get_contents($dump); |
||||
0 ignored issues
–
show
It seems like
$dump can also be of type false ; however, parameter $handle of stream_get_contents() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
46 | } |
||||
47 | |||||
48 | /** |
||||
49 | * This method is removed from interface in Twig v2.0 |
||||
50 | * |
||||
51 | * @TODO Remove this method when drop support of Symfony < 5.0 |
||||
52 | * |
||||
53 | * @return string |
||||
54 | */ |
||||
55 | public function getName() : string |
||||
56 | { |
||||
57 | return get_class($this); |
||||
58 | } |
||||
59 | } |
||||
60 |