1 | <?php |
||
8 | class Column implements Buildable |
||
9 | { |
||
10 | /** |
||
11 | * grid system prefix width |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $width = []; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $contents = []; |
||
21 | |||
22 | /** |
||
23 | * Column constructor. |
||
24 | * |
||
25 | * @param $content |
||
26 | * @param int $width |
||
27 | */ |
||
28 | public function __construct($content, $width = 12) |
||
29 | { |
||
30 | if ($content instanceof \Closure) { |
||
31 | call_user_func($content, $this); |
||
32 | } else { |
||
33 | $this->append($content); |
||
34 | } |
||
35 | |||
36 | ///// set width. |
||
37 | // if null, or $this->width is empty array, set as "md" => "12" |
||
38 | if (is_null($width) || (is_array($width) && count($width) === 0)) { |
||
39 | $this->width['md'] = 12; |
||
40 | } |
||
41 | // $this->width is number(old version), set as "md" => $width |
||
42 | elseif (is_numeric($width)) { |
||
43 | $this->width['md'] = $width; |
||
44 | } else { |
||
45 | $this->width = $width; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Append content to column. |
||
51 | * |
||
52 | * @param $content |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function append($content) |
||
62 | |||
63 | /** |
||
64 | * Add a row for column. |
||
65 | * |
||
66 | * @param $content |
||
67 | * |
||
68 | * @return Column |
||
69 | */ |
||
70 | public function row($content) |
||
90 | |||
91 | /** |
||
92 | * Build column html. |
||
93 | */ |
||
94 | public function build() |
||
108 | |||
109 | /** |
||
110 | * Start column. |
||
111 | */ |
||
112 | protected function startColumn() |
||
120 | |||
121 | /** |
||
122 | * End column. |
||
123 | */ |
||
124 | protected function endColumn() |
||
128 | } |
||
129 |