Completed
Push — master ( 904db4...e42307 )
by Leny
18s
created

VictoireCollector::addCachedWidget()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Victoire\Bundle\CoreBundle\DataCollector;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
8
use Victoire\Bundle\WidgetBundle\Entity\Widget;
9
10
/**
11
 * This collector displays a victoire element in toolbar.
12
 */
13
class VictoireCollector extends DataCollector
14
{
15
    protected $cachedWidgets = [];
16
17
    /**
18
     * @param Request         $request
19
     * @param Response        $response
20
     * @param \Exception|null $exception
21
     */
22
    public function collect(Request $request, Response $response, \Exception $exception = null)
23
    {
24
        $this->data = [
25
            'cachedWidgetCount' => count($this->cachedWidgets),
26
        ];
27
    }
28
29
    /**
30
     * Add a widget to the stack of cached widgets.
31
     *
32
     * @param Widget $widget
33
     */
34
    public function addCachedWidget(Widget $widget)
35
    {
36
        $this->cachedWidgets[] = $widget;
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getCachedWidgetCount()
43
    {
44
        return $this->data['cachedWidgetCount'];
45
    }
46
47
    public function getName()
48
    {
49
        return 'victoire_core.victoire_collector';
50
    }
51
}
52