@@ -135,31 +135,31 @@ discard block |
||
135 | 135 | //::span('inner text', $attributes) |
136 | 136 | public static function __callStatic($element_type, $arguments) |
137 | 137 | { |
138 | - $i=0; |
|
139 | - $element_inner =$arguments[$i++]??null; |
|
140 | - $attributes=$arguments[$i++]??[]; |
|
138 | + $i = 0; |
|
139 | + $element_inner = $arguments[$i++] ?? null; |
|
140 | + $attributes = $arguments[$i++] ?? []; |
|
141 | 141 | |
142 | 142 | return new Element($element_type, $element_inner, $attributes); |
143 | 143 | } |
144 | 144 | |
145 | 145 | // TODO labels should mandatory, accessibility |
146 | 146 | // TODO implement all options of font-awesome |
147 | - public static function fas($icon, $title=null, $attributes=[]) |
|
147 | + public static function fas($icon, $title = null, $attributes = []) |
|
148 | 148 | { |
149 | 149 | $attributes['title'] = $attributes['title'] ?? $title; // attributes take precedence |
150 | 150 | $attributes['class'] = sprintf('fas fa-%s %s', $icon, $attributes['class'] ?? ''); |
151 | - return new Element('i','', $attributes); |
|
151 | + return new Element('i', '', $attributes); |
|
152 | 152 | } |
153 | 153 | |
154 | - public static function checkbutton($field_name, $field_value, $field_label, $attributes=[]) |
|
154 | + public static function checkbutton($field_name, $field_value, $field_label, $attributes = []) |
|
155 | 155 | { |
156 | - if(!isset($attributes['id'])) |
|
157 | - $attributes['id']=$field_name; |
|
156 | + if (!isset($attributes['id'])) |
|
157 | + $attributes['id'] = $field_name; |
|
158 | 158 | |
159 | - if(!isset($attributes['type'])) |
|
160 | - $attributes['type']='checkbox'; // default |
|
159 | + if (!isset($attributes['type'])) |
|
160 | + $attributes['type'] = 'checkbox'; // default |
|
161 | 161 | |
162 | - if(isset($attributes['is_checked']) && $attributes['is_checked'] === true) // for boolean checkbuttons |
|
162 | + if (isset($attributes['is_checked']) && $attributes['is_checked'] === true) // for boolean checkbuttons |
|
163 | 163 | { |
164 | 164 | $attributes['checked'] = 'checked'; |
165 | 165 | unset($attributes['is_checked']); |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | ['class'=>'checkbutton']); |
173 | 173 | } |
174 | 174 | |
175 | - public static function img($src, $title, $attributes=[]) |
|
175 | + public static function img($src, $title, $attributes = []) |
|
176 | 176 | { |
177 | 177 | $attributes['src'] = $attributes['src'] ?? $src; |
178 | 178 | $attributes['title'] = $attributes['title'] ?? $title; |
179 | 179 | return new Element('img', null, $attributes); |
180 | 180 | } |
181 | 181 | |
182 | - public static function a($href, $label, $attributes=[]) |
|
182 | + public static function a($href, $label, $attributes = []) |
|
183 | 183 | { |
184 | 184 | $attributes['href'] = $attributes['href'] ?? $href; |
185 | 185 | return new Element('a', $label, $attributes); |
@@ -10,18 +10,18 @@ discard block |
||
10 | 10 | public static function __callStatic($element_type, $arguments) |
11 | 11 | { |
12 | 12 | // arguments [name, value, [attributes], [errors]] |
13 | - $i=0; |
|
14 | - $field_name= $arguments[$i++] ?? null; |
|
15 | - $field_value= $arguments[$i++] ?? null; |
|
16 | - $attributes= $arguments[$i++] ?? []; |
|
17 | - $errors= $arguments[$i++] ?? []; |
|
13 | + $i = 0; |
|
14 | + $field_name = $arguments[$i++] ?? null; |
|
15 | + $field_value = $arguments[$i++] ?? null; |
|
16 | + $attributes = $arguments[$i++] ?? []; |
|
17 | + $errors = $arguments[$i++] ?? []; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | $attributes['type'] = $element_type; |
21 | 21 | $attributes['name'] = $attributes['name'] ?? $field_name; |
22 | 22 | $attributes['value'] = $attributes['value'] ?? $field_value; |
23 | 23 | |
24 | - switch($attributes['type']) |
|
24 | + switch ($attributes['type']) |
|
25 | 25 | { |
26 | 26 | case 'datetime': |
27 | 27 | $attributes['type'] = 'datetime-local'; |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | |
36 | 36 | } |
37 | 37 | |
38 | - public static function input($field_name, $field_value=null, $attributes=[], $errors=[]) |
|
38 | + public static function input($field_name, $field_value = null, $attributes = [], $errors = []) |
|
39 | 39 | { |
40 | 40 | |
41 | - if(isset($attributes['disabled']) || !isset($attributes['type']) || in_array('disabled', $attributes, true)) |
|
41 | + if (isset($attributes['disabled']) || !isset($attributes['type']) || in_array('disabled', $attributes, true)) |
|
42 | 42 | $attributes['type'] = 'text'; |
43 | 43 | else |
44 | 44 | $attributes['type'] = $attributes['type'] ?? 'text'; |
@@ -49,45 +49,45 @@ discard block |
||
49 | 49 | return self::element_with_errors('input', null, $attributes, isset($errors[$field_name])); |
50 | 50 | } |
51 | 51 | |
52 | - public static function textarea($field_name, $field_value=null, $attributes=[], $errors=[]) |
|
52 | + public static function textarea($field_name, $field_value = null, $attributes = [], $errors = []) |
|
53 | 53 | { |
54 | 54 | $attributes['name'] = $attributes['name'] ?? $field_name; |
55 | 55 | return self::element_with_errors('textarea', $field_value, $attributes, isset($errors[$field_name])); |
56 | 56 | } |
57 | 57 | |
58 | - public static function select($field_name, $option_list, $selected = null, $attributes=[], $errors=[]) |
|
58 | + public static function select($field_name, $option_list, $selected = null, $attributes = [], $errors = []) |
|
59 | 59 | { |
60 | 60 | $attributes['name'] = $attributes['name'] ?? $field_name; |
61 | 61 | |
62 | 62 | $options = ''; |
63 | - foreach($option_list as $value => $label) |
|
63 | + foreach ($option_list as $value => $label) |
|
64 | 64 | { |
65 | 65 | $option_attributes = ['value' => $value]; |
66 | - if($selected == $value) |
|
67 | - $option_attributes['selected'] = 'selected'; |
|
66 | + if ($selected == $value) |
|
67 | + $option_attributes['selected'] = 'selected'; |
|
68 | 68 | |
69 | 69 | $options .= new Element('option', $label, $option_attributes); |
70 | 70 | } |
71 | 71 | return self::element_with_errors('select', $options, $attributes, isset($errors[$field_name])); |
72 | 72 | } |
73 | 73 | |
74 | - public static function legend($label, $attributes=[]) |
|
74 | + public static function legend($label, $attributes = []) |
|
75 | 75 | { |
76 | 76 | return new Element('legend', $label, $attributes); |
77 | 77 | } |
78 | 78 | |
79 | - public static function label($field_for, $field_label, $attributes=[], $errors=[]) |
|
79 | + public static function label($field_for, $field_label, $attributes = [], $errors = []) |
|
80 | 80 | { |
81 | 81 | $attributes['for'] = $field_for; |
82 | 82 | return self::element_with_errors('label', $field_label, $attributes, isset($errors[$field_for])); |
83 | 83 | } |
84 | 84 | |
85 | - public static function submit($field_id, $field_label, $attributes=[]) |
|
85 | + public static function submit($field_id, $field_label, $attributes = []) |
|
86 | 86 | { |
87 | 87 | $attributes['id'] = $attributes['id'] ?? $field_id; |
88 | 88 | unset($attributes['name']); |
89 | 89 | $attributes['type'] = 'submit'; |
90 | - if(isset($attributes['tag']) && $attributes['tag'] === 'input') |
|
90 | + if (isset($attributes['tag']) && $attributes['tag'] === 'input') |
|
91 | 91 | return new Element('input', '', $attributes); |
92 | 92 | else |
93 | 93 | { |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - private static function element_with_errors($tag, $content, $attributes=[], $errors=false) |
|
100 | + private static function element_with_errors($tag, $content, $attributes = [], $errors = false) |
|
101 | 101 | { |
102 | 102 | |
103 | 103 | $attributes['id'] = $attributes['id'] ?? $attributes['name'] ?? ''; |
104 | 104 | |
105 | - if($errors === true) |
|
105 | + if ($errors === true) |
|
106 | 106 | { |
107 | 107 | $attributes['class'] = $attributes['class'] ?? ''; |
108 | 108 | $attributes['class'] .= ' error'; |
109 | 109 | } |
110 | 110 | |
111 | 111 | $label = ''; |
112 | - if(isset($attributes['label'])) |
|
112 | + if (isset($attributes['label'])) |
|
113 | 113 | { |
114 | 114 | $label = self::label($attributes['id'], $attributes['label'], [], $errors); |
115 | 115 | unset($attributes['label']); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | return in_array($this->tagName, self::VOID_ELEMENTS); |
17 | 17 | } |
18 | 18 | |
19 | - public function __construct($tagName, $innerContent=null, $attributeList = []) |
|
19 | + public function __construct($tagName, $innerContent = null, $attributeList = []) |
|
20 | 20 | { |
21 | 21 | $this->tagName = $tagName; |
22 | 22 | $this->attributeList = $attributeList; |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | { |
28 | 28 | $ret = ''; |
29 | 29 | |
30 | - foreach($this->attributeList as $k => $v) |
|
31 | - if(!is_null($v) && $v !== '' && !is_array($v)) |
|
32 | - $ret .= is_int($k) ? " $v" : sprintf(' %s="%s"', $k, $v); |
|
30 | + foreach ($this->attributeList as $k => $v) |
|
31 | + if (!is_null($v) && $v !== '' && !is_array($v)) |
|
32 | + $ret .= is_int($k) ? " $v" : sprintf(' %s="%s"', $k, $v); |
|
33 | 33 | |
34 | 34 | return $ret; |
35 | 35 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $flattributes = $this->format_attributes(); |
40 | 40 | |
41 | 41 | $ret = ''; |
42 | - if($this->is_void()) |
|
42 | + if ($this->is_void()) |
|
43 | 43 | $ret = sprintf('<%s%s/>', $this->tagName, $flattributes); |
44 | 44 | else |
45 | 45 | { |