Skip to content

Commit d035042

Browse files
committed
Refactored globals
1 parent d57ef0e commit d035042

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

src/OpCacheGUI/OpCache/Status.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace OpCacheGUI\OpCache;
1515

1616
use OpCacheGUI\Format\Byte;
17-
use OpCacheGUI\I18n\FileTranslator;
17+
use OpCacheGUI\I18n\Translator;
1818

1919
/**
2020
* Container for the current status of OpCache
@@ -37,6 +37,11 @@ class Status
3737
*/
3838
private $byteFormatter;
3939

40+
/**
41+
* @var \OpCacheGUI\I18n\Translator A translator
42+
*/
43+
private $translator;
44+
4045
/**
4146
* @var array The (unfiltered) output of opcache_get_status()
4247
*/
@@ -45,12 +50,14 @@ class Status
4550
/**
4651
* Creates instance
4752
*
48-
* @param \OpCacheGUI\Format\Byte $byteFormatter Formatter of byte values
49-
* @param array $statusData The (unfiltered) output of opcache_get_status()
53+
* @param \OpCacheGUI\Format\Byte $byteFormatter Formatter of byte values
54+
* @param \OpCacheGUI\I18n\Translator $translator A translator
55+
* @param array $statusData The (unfiltered) output of opcache_get_status()
5056
*/
51-
public function __construct(Byte $byteFormatter, array $statusData)
57+
public function __construct(Byte $byteFormatter, Translator $translator, array $statusData)
5258
{
5359
$this->byteFormatter = $byteFormatter;
60+
$this->translator = $translator;
5461
$this->statusData = $statusData;
5562
}
5663

@@ -94,23 +101,22 @@ public function getMemoryInfo()
94101
public function getGraphMemoryInfo()
95102
{
96103
$memory = $this->statusData['memory_usage'];
97-
global $translator;
98104

99105
return json_encode([
100106
[
101107
'value' => $memory['used_memory'],
102108
'color' => self::RED,
103-
'label' => $translator->translate('graph.memory.used'),
109+
'label' => $this->translator->translate('graph.memory.used'),
104110
],
105111
[
106112
'value' => $memory['free_memory'],
107113
'color' => self::GREEN,
108-
'label' => $translator->translate('graph.memory.free'),
114+
'label' => $this->translator->translate('graph.memory.free'),
109115
],
110116
[
111117
'value' => $memory['wasted_memory'],
112118
'color' => self::DARK_GREEN,
113-
'label' => $translator->translate('graph.memory.wasted'),
119+
'label' => $this->translator->translate('graph.memory.wasted'),
114120
],
115121
]);
116122
}
@@ -181,23 +187,22 @@ public function getStatsInfo()
181187
public function getGraphKeyStatsInfo()
182188
{
183189
$stats = $this->statusData['opcache_statistics'];
184-
global $translator;
185190

186191
return json_encode([
187192
[
188193
'value' => $stats['num_cached_scripts'],
189194
'color' => self::RED,
190-
'label' => $translator->translate('graph.keys.scripts'),
195+
'label' => $this->translator->translate('graph.keys.scripts'),
191196
],
192197
[
193198
'value' => $stats['max_cached_keys'] - $stats['num_cached_keys'],
194199
'color' => self::GREEN,
195-
'label' => $translator->translate('graph.keys.free'),
200+
'label' => $this->translator->translate('graph.keys.free'),
196201
],
197202
[
198203
'value' => $stats['num_cached_keys'] - $stats['num_cached_scripts'],
199204
'color' => self::DARK_GREEN,
200-
'label' => $translator->translate('graph.keys.wasted'),
205+
'label' => $this->translator->translate('graph.keys.wasted'),
201206
],
202207
]);
203208
}
@@ -210,23 +215,22 @@ public function getGraphKeyStatsInfo()
210215
public function getGraphHitStatsInfo()
211216
{
212217
$stats = $this->statusData['opcache_statistics'];
213-
global $translator;
214218

215219
return json_encode([
216220
[
217221
'value' => $stats['hits'],
218222
'color' => self::RED,
219-
'label' => $translator->translate('graph.hits.hits'),
223+
'label' => $this->translator->translate('graph.hits.hits'),
220224
],
221225
[
222226
'value' => $stats['misses'],
223227
'color' => self::GREEN,
224-
'label' => $translator->translate('graph.hits.misses'),
228+
'label' => $this->translator->translate('graph.hits.misses'),
225229
],
226230
[
227231
'value' => $stats['blacklist_misses'],
228232
'color' => self::DARK_GREEN,
229-
'label' => $translator->translate('graph.hits.blacklist'),
233+
'label' => $this->translator->translate('graph.hits.blacklist'),
230234
],
231235
]);
232236
}

template/cached.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, opcache_get_status());
2+
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, $this->translator, opcache_get_status());
33
$classCycler = new OpCacheGUI\Presentation\ClassCycler(['odd', 'even']);
44

55
$directories = [];

template/graphs.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, opcache_get_status());
2+
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, $this->translator, opcache_get_status());
33
$classCycler = new OpCacheGUI\Presentation\ClassCycler(['odd', 'even']);
44

55
$memoryInfo = $status->getMemoryInfo();

template/status.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, opcache_get_status());
2+
$status = new OpCacheGUI\OpCache\Status($this->byteFormatter, $this->translator, opcache_get_status());
33
$classCycler = new OpCacheGUI\Presentation\ClassCycler(['odd', 'even']);
44
?>
55

0 commit comments

Comments
 (0)