1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | /* |
||||||
6 | * This file is part of the ekino Drupal Debug project. |
||||||
7 | * |
||||||
8 | * (c) ekino |
||||||
9 | * |
||||||
10 | * For the full copyright and license information, please view the LICENSE |
||||||
11 | * file that was distributed with this source code. |
||||||
12 | */ |
||||||
13 | |||||||
14 | namespace Ekino\Drupal\Debug\Action\DisplayDumpLocation; |
||||||
15 | |||||||
16 | use Ekino\Drupal\Debug\Action\EventSubscriberActionInterface; |
||||||
17 | use Ekino\Drupal\Debug\Kernel\Event\DebugKernelEvents; |
||||||
18 | use Symfony\Component\VarDumper\Cloner\VarCloner; |
||||||
19 | use Symfony\Component\VarDumper\Dumper\CliDumper; |
||||||
20 | use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider; |
||||||
21 | use Symfony\Component\VarDumper\Dumper\HtmlDumper; |
||||||
22 | use Symfony\Component\VarDumper\VarDumper; |
||||||
23 | |||||||
24 | class DisplayDumpLocationAction implements EventSubscriberActionInterface |
||||||
25 | { |
||||||
26 | /** |
||||||
27 | * {@inheritdoc} |
||||||
28 | */ |
||||||
29 | 1 | public static function getSubscribedEvents(): array |
|||||
30 | { |
||||||
31 | return array( |
||||||
32 | 1 | DebugKernelEvents::ON_KERNEL_INSTANTIATION => 'process', |
|||||
33 | ); |
||||||
34 | } |
||||||
35 | |||||||
36 | 1 | public function process(): void |
|||||
37 | { |
||||||
38 | 1 | if (!\class_exists(SourceContextProvider::class)) { |
|||||
39 | return; |
||||||
40 | } |
||||||
41 | |||||||
42 | 1 | $cloner = new VarCloner(); |
|||||
43 | 1 | $dumper = \in_array(\PHP_SAPI, array('cli', 'phpdbg'), true) ? new CliDumper() : new HtmlDumper(); |
|||||
44 | |||||||
45 | VarDumper::setHandler(static function ($var) use ($cloner, $dumper): void { |
||||||
46 | (function (): void { |
||||||
47 | list('name' => $name, 'file' => $file, 'line' => $line) = (new SourceContextProvider())->getContext(); |
||||||
48 | |||||||
49 | $attr = array(); |
||||||
50 | if ($this instanceof HtmlDumper) { |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
51 | if (\is_string($file)) { |
||||||
52 | $attr = array( |
||||||
53 | 'file' => $file, |
||||||
54 | 'line' => $line, |
||||||
55 | 'title' => $file, |
||||||
56 | ); |
||||||
57 | } |
||||||
58 | } else { |
||||||
59 | $name = $file; |
||||||
60 | } |
||||||
61 | |||||||
62 | $this->line = \sprintf('%s on line %s:', $this->style('meta', $name, $attr), $this->style('meta', $line)); |
||||||
0 ignored issues
–
show
The method
style() does not exist on Ekino\Drupal\Debug\Actio...splayDumpLocationAction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
63 | $this->dumpLine(0); |
||||||
0 ignored issues
–
show
The method
dumpLine() does not exist on Ekino\Drupal\Debug\Actio...splayDumpLocationAction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
64 | })->bindTo($dumper, $dumper)(); |
||||||
65 | |||||||
66 | $dumper->dump($cloner->cloneVar($var)); |
||||||
67 | 1 | }); |
|||||
68 | 1 | } |
|||||
69 | } |
||||||
70 |