WidgetContentResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Victoire\Bundle\WidgetBundle\Resolver;
4
5
use Victoire\Bundle\WidgetBundle\Entity\Widget;
6
use Victoire\Bundle\WidgetBundle\Resolver\Chain\WidgetContentResolverChain;
7
8
class WidgetContentResolver
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
9
{
10
    private $widgetContentResolverChain;
11
12
    public function __construct(WidgetContentResolverChain $widgetContentResolverChain)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
13
    {
14
        $this->widgetContentResolverChain = $widgetContentResolverChain;
15
    }
16
17
    /**
18
     * Get content for the widget.
19
     *
20
     * @param Widget $widget
21
     *
22
     * @throws \Exception
23
     *
24
     * @return array
25
     */
26
    public function getWidgetContent(Widget $widget)
27
    {
28
        //the mode of display of the widget
29
        $mode = $widget->getMode();
30
31
        //the widget must have a mode
32
        if ($mode === null) {
33
            throw new \Exception('The widget ['.$widget->getId().'] has no mode.');
34
        }
35
36
        $resolver = $this->widgetContentResolverChain->getResolverForWidget($widget);
37
38
        switch ($mode) {
39
            case Widget::MODE_STATIC:
40
                $parameters = $resolver->getWidgetStaticContent($widget);
41
                break;
42
            case Widget::MODE_ENTITY:
43
                //get the content of the widget with its entity
44
                $parameters = $resolver->getWidgetEntityContent($widget);
45
                break;
46
            case Widget::MODE_BUSINESS_ENTITY:
47
                //get the content of the widget with its entity
48
                $parameters = $resolver->getWidgetBusinessEntityContent($widget);
49
                break;
50
            case Widget::MODE_QUERY:
51
                $parameters = $resolver->getWidgetQueryContent($widget);
52
                break;
53
            default:
54
                throw new \Exception('The mode ['.$mode.'] is not supported by the widget manager. Widget ID:['.$widget->getId().']');
55
        }
56
57
        return $parameters;
58
    }
59
}
60