Completed
Push — master ( 0e0f65...ba2162 )
by Robbie
10s
created

SSViewerProxy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 5 1
A getTemplatesUsed() 0 4 1
A trackTemplateUsed() 0 4 1
1
<?php
2
3
namespace LeKoala\DebugBar\Proxy;
4
5
use LeKoala\DebugBar\DebugBar;
6
use SilverStripe\View\SSViewer;
7
8
/**
9
 * The template parser proxy will monitor the templates that are used during a page request. Since the
10
 * use of the template parser is behind cache checks, this will only execute during a cache flush.
11
 */
12
class SSViewerProxy extends SSViewer
13
{
14
    /**
15
     * Tracks all templates used in the current request
16
     *
17
     * @var array
18
     */
19
    protected static $allTemplates = array();
20
21
    /**
22
     * Whether the class has been used, meaning whether the page has been cached
23
     *
24
     * @var boolean
25
     */
26
    protected static $cached = true;
27
28
    /**
29
     * Overloaded to track all templates used in the current request
30
     *
31
     * {@inheritDoc}
32
     */
33
    public function process($item, $arguments = null, $inheritedScope = null)
34
    {
35
        self::trackTemplateUsed($this->chosen);
36
        return parent::process($item, $arguments, $inheritedScope);
37
    }
38
39
    /**
40
     * Get the templates used in the current request and the number of times they were called
41
     *
42
     * @return array
43
     */
44
    public static function getTemplatesUsed()
45
    {
46
        return static::$allTemplates;
47
    }
48
49
    /**
50
     * Remove the base path from a template file path and track its use
51
     *
52
     * @param string $templateName
53
     */
54
    protected static function trackTemplateUsed($templateName)
55
    {
56
        static::$allTemplates[] = str_ireplace(BASE_PATH, '', $templateName);
57
    }
58
}
59