1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of phpFastCache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt file. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author PastisD https://github.com/PastisD |
13
|
|
|
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Phpfastcache\Bundle\DataCollector; |
18
|
|
|
|
19
|
|
|
use Phpfastcache\Api as PhpfastcacheApi; |
20
|
|
|
use Phpfastcache\Bundle\PhpfastcacheBundle; |
21
|
|
|
use Phpfastcache\Bundle\Service\Phpfastcache; |
22
|
|
|
use Phpfastcache\CacheManager; |
23
|
|
|
use Symfony\Component\HttpFoundation\Request; |
24
|
|
|
use Symfony\Component\HttpFoundation\Response; |
25
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
26
|
|
|
|
27
|
|
|
class CacheCollector extends DataCollector |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \Phpfastcache\Bundle\Service\Phpfastcache |
31
|
|
|
*/ |
32
|
|
|
private $cache; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $twig_cache_blocks = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* CacheCollector constructor. |
41
|
|
|
* |
42
|
|
|
* @param \Phpfastcache\Bundle\Service\Phpfastcache $cache |
43
|
|
|
*/ |
44
|
|
|
public function __construct(Phpfastcache $cache) |
45
|
|
|
{ |
46
|
|
|
$this->cache = $cache; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
51
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
52
|
|
|
* @param \Exception|null $exception |
53
|
|
|
*/ |
54
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
55
|
|
|
{ |
56
|
|
|
$size = 0; |
57
|
|
|
$stats = []; |
58
|
|
|
$instances = []; |
59
|
|
|
$driverUsed = []; |
60
|
|
|
|
61
|
|
|
/** @var $cache */ |
62
|
|
|
foreach ($this->cache->getInstances() as $instanceName => $cache) { |
63
|
|
|
if ($cache->getStats()->getSize()) { |
64
|
|
|
$size += $cache->getStats()->getSize(); |
65
|
|
|
} |
66
|
|
|
$stats[ $instanceName ] = $cache->getStats(); |
67
|
|
|
$instances[ $instanceName ] = [ |
68
|
|
|
'driverName' => $cache->getDriverName(), |
69
|
|
|
'configClassName' => \get_class( $cache->getConfig()), |
70
|
|
|
'driverConfig' => $cache->getConfig()->toArray() |
71
|
|
|
]; |
72
|
|
|
$driverUsed[ $cache->getDriverName() ] = \get_class($cache); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->data = [ |
76
|
|
|
'twigCacheBlocks' => $this->twig_cache_blocks, |
77
|
|
|
'apiVersion' => PhpfastcacheApi::getVersion(), |
78
|
|
|
'pfcVersion' => PhpfastcacheApi::getPhpFastCacheVersion(), |
79
|
|
|
'bundleVersion' => phpFastCacheBundle::VERSION, |
80
|
|
|
'apiChangelog' => PhpfastcacheApi::getChangelog(), |
81
|
|
|
'driverUsed' => $driverUsed, |
82
|
|
|
'instances' => $instances, |
83
|
|
|
'stats' => $stats, |
84
|
|
|
'size' => $size, |
85
|
|
|
'hits' => [ |
86
|
|
|
'read' => (int) CacheManager::$ReadHits, |
87
|
|
|
'write' => (int) CacheManager::$WriteHits, |
88
|
|
|
], |
89
|
|
|
'coreConfig' => [ |
90
|
|
|
'driverList' => CacheManager::getDriverList(true), |
|
|
|
|
91
|
|
|
'namespacePath (deprecated)' => CacheManager::getNamespacePath(), |
92
|
|
|
], |
93
|
|
|
'projectConfig' => [ |
94
|
|
|
'twig_driver' => $this->cache->getConfig()['twig_driver'], |
95
|
|
|
'twig_block_debug' => $this->cache->getConfig()['twig_block_debug'], |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public function getStats() |
104
|
|
|
{ |
105
|
|
|
return $this->data[ 'stats' ]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function getInstances() |
112
|
|
|
{ |
113
|
|
|
return $this->data[ 'instances' ]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
public function getDriverUsed() |
120
|
|
|
{ |
121
|
|
|
return $this->data[ 'driverUsed' ]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function getHits() |
128
|
|
|
{ |
129
|
|
|
return $this->data[ 'hits' ]; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function getSize() |
136
|
|
|
{ |
137
|
|
|
return $this->data[ 'size' ]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
|
|
public function getCoreConfig() |
144
|
|
|
{ |
145
|
|
|
return $this->data[ 'coreConfig' ]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return mixed |
150
|
|
|
*/ |
151
|
|
|
public function getProjectConfig() |
152
|
|
|
{ |
153
|
|
|
return $this->data[ 'projectConfig' ]; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return mixed |
158
|
|
|
*/ |
159
|
|
|
public function getApiVersion() |
160
|
|
|
{ |
161
|
|
|
return $this->data[ 'apiVersion' ]; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return mixed |
166
|
|
|
*/ |
167
|
|
|
public function getPfcVersion() |
168
|
|
|
{ |
169
|
|
|
return $this->data[ 'pfcVersion' ]; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return mixed |
174
|
|
|
*/ |
175
|
|
|
public function getBundleVersion() |
176
|
|
|
{ |
177
|
|
|
return $this->data[ 'bundleVersion' ]; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return mixed |
182
|
|
|
*/ |
183
|
|
|
public function getApiChangelog() |
184
|
|
|
{ |
185
|
|
|
return $this->data[ 'apiChangelog' ]; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $blockName |
190
|
|
|
* @param array $cacheBlock |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
|
|
public function setTwigCacheBlock($blockName, array $cacheBlock) |
194
|
|
|
{ |
195
|
|
|
if(isset($this->twig_cache_blocks[$blockName])){ |
196
|
|
|
$this->twig_cache_blocks[$blockName] = array_merge($this->twig_cache_blocks[$blockName], $cacheBlock); |
197
|
|
|
}else{ |
198
|
|
|
$this->twig_cache_blocks[$blockName] = $cacheBlock; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return array |
207
|
|
|
*/ |
208
|
|
|
public function getTwigCacheBlocks() |
209
|
|
|
{ |
210
|
|
|
return $this->data[ 'twigCacheBlocks' ]; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function getName() |
217
|
|
|
{ |
218
|
|
|
return 'phpfastcache'; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function reset() |
222
|
|
|
{ |
223
|
|
|
// TODO: Implement reset() method. |
224
|
|
|
} |
225
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.