@@ -9,7 +9,10 @@ |
||
| 9 | 9 | |
| 10 | 10 | namespace Form { |
| 11 | 11 | |
| 12 | - use Dataset, Form, Request, Tag; |
|
| 12 | + use Dataset; |
|
| 13 | + use Form; |
|
| 14 | + use Request; |
|
| 15 | + use Tag; |
|
| 13 | 16 | |
| 14 | 17 | abstract class Field { |
| 15 | 18 | |
@@ -57,11 +57,17 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | # Set appearance |
| 59 | 59 | |
| 60 | - if ($this->disabled) $data['disabled'] = 'disabled'; |
|
| 60 | + if ($this->disabled) { |
|
| 61 | + $data['disabled'] = 'disabled'; |
|
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if ($this->required) $data['data-required'] = 'required'; |
|
| 64 | + if ($this->required) { |
|
| 65 | + $data['data-required'] = 'required'; |
|
| 66 | + } |
|
| 63 | 67 | |
| 64 | - if ($this->error) $data['data-error'] = 'error'; |
|
| 68 | + if ($this->error) { |
|
| 69 | + $data['data-error'] = 'error'; |
|
| 70 | + } |
|
| 65 | 71 | |
| 66 | 72 | # ------------------------ |
| 67 | 73 | |
@@ -76,7 +82,9 @@ discard block |
||
| 76 | 82 | |
| 77 | 83 | public function post() : bool { |
| 78 | 84 | |
| 79 | - if ($this->posted || $this->disabled || ('' === $this->key)) return false; |
|
| 85 | + if ($this->posted || $this->disabled || ('' === $this->key)) { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 80 | 88 | |
| 81 | 89 | $this->error = (!$this->setValue(Request::post($this->name)) && $this->required); |
| 82 | 90 | |
@@ -9,7 +9,10 @@ |
||
| 9 | 9 | |
| 10 | 10 | namespace Form\Field { |
| 11 | 11 | |
| 12 | - use Form, Str, Tag, Template; |
|
| 12 | + use Form; |
|
| 13 | + use Str; |
|
| 14 | + use Tag; |
|
| 15 | + use Template; |
|
| 13 | 16 | |
| 14 | 17 | class Text extends Form\Field { |
| 15 | 18 | |
@@ -82,9 +82,13 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $tag = $this->getTag('textarea', [], $this->value); |
| 84 | 84 | |
| 85 | - if ($this->rows > 0) $tag->setAttribute('rows', $this->rows); |
|
| 85 | + if ($this->rows > 0) { |
|
| 86 | + $tag->setAttribute('rows', $this->rows); |
|
| 87 | + } |
|
| 86 | 88 | |
| 87 | - if ($this->cols > 0) $tag->setAttribute('cols', $this->cols); |
|
| 89 | + if ($this->cols > 0) { |
|
| 90 | + $tag->setAttribute('cols', $this->cols); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | # ------------------------ |
| 90 | 94 | |
@@ -97,9 +101,11 @@ discard block |
||
| 97 | 101 | |
| 98 | 102 | private function processSpaces() { |
| 99 | 103 | |
| 100 | - if ($this->spaces === 'strip') $this->value = Str::stripSpaces($this->value); |
|
| 101 | - |
|
| 102 | - else if ($this->spaces === 'single') $this->value = Str::singleSpaces($this->value); |
|
| 104 | + if ($this->spaces === 'strip') { |
|
| 105 | + $this->value = Str::stripSpaces($this->value); |
|
| 106 | + } else if ($this->spaces === 'single') { |
|
| 107 | + $this->value = Str::singleSpaces($this->value); |
|
| 108 | + } |
|
| 103 | 109 | } |
| 104 | 110 | |
| 105 | 111 | /** |
@@ -108,9 +114,11 @@ discard block |
||
| 108 | 114 | |
| 109 | 115 | private function processConvert() { |
| 110 | 116 | |
| 111 | - if ($this->convert === 'url') $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 112 | - |
|
| 113 | - else if ($this->convert === 'var') $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 117 | + if ($this->convert === 'url') { |
|
| 118 | + $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 119 | + } else if ($this->convert === 'var') { |
|
| 120 | + $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 121 | + } |
|
| 114 | 122 | } |
| 115 | 123 | |
| 116 | 124 | /** |
@@ -119,9 +127,11 @@ discard block |
||
| 119 | 127 | |
| 120 | 128 | private function processTransform() { |
| 121 | 129 | |
| 122 | - if ($this->transform === 'lower') $this->value = Str::toLower($this->value); |
|
| 123 | - |
|
| 124 | - else if ($this->transform === 'upper') $this->value = Str::toUpper($this->value); |
|
| 130 | + if ($this->transform === 'lower') { |
|
| 131 | + $this->value = Str::toLower($this->value); |
|
| 132 | + } else if ($this->transform === 'upper') { |
|
| 133 | + $this->value = Str::toUpper($this->value); |
|
| 134 | + } |
|
| 125 | 135 | } |
| 126 | 136 | |
| 127 | 137 | /** |
@@ -183,27 +193,39 @@ discard block |
||
| 183 | 193 | |
| 184 | 194 | # Process hidden field |
| 185 | 195 | |
| 186 | - if ($this->type === FORM_FIELD_HIDDEN) return $this->getHidden()->getBlock(); |
|
| 196 | + if ($this->type === FORM_FIELD_HIDDEN) { |
|
| 197 | + return $this->getHidden()->getBlock(); |
|
| 198 | + } |
|
| 187 | 199 | |
| 188 | 200 | # Process visible field |
| 189 | 201 | |
| 190 | - else if ($this->type === FORM_FIELD_PASSWORD) $tag = $this->getPassword(); |
|
| 191 | - |
|
| 192 | - else if ($this->type === FORM_FIELD_CAPTCHA) $tag = $this->getCaptcha(); |
|
| 193 | - |
|
| 194 | - else if ($this->type === FORM_FIELD_TEXTAREA) $tag = $this->getTextarea(); |
|
| 195 | - |
|
| 196 | - else $tag = $this->getText(); |
|
| 202 | + else if ($this->type === FORM_FIELD_PASSWORD) { |
|
| 203 | + $tag = $this->getPassword(); |
|
| 204 | + } else if ($this->type === FORM_FIELD_CAPTCHA) { |
|
| 205 | + $tag = $this->getCaptcha(); |
|
| 206 | + } else if ($this->type === FORM_FIELD_TEXTAREA) { |
|
| 207 | + $tag = $this->getTextarea(); |
|
| 208 | + } else { |
|
| 209 | + $tag = $this->getText(); |
|
| 210 | + } |
|
| 197 | 211 | |
| 198 | 212 | # Set appearance |
| 199 | 213 | |
| 200 | - if ($this->maxlength > 0) $tag->setAttribute('maxlength', $this->maxlength); |
|
| 214 | + if ($this->maxlength > 0) { |
|
| 215 | + $tag->setAttribute('maxlength', $this->maxlength); |
|
| 216 | + } |
|
| 201 | 217 | |
| 202 | - if ('' !== $this->placeholder) $tag->setAttribute('placeholder', $this->placeholder); |
|
| 218 | + if ('' !== $this->placeholder) { |
|
| 219 | + $tag->setAttribute('placeholder', $this->placeholder); |
|
| 220 | + } |
|
| 203 | 221 | |
| 204 | - if ($this->readonly) $tag->setAttribute('readonly', 'readonly'); |
|
| 222 | + if ($this->readonly) { |
|
| 223 | + $tag->setAttribute('readonly', 'readonly'); |
|
| 224 | + } |
|
| 205 | 225 | |
| 206 | - if ($this->autofocus) $tag->setAttribute('autofocus', 'autofocus'); |
|
| 226 | + if ($this->autofocus) { |
|
| 227 | + $tag->setAttribute('autofocus', 'autofocus'); |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | # ------------------------ |
| 209 | 231 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * Set a name |
| 29 | 29 | * |
| 30 | - * @return the current tag object |
|
| 30 | + * @return Tag current tag object |
|
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | 33 | public function setName(string $name) : Tag { |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * Set an attribute |
| 42 | 42 | * |
| 43 | - * @return the current tag object |
|
| 43 | + * @return Tag current tag object |
|
| 44 | 44 | */ |
| 45 | 45 | |
| 46 | 46 | public function setAttribute(string $name, string $value) : Tag { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * Set multiple attributes |
| 55 | 55 | * |
| 56 | - * @return the current tag object |
|
| 56 | + * @return Tag current tag object |
|
| 57 | 57 | */ |
| 58 | 58 | |
| 59 | 59 | public function setAttributes(array $attributes) : Tag { |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | /** |
| 67 | 67 | * Set contents. The method expects a block, a string, or null |
| 68 | 68 | * |
| 69 | - * @return the current tag object |
|
| 69 | + * @return Tag current tag object |
|
| 70 | 70 | */ |
| 71 | 71 | |
| 72 | 72 | public function setContents($contents) : Tag { |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * Get the tag as a block |
| 110 | 110 | * |
| 111 | - * @return the self-closing tag if no valid contents have been set, otherwise the regular tag |
|
| 111 | + * @return Template\Block self-closing tag if no valid contents have been set, otherwise the regular tag |
|
| 112 | 112 | */ |
| 113 | 113 | |
| 114 | 114 | public function getBlock() : Template\Block { |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | |
| 118 | 118 | $block = clone (self::$block ?? (self::$block = Template::createBlock( |
| 119 | 119 | |
| 120 | - '<$name${ for:attributes } $name$="$value$"{ / for:attributes }>' . |
|
| 120 | + '<$name${ for:attributes } $name$="$value$"{ / for:attributes }>'. |
|
| 121 | 121 | |
| 122 | 122 | '{ block:contents / }$contents${ ! block:closing }</$name$>{ / block:closing }' |
| 123 | 123 | ))); |
@@ -58,7 +58,9 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function setAttributes(array $attributes) : Tag { |
| 60 | 60 | |
| 61 | - foreach ($attributes as $name => $value) if (is_scalar($value)) $this->setAttribute($name, $value); |
|
| 61 | + foreach ($attributes as $name => $value) { |
|
| 62 | + if (is_scalar($value)) $this->setAttribute($name, $value); |
|
| 63 | + } |
|
| 62 | 64 | |
| 63 | 65 | return $this; |
| 64 | 66 | } |
@@ -71,7 +73,9 @@ discard block |
||
| 71 | 73 | |
| 72 | 74 | public function setContents($contents) : Tag { |
| 73 | 75 | |
| 74 | - if (Template::isBlock($contents) || is_scalar($contents) || is_null($contents)) $this->contents = $contents; |
|
| 76 | + if (Template::isBlock($contents) || is_scalar($contents) || is_null($contents)) { |
|
| 77 | + $this->contents = $contents; |
|
| 78 | + } |
|
| 75 | 79 | |
| 76 | 80 | return $this; |
| 77 | 81 | } |
@@ -77,9 +77,13 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | # Set appearance |
| 79 | 79 | |
| 80 | - if ($this->search) $tag->setAttribute('data-search', 'search'); |
|
| 80 | + if ($this->search) { |
|
| 81 | + $tag->setAttribute('data-search', 'search'); |
|
| 82 | + } |
|
| 81 | 83 | |
| 82 | - if ($this->auto) $tag->setAttribute('data-auto', 'auto'); |
|
| 84 | + if ($this->auto) { |
|
| 85 | + $tag->setAttribute('data-auto', 'auto'); |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | 88 | # Set options |
| 85 | 89 | |
@@ -87,7 +91,9 @@ discard block |
||
| 87 | 91 | |
| 88 | 92 | $option = (new Tag('option', [], $text))->setAttribute('value', $value); |
| 89 | 93 | |
| 90 | - if ($this->value === $value) $option->setAttribute('selected', ''); |
|
| 94 | + if ($this->value === $value) { |
|
| 95 | + $option->setAttribute('selected', ''); |
|
| 96 | + } |
|
| 91 | 97 | |
| 92 | 98 | $options->addItem($option->getBlock()); |
| 93 | 99 | } |