Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit f5f5edb

Browse files
committed
Profiler
1 parent 33d77da commit f5f5edb

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

DataCollector/CacheCollector.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace phpFastCache\Bundle\DataCollector;
4+
5+
use phpFastCache\Bundle\Service\Cache;
6+
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
7+
use Symfony\Component\HttpFoundation\Request;
8+
use Symfony\Component\HttpFoundation\Response;
9+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10+
11+
class CacheCollector extends DataCollector
12+
{
13+
/**
14+
* @var \phpFastCache\Bundle\Service\Cache
15+
*/
16+
private $cache;
17+
18+
/**
19+
* CacheCollector constructor.
20+
*
21+
* @param \phpFastCache\Bundle\Service\Cache $cache
22+
*/
23+
public function __construct(Cache $cache)
24+
{
25+
$this->cache = $cache;
26+
}
27+
28+
/**
29+
* @param \Symfony\Component\HttpFoundation\Request $request
30+
* @param \Symfony\Component\HttpFoundation\Response $response
31+
* @param \Exception|null $exception
32+
*/
33+
public function collect(Request $request, Response $response, \Exception $exception = null)
34+
{
35+
$this->data = [
36+
'cache' => $this->cache,
37+
];
38+
}
39+
40+
public function getCache()
41+
{
42+
/**
43+
* @var $name
44+
* @var ExtendedCacheItemPoolInterface $cache
45+
*/
46+
foreach($this->data['cache'] as $name => $cache) {
47+
var_dump($cache->getStats());
48+
}
49+
return $this->data['cache'];
50+
}
51+
52+
public function getName()
53+
{
54+
return 'phpfastcache.request_collector';
55+
}
56+
}

Resources/config/services.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
parameters:
22
php_fast_cache.cache.class: phpFastCache\Bundle\Service\Cache
3+
php_fast_cache.data_collector.class: phpFastCache\Bundle\DataCollector\CacheCollector
34

45
services:
56
phpfastcache:
67
class: "%php_fast_cache.cache.class%"
78
arguments:
8-
- "%phpfastcache%"
9+
- "%phpfastcache%"
10+
11+
phpfastcache.request_collector:
12+
class: "%php_fast_cache.data_collector.class%"
13+
arguments:
14+
- "@phpfastcache"
15+
public: false
16+
tags:
17+
-
18+
name: data_collector
19+
template: '@phpFastCache/data_collector/template.html.twig'
20+
id: 'phpfastcache.request_collector'
21+
priority: 300
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}
2+
3+
{% block toolbar %}
4+
{% set icon %}
5+
<span class="icon">{{ include('@phpFastCache/data_collector/icon.svg') }}</span>
6+
<span class="sf-toolbar-value">PhpFastCache</span>
7+
{% endset %}
8+
9+
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig') }}
10+
{% endblock %}
11+
12+
{% block menu %}
13+
<span class="label">
14+
<span class="icon">{{ include('@phpFastCache/data_collector/icon.svg') }}</span>
15+
<strong>PhpFastCache</strong>
16+
</span>
17+
{% endblock %}
18+
19+
{% block panel %}
20+
<div class="sf-tabs">
21+
{% for name, cache in collector.cache.instances %}
22+
<div class="tab">
23+
<h3 class="tab-title">{{ name }}</h3>
24+
<div class="tab-content">
25+
<h3>Info</h3>
26+
{{ dump(cache.stats.info) }}
27+
<h3>Size</h3>
28+
{{ dump(cache.stats.size) }}
29+
<h3>Data</h3>
30+
{{ dump(cache.stats.data) }}
31+
<h3>RawData</h3>
32+
{{ dump(cache.stats.rawData) }}
33+
</div>
34+
</div>
35+
{% endfor %}
36+
</div>
37+
{% endblock %}

Service/Cache.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ public function get($name)
6969

7070
return $this->cacheInstances[$name];
7171
}
72+
73+
/**
74+
* Return all cache instances
75+
*
76+
* @return \phpFastCache\Cache\ExtendedCacheItemPoolInterface[]
77+
*/
78+
public function getInstances()
79+
{
80+
return $this->cacheInstances;
81+
}
7282
}

0 commit comments

Comments
 (0)