From 1fb5da6029ae42d6c264ced0700aa29fb753c6d7 Mon Sep 17 00:00:00 2001 From: Mathieu Haverkamp Date: Thu, 15 Aug 2024 10:27:48 +0200 Subject: [PATCH] Add working demo collector --- src/DataCollector/TestDataCollector.php | 41 ++++++++++++++++++ templates/collector/test.html.twig | 56 +++++++++++++++++++++++++ templates/default/homepage.html.twig | 3 ++ templates/stuff/_test.html.twig | 3 ++ 4 files changed, 103 insertions(+) create mode 100644 src/DataCollector/TestDataCollector.php create mode 100644 templates/collector/test.html.twig create mode 100644 templates/stuff/_test.html.twig diff --git a/src/DataCollector/TestDataCollector.php b/src/DataCollector/TestDataCollector.php new file mode 100644 index 0000000..7b1ea46 --- /dev/null +++ b/src/DataCollector/TestDataCollector.php @@ -0,0 +1,41 @@ +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/test.html.twig'; + } +} \ No newline at end of file diff --git a/templates/collector/test.html.twig b/templates/collector/test.html.twig new file mode 100644 index 0000000..a6baa36 --- /dev/null +++ b/templates/collector/test.html.twig @@ -0,0 +1,56 @@ +{% extends '@WebProfiler/Profiler/layout.html.twig' %} + +{% block toolbar %} + {% set icon %} + {% import 'stuff/_test.html.twig' as cavia %} + {# this is the content displayed as a panel in the toolbar #} + {{ cavia.cavia('cavia') }} + {% endset %} + + {% set text %} + {# this is the content displayed when hovering the mouse over + the toolbar panel #} +
+ Method + {{ collector.method }} +
+ +
+ Accepted content type + {{ collector.acceptableContentTypes|join(', ') }} +
+ {% 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. #} + + + Cavia + +{% endblock %} + +{% block panel %} + {# Optional, for showing the most details. #} +

Acceptable Content Types

+ + + + + + {% for type in collector.acceptableContentTypes %} + + + + {% endfor %} + + {# use the profiler_dump() function to render the contents of dumped objects #} + + {{ profiler_dump(collector.someObject) }} + +
Content Type
{{ type }}
+{% endblock %} \ No newline at end of file diff --git a/templates/default/homepage.html.twig b/templates/default/homepage.html.twig index a38a4dd..4f65fe1 100644 --- a/templates/default/homepage.html.twig +++ b/templates/default/homepage.html.twig @@ -1,5 +1,7 @@ {% extends 'base.html.twig' %} +{% from 'stuff/_test.html.twig' import cavia %} + {% block body_id 'homepage' %} {# @@ -23,6 +25,7 @@

{{ 'help.browse_app'|trans|raw }}

+ {{ cavia('asdasdasdasdasd') }}

{{ 'action.browse_app'|trans }} diff --git a/templates/stuff/_test.html.twig b/templates/stuff/_test.html.twig new file mode 100644 index 0000000..cbff6ff --- /dev/null +++ b/templates/stuff/_test.html.twig @@ -0,0 +1,3 @@ +{% macro cavia(cavia) %} + I AM A {{ cavia }} MACRO +{% endmacro cavia %} \ No newline at end of file