Skip to content

[Cache][WebProfilerBundle] Add adapter class to Cache DataCollector #46806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
<h3 class="tab-title">{{ name }} <span class="badge">{{ collector.statistics[name].calls }}</span></h3>

<div class="tab-content">
<h4>Adapter</h4>
<div class="card">
{% if collector.adapters[name] is defined %}
<code>{{ collector.adapters[name] }}</code>
{% else %}
<span class="text-muted">Unable to get adapter class.</span>
{% endif %}
</div>
{% if calls|length == 0 %}
<div class="empty">
<p>No calls were made for {{ name }} pool.</p>
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ public function clearCalls()
$this->calls = [];
}

public function getPool(): AdapterInterface
{
return $this->pool;
}

protected function start(string $name)
{
$this->calls[] = $event = new TraceableAdapterEvent();
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public function addInstance(string $name, TraceableAdapter $instance)
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
$empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []];
$empty = ['calls' => [], 'adapters' => [], 'config' => [], 'options' => [], 'statistics' => []];
$this->data = ['instances' => $empty, 'total' => $empty];
foreach ($this->instances as $name => $instance) {
$this->data['instances']['calls'][$name] = $instance->getCalls();
$this->data['instances']['adapters'][$name] = \get_debug_type($instance->getPool());
}

$this->data['instances']['statistics'] = $this->calculateStatistics();
Expand Down Expand Up @@ -96,6 +97,14 @@ public function getCalls(): mixed
return $this->data['instances']['calls'];
}

/**
* Method returns all logged Cache adapter classes.
*/
public function getAdapters(): array
{
return $this->data['instances']['adapters'];
}

private function calculateStatistics(): array
{
$statistics = [];
Expand Down