Completed
Push — master ( e5d33b...d5d3e2 )
by Thomas
02:22
created

ConfigManifestProxy::getTrackEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LeKoala\DebugBar\Proxy;
4
5
use SilverStripe\Config\Collections\CachedConfigCollection;
6
7
class ConfigManifestProxy extends CachedConfigCollection
8
{
9
    /**
10
     * @var CachedConfigCollection
11
     */
12
    protected $parent;
13
14
    /**
15
     * @var array
16
     */
17
    protected static $configCalls = [];
18
19
    /**
20
     * @var boolean
21
     */
22
    protected $trackEmpty = false;
23
24
    /**
25
     * @param CachedConfigCollection $parent
26
     */
27
    public function __construct(CachedConfigCollection $parent)
28
    {
29
        $this->parent = $parent;
30
31
        $this->collection = $this->parent->getCollection();
32
        $this->cache = $this->parent->getCache();
33
        $this->flush = $this->parent->getFlush();
34
        $this->collectionCreator = $this->parent->getCollectionCreator();
35
    }
36
37
    /**
38
     * Monitor calls made to get configuration during a request
39
     *
40
     * {@inheritDoc}
41
     */
42
    public function get($class, $name = null, $excludeMiddleware = 0)
43
    {
44
        $result = parent::get($class, $name, $excludeMiddleware);
45
46
        // Only track not empty values by default
47
        if ($result || $this->trackEmpty) {
48
            if (!isset(self::$configCalls[$class][$name])) {
49
                self::$configCalls[$class][$name] = [
50
                    'calls' => 0,
51
                    'result' => null
52
                ];
53
            }
54
            self::$configCalls[$class][$name]['calls']++;
55
            self::$configCalls[$class][$name]['result'] = $result;
56
        }
57
58
        return $result;
59
    }
60
61
    /**
62
     * Return a list of all config calls made during the request, including how many times they were called
63
     * and the result
64
     *
65
     * @return array
66
     */
67
    public static function getConfigCalls()
68
    {
69
        return self::$configCalls;
70
    }
71
72
    /**
73
     * Get the value of trackEmpty
74
     *
75
     * @return boolean
76
     */
77
    public function getTrackEmpty()
78
    {
79
        return $this->trackEmpty;
80
    }
81
82
    /**
83
     * Set the value of trackEmpty
84
     *
85
     * @param boolean $trackEmpty
86
     *
87
     * @return self
88
     */
89
    public function setTrackEmpty($trackEmpty)
90
    {
91
        $this->trackEmpty = $trackEmpty;
92
        return $this;
93
    }
94
}
95