PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / trunk
Kubio AI Page Builder vtrunk
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / symfony / var-dumper / Command / Descriptor / HtmlDescriptor.php
kubio / vendor / symfony / var-dumper / Command / Descriptor Last commit date
CliDescriptor.php 1 year ago DumpDescriptorInterface.php 4 years ago HtmlDescriptor.php 4 years ago
HtmlDescriptor.php
120 lines
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\VarDumper\Command\Descriptor;
13
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\VarDumper\Cloner\Data;
16 use Symfony\Component\VarDumper\Dumper\HtmlDumper;
17
18 /**
19 * Describe collected data clones for html output.
20 *
21 * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
22 *
23 * @final
24 */
25 class HtmlDescriptor implements DumpDescriptorInterface
26 {
27 private $dumper;
28 private $initialized = false;
29
30 public function __construct(HtmlDumper $dumper)
31 {
32 $this->dumper = $dumper;
33 }
34
35 public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
36 {
37 if (!$this->initialized) {
38 $styles = file_get_contents(__DIR__.'/../../Resources/css/htmlDescriptor.css');
39 $scripts = file_get_contents(__DIR__.'/../../Resources/js/htmlDescriptor.js');
40 $output->writeln("<style>$styles</style><script>$scripts</script>");
41 $this->initialized = true;
42 }
43
44 $title = '-';
45 if (isset($context['request'])) {
46 $request = $context['request'];
47 $controller = "<span class='dumped-tag'>{$this->dumper->dump($request['controller'], true, ['maxDepth' => 0])}</span>";
48 $title = sprintf('<code>%s</code> <a href="%s">%s</a>', $request['method'], $uri = $request['uri'], $uri);
49 $dedupIdentifier = $request['identifier'];
50 } elseif (isset($context['cli'])) {
51 $title = '<code>$ </code>'.$context['cli']['command_line'];
52 $dedupIdentifier = $context['cli']['identifier'];
53 } else {
54 $dedupIdentifier = uniqid('', true);
55 }
56
57 $sourceDescription = '';
58 if (isset($context['source'])) {
59 $source = $context['source'];
60 $projectDir = $source['project_dir'] ?? null;
61 $sourceDescription = sprintf('%s on line %d', $source['name'], $source['line']);
62 if (isset($source['file_link'])) {
63 $sourceDescription = sprintf('<a href="%s">%s</a>', $source['file_link'], $sourceDescription);
64 }
65 }
66
67 $isoDate = $this->extractDate($context, 'c');
68 $tags = array_filter([
69 'controller' => $controller ?? null,
70 'project dir' => $projectDir ?? null,
71 ]);
72
73 $output->writeln(<<<HTML
74 <article data-dedup-id="$dedupIdentifier">
75 <header>
76 <div class="row">
77 <h2 class="col">$title</h2>
78 <time class="col text-small" title="$isoDate" datetime="$isoDate">
79 {$this->extractDate($context)}
80 </time>
81 </div>
82 {$this->renderTags($tags)}
83 </header>
84 <section class="body">
85 <p class="text-small">
86 $sourceDescription
87 </p>
88 {$this->dumper->dump($data, true)}
89 </section>
90 </article>
91 HTML
92 );
93 }
94
95 private function extractDate(array $context, string $format = 'r'): string
96 {
97 return date($format, (int) $context['timestamp']);
98 }
99
100 private function renderTags(array $tags): string
101 {
102 if (!$tags) {
103 return '';
104 }
105
106 $renderedTags = '';
107 foreach ($tags as $key => $value) {
108 $renderedTags .= sprintf('<li><span class="badge">%s</span>%s</li>', $key, $value);
109 }
110
111 return <<<HTML
112 <div class="row">
113 <ul class="tags">
114 $renderedTags
115 </ul>
116 </div>
117 HTML;
118 }
119 }
120