This repository was archived by the owner on Jan 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +118
-1
lines changed Expand file tree Collapse file tree 5 files changed +118
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
parameters :
2
2
php_fast_cache.cache.class : phpFastCache\Bundle\Service\Cache
3
+ php_fast_cache.data_collector.class : phpFastCache\Bundle\DataCollector\CacheCollector
3
4
4
5
services :
5
6
phpfastcache :
6
7
class : " %php_fast_cache.cache.class%"
7
8
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
Original file line number Diff line number Diff line change
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 %}
Original file line number Diff line number Diff line change @@ -69,4 +69,14 @@ public function get($name)
69
69
70
70
return $ this ->cacheInstances [$ name ];
71
71
}
72
+
73
+ /**
74
+ * Return all cache instances
75
+ *
76
+ * @return \phpFastCache\Cache\ExtendedCacheItemPoolInterface[]
77
+ */
78
+ public function getInstances ()
79
+ {
80
+ return $ this ->cacheInstances ;
81
+ }
72
82
}
You can’t perform that action at this time.
0 commit comments