Completed
Pull Request — master (#60)
by Robbie
01:30
created

ConfigManifestProxy::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 3
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
     * @param ConfigCollectionInterface $parent
21
     */
22
    public function __construct(CachedConfigCollection $parent)
23
    {
24
        $this->parent = $parent;
25
26
        $this->collection = $this->parent->getCollection();
27
        $this->cache = $this->parent->getCache();
28
        $this->flush = $this->parent->getFlush();
29
        $this->collectionCreator = $this->parent->getCollectionCreator();
30
    }
31
32
    /**
33
     * Monitor calls made to get configuration during a request
34
     *
35
     * {@inheritDoc}
36
     */
37
    public function get($class, $name = null, $excludeMiddleware = 0)
38
    {
39
        $result = parent::get($class, $name, $excludeMiddleware);
40
41
        if (!isset(self::$configCalls[$class][$name])) {
42
            self::$configCalls[$class][$name] = [
43
                'calls' => 0,
44
                'result' => null
45
            ];
46
        }
47
        self::$configCalls[$class][$name]['calls']++;
48
        self::$configCalls[$class][$name]['result'] = $result;
49
50
        return $result;
51
    }
52
53
    /**
54
     * Return a lsit of all config calls made during the request, including how many times they were called
55
     * and the result
56
     *
57
     * @return array
58
     */
59
    public static function getConfigCalls()
60
    {
61
        return self::$configCalls;
62
    }
63
}
64