Completed
Pull Request — master (#78)
by Franco
01:33
created

PartialCacheCollector::getTemplateCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace LeKoala\DebugBar\Collector;
4
5
use DebugBar\DataCollector\DataCollector;
6
use DebugBar\DataCollector\Renderable;
7
8
/**
9
 * Collects data about the partial cache hits and misses during a SilverStripe request
10
 */
11
class PartialCacheCollector extends DataCollector implements Renderable
12
{
13
14
    /**
15
     * Contains a list of all partial caches found.
16
     * @var array
17
     */
18
    private static $templateCache = array();
19
20
    public function getName()
21
    {
22
        return 'partial-cache';
23
    }
24
25
    public function collect()
26
    {
27
        $result = self::getTemplateCache();
28
        return [
29
            'count' => count($result),
30
            'calls' => $result
31
        ];
32
    }
33
34
    public function getWidgets()
35
    {
36
        $widgets = [
37
            'Partial Cache' => [
38
                'icon' => 'asterisk',
39
                'widget' => 'PhpDebugBar.Widgets.ConfigWidget',
40
                'map' => 'partial-cache.calls',
41
                'default' => '{}'
42
            ]
43
        ];
44
        if (count(self::getTemplateCache()) > 0) {
45
            $widgets['Partial Cache:badge'] = [
46
                'map' => 'partial-cache.count',
47
                'default' => 0
48
            ];
49
        }
50
51
        return $widgets;
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public static function getTemplateCache()
58
    {
59
        return (self::$templateCache) ?: array();
60
    }
61
62
    /**
63
     * Adds an item to the templateCache array
64
     * @param string $key
65
     * @param array $item
66
     */
67
    public static function addTemplateCache($key, $item)
68
    {
69
        self::$templateCache[$key] = $item;
70
    }
71
72
    /**
73
     * @param array $templateCache
74
     */
75
    public static function setTemplateCache($templateCache)
76
    {
77
        self::$templateCache = $templateCache;
78
    }
79
}
80