Skip to content

Commit

Permalink
Add working demo collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Haverkamp committed Aug 15, 2024
1 parent dd0e608 commit 1fb5da6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/DataCollector/TestDataCollector.php
Original file line number Diff line number Diff line change
@@ -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 TestDataCollector 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/test.html.twig';
}
}
56 changes: 56 additions & 0 deletions templates/collector/test.html.twig
Original file line number Diff line number Diff line change
@@ -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 #}
<span class="sf-toolbar-value">{{ cavia.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 %}
3 changes: 3 additions & 0 deletions templates/default/homepage.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends 'base.html.twig' %}

{% from 'stuff/_test.html.twig' import cavia %}

{% block body_id 'homepage' %}

{#
Expand All @@ -23,6 +25,7 @@
<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 }}
Expand Down
3 changes: 3 additions & 0 deletions templates/stuff/_test.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro cavia(cavia) %}
I AM A {{ cavia }} MACRO
{% endmacro cavia %}

0 comments on commit 1fb5da6

Please sign in to comment.