Completed
Pull Request — master (#38)
by Robbie
01:36
created

DebugBarTemplateParserProxy::compileString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 4
1
<?php
2
3
/**
4
 * The template parser proxy will monitor the templates that are used during a page request. Since the
5
 * use of the template parser is behind cache checks, this will only execute during a cache flush.
6
 */
7
class DebugBarTemplateParserProxy extends SSTemplateParser
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * Tracks all templates used in the current request
11
     *
12
     * @var array
13
     */
14
    protected static $allTemplates = array();
15
16
    /**
17
     * Whether the class has been used, meaning whether the page has been cached
18
     *
19
     * @var boolean
20
     */
21
    protected static $cached = true;
22
23
    /**
24
     * Overloaded to track all templates used in the current request
25
     *
26
     * {@inheritDoc}
27
     */
28
    public function compileString($string, $templateName = '', $includeDebuggingComments = false, $topTemplate = true)
29
    {
30
        static::$cached = false;
31
32
        if (DebugBar::config()->force_proxy) {
33
            static::trackTemplateUsed($templateName);
34
        }
35
36
        return parent::compileString($string, $templateName, $includeDebuggingComments, $topTemplate);
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
     * Determines whether the template rendering is cached or not based on whether the compileString method has been
51
     * called at any point.
52
     *
53
     * @return bool
54
     */
55
    public static function getCached()
56
    {
57
        return static::$cached;
58
    }
59
60
    /**
61
     * Remove the base path from a template file path and track its use
62
     *
63
     * @param string $templateName
64
     */
65
    protected static function trackTemplateUsed($templateName)
66
    {
67
        static::$allTemplates[] = str_ireplace(BASE_PATH, '', $templateName);
68
    }
69
}
70