|
1
|
|
|
<?php |
|
2
|
|
|
namespace rtens\domin\delivery\web\renderers\dashboard\types; |
|
3
|
|
|
|
|
4
|
|
|
use rtens\domin\delivery\RendererRegistry; |
|
5
|
|
|
use rtens\domin\delivery\web\Element; |
|
6
|
|
|
use rtens\domin\delivery\web\renderers\dashboard\DashboardItem; |
|
7
|
|
|
use rtens\domin\delivery\web\WebRenderer; |
|
8
|
|
|
|
|
9
|
|
|
class Column implements DashboardItem { |
|
10
|
|
|
|
|
11
|
|
|
/** @var mixed */ |
|
12
|
|
|
public $content; |
|
13
|
|
|
|
|
14
|
|
|
/** @var int[] */ |
|
15
|
|
|
private $widths; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param mixed $content |
|
19
|
|
|
* @param int $width Out of 12 |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct($content, $width) { |
|
22
|
|
|
$this->content = $content; |
|
23
|
|
|
$this->widths = ['lg' => $width]; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setMediumWidth($width) { |
|
27
|
|
|
$this->widths['md'] = $width; |
|
28
|
|
|
return $this; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setSmallWidth($width) { |
|
32
|
|
|
$this->widths['sm'] = $width; |
|
33
|
|
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setExtraSmallWidth($width) { |
|
37
|
|
|
$this->widths['xs'] = $width; |
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param RendererRegistry $renderers |
|
43
|
|
|
* @return Element |
|
44
|
|
|
* @throws \Exception |
|
45
|
|
|
*/ |
|
46
|
|
|
public function render(RendererRegistry $renderers) { |
|
47
|
|
|
return new Element('div', |
|
48
|
|
|
['class' => $this->makeWidthClasses()], |
|
49
|
|
|
[$renderers->getRenderer($this->content)->render($this->content)]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param RendererRegistry $renderers |
|
54
|
|
|
* @return \rtens\domin\delivery\web\Element[] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function headElements(RendererRegistry $renderers) { |
|
57
|
|
|
$renderer = $renderers->getRenderer($this->content); |
|
58
|
|
|
if ($renderer instanceof WebRenderer) { |
|
59
|
|
|
return $renderer->headElements($this->content); |
|
60
|
|
|
} |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private function makeWidthClasses() { |
|
65
|
|
|
$classes = []; |
|
66
|
|
|
foreach ($this->widths as $size => $width) { |
|
67
|
|
|
$classes[] = "col-$size-$width"; |
|
68
|
|
|
} |
|
69
|
|
|
return implode(' ', $classes); |
|
70
|
|
|
} |
|
71
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..