Skip to content

Instantly share code, notes, and snippets.

@jmsche
Created June 17, 2025 06:53
Show Gist options
  • Select an option

  • Save jmsche/cd2d12e044e681b9ef76b34f5a41ff1e to your computer and use it in GitHub Desktop.

Select an option

Save jmsche/cd2d12e044e681b9ef76b34f5a41ff1e to your computer and use it in GitHub Desktop.
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
{% block toolbar %}
{% set icon %}
{{ include('data_collector/icon.svg') }}
<span class="sf-toolbar-value">{{ collector.gitBranch }}</span>
{% endset %}
{% set text %}
<div class="sf-toolbar-info-piece">
<b>Last commit</b>
<span>{{ collector.lastCommitDate }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Author</b>
<span>{{ collector.lastCommitAuthor }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Message</b>
<span style="text-overflow: ellipsis; line-height: 15px; max-width: 400px; overflow: hidden; vertical-align: bottom;">{{ collector.lastCommitMessage }}</span>
</div>
{% endset %}
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: false }) }}
{% endblock %}
<?php
declare(strict_types=1);
namespace App\DataCollector;
use App\Base\Core\Manager\GitManager;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
#[AutoconfigureTag('data_collector', ['template' => 'data_collector/git_data.html.twig', 'id' => 'app.git_data_collector'])]
final class GitDataCollector extends DataCollector
{
public function __construct(private GitManager $gitManager)
{
}
public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
$this->data = [
'git_branch' => $this->gitManager->getBranchName(),
'last_commit_message' => $this->gitManager->getLastCommitMessage(),
'logs' => $this->gitManager->getLastCommitDetail(),
];
}
public function getName(): string
{
return 'app.git_data_collector';
}
public function reset(): void
{
$this->data = [];
}
public function getGitBranch(): string
{
return $this->data['git_branch'];
}
public function getLastCommitMessage(): string
{
return $this->data['last_commit_message'];
}
public function getLastCommitAuthor(): string
{
return $this->data['logs']['author'];
}
public function getLastCommitDate(): string
{
return $this->data['logs']['date'];
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment