From 8188b36aff796ce34bb6a2fb06b0873b9fd4d91e Mon Sep 17 00:00:00 2001 From: Mathieu Haverkamp <m.haverkamp@paragin.com> Date: Thu, 15 Aug 2024 10:34:14 +0200 Subject: [PATCH] Add broken data collector template --- src/DataCollector/AnotherDataCollector.php | 41 +++++++++++++++ templates/collector/another.html.twig | 61 ++++++++++++++++++++++ templates/default/homepage.html.twig | 3 +- 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/DataCollector/AnotherDataCollector.php create mode 100644 templates/collector/another.html.twig diff --git a/src/DataCollector/AnotherDataCollector.php b/src/DataCollector/AnotherDataCollector.php new file mode 100644 index 0000000..1855951 --- /dev/null +++ b/src/DataCollector/AnotherDataCollector.php @@ -0,0 +1,41 @@ +<?php + +namespace App\DataCollector; + +use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\VarDumper\Cloner\Data; + +class AnotherDataCollector extends AbstractDataCollector +{ + + public function collect(Request $request, Response $response, ?\Throwable $exception = null): void + { + $this->data = [ + 'method' => $request->getMethod(), + 'acceptable_content_types' => $request->getAcceptableContentTypes(), + ]; + } + + public function getMethod(): string + { + return $this->data['method']; + } + + public function getAcceptableContentTypes(): array + { + return $this->data['acceptable_content_types']; + } + + public function getSomeObject(): Data + { + // use the cloneVar() method to dump collected data in the profiler + return $this->cloneVar($this->data['method']); + } + + public static function getTemplate(): ?string + { + return 'collector/another.html.twig'; + } +} \ No newline at end of file diff --git a/templates/collector/another.html.twig b/templates/collector/another.html.twig new file mode 100644 index 0000000..da4853f --- /dev/null +++ b/templates/collector/another.html.twig @@ -0,0 +1,61 @@ +{% extends '@WebProfiler/Profiler/layout.html.twig' %} + +{# Now this breaks stuff #} +{% from 'stuff/_test.html.twig' import cavia %} + +{% block toolbar %} + {% set icon %} + {# this is the content displayed as + a panel in the toolbar #} + + {# Especially here #} + <span class="sf-toolbar-value">{{ cavia('cavia') }}</span> + {% endset %} + + {% set text %} + {# this is the content displayed when hovering the mouse over + the toolbar panel #} + <div class="sf-toolbar-info-piece"> + <b>Method</b> + <span>{{ collector.method }}</span> + </div> + + <div class="sf-toolbar-info-piece"> + <b>Accepted content type</b> + <span>{{ collector.acceptableContentTypes|join(', ') }}</span> + </div> + {% endset %} + + {# the 'link' value set to 'false' means that this panel doesn't + show a section in the web profiler #} + {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: false }) }} +{% endblock %} + +{% block menu %} + {# This left-hand menu appears when using the full-screen profiler. #} + <span class="label"> + <span class="icon"><img src="..." alt=""/></span> + <strong>Cavia</strong> + </span> +{% endblock %} + +{% block panel %} + {# Optional, for showing the most details. #} + <h2>Acceptable Content Types</h2> + <table> + <tr> + <th>Content Type</th> + </tr> + + {% for type in collector.acceptableContentTypes %} + <tr> + <td>{{ type }}</td> + </tr> + {% endfor %} + + {# use the profiler_dump() function to render the contents of dumped objects #} + <tr> + {{ profiler_dump(collector.someObject) }} + </tr> + </table> +{% endblock %} \ No newline at end of file diff --git a/templates/default/homepage.html.twig b/templates/default/homepage.html.twig index 4f65fe1..76c09ff 100644 --- a/templates/default/homepage.html.twig +++ b/templates/default/homepage.html.twig @@ -19,13 +19,14 @@ {{ render_language_selector(true) }} </div> + <h1>{{ cavia('asdasdasdasdasd') }} import</h1> + <div class="row"> <div class="col-sm"> <div class="jumbotron"> <p> {{ 'help.browse_app'|trans|raw }} </p> - {{ cavia('asdasdasdasdasd') }} <p> <a class="btn btn-primary btn-lg" href="{{ path('blog_index') }}"> <i class="fa fa-users" aria-hidden="true"></i> {{ 'action.browse_app'|trans }}