Completed
Push — master ( 5e25c5...3a7a39 )
by Nekrasov
02:08
created

AbstractWidget::addConfigDefaults()   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 Arrilot\Widgets;
4
5
abstract class AbstractWidget
6
{
7
    /**
8
     * The number of seconds before each reload.
9
     * False means no reload at all.
10
     *
11
     * @var int|float|bool
12
     */
13
    public $reloadTimeout = false;
14
15
    /**
16
     * The number of minutes before cache expires.
17
     * False means no caching at all.
18
     *
19
     * @var int|float|bool
20
     */
21
    public $cacheTime = false;
22
23
    /**
24
     * The configuration array.
25
     *
26
     * @var array
27
     */
28
    protected $config = [];
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param array $config
34
     */
35
    public function __construct(array $config = [])
36
    {
37
        foreach ($config as $key => $value) {
38
            $this->config[$key] = $value;
39
        }
40
    }
41
42
    /**
43
     * Placeholder for async widget.
44
     * You can customize it by overwriting this method.
45
     *
46
     * @return string
47
     */
48
    public function placeholder()
49
    {
50
        return '';
51
    }
52
53
    /**
54
     * Async and reloadable widgets are wrapped in container.
55
     * You can customize it by overriding this method.
56
     *
57
     * @return array
58
     */
59
    public function container()
60
    {
61
        return [
62
            'element'       => 'div',
63
            'attributes'    => 'style="display:inline" class="arrilot-widget-container"',
64
        ];
65
    }
66
67
    /**
68
     * Cache key that is used if caching is enabled.
69
     *
70
     * @param $params
71
     *
72
     * @return string
73
     */
74
    public function cacheKey(array $params = [])
75
    {
76
        return 'arrilot.widgets.'.serialize($params);
77
    }
78
79
    /**
80
     * Add defaults to configuration array.
81
     *
82
     * @param array $defaults
83
     */
84
    protected function addConfigDefaults(array $defaults)
85
    {
86
        $this->config = array_merge($this->config, $defaults);
87
    }
88
}
89