@@ -4,16 +4,11 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Ffcms\Core\App; |
| 6 | 6 | use Ffcms\Core\Arch\Model; |
| 7 | -use Ffcms\Core\Exception\NativeException; |
|
| 8 | 7 | use Ffcms\Core\Exception\SyntaxException; |
| 9 | 8 | use Ffcms\Core\Helper\FileSystem\File; |
| 10 | -use Ffcms\Core\Helper\HTML\Form\Constructor; |
|
| 11 | 9 | use Ffcms\Core\Helper\HTML\Form\FieldSelector; |
| 12 | 10 | use Ffcms\Core\Helper\HTML\System\NativeGenerator; |
| 13 | 11 | use Ffcms\Core\Helper\Type\Any; |
| 14 | -use Ffcms\Core\Helper\Type\Arr; |
|
| 15 | -use Ffcms\Core\Helper\Type\Obj; |
|
| 16 | -use Ffcms\Core\Helper\Type\Str; |
|
| 17 | 12 | |
| 18 | 13 | /** |
| 19 | 14 | * Class Form. Simple HTML model generator for fast form building. |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $form = self::buildSingleTag('form', $this->formProperty, false); |
| 88 | 88 | if ($this->model->_tokenRequired) |
| 89 | - $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]); |
|
| 89 | + $form .= PHP_EOL.$this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]); |
|
| 90 | 90 | |
| 91 | 91 | return $form; |
| 92 | 92 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $response = null; |
| 107 | 107 | try { |
| 108 | 108 | $response = $this->field->{$type}($object, $property, $helper, $layerFile); |
| 109 | - } catch (\Exception $e){} |
|
| 109 | + } catch (\Exception $e) {} |
|
| 110 | 110 | return $response; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function submitButton($title, array $property = []) |
| 120 | 120 | { |
| 121 | 121 | $property['type'] = 'submit'; |
| 122 | - $property['name'] = $this->name . '[submit]'; |
|
| 122 | + $property['name'] = $this->name.'[submit]'; |
|
| 123 | 123 | $property['value'] = $title; |
| 124 | 124 | return self::buildSingleTag('input', $property); |
| 125 | 125 | } |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | // pre-validate form fields based on model rules and jquery.validation |
| 135 | 135 | if ($validate) { |
| 136 | - App::$Alias->addPlainCode('js', '$().ready(function() { $("#' . $this->name . '").validate(); });'); |
|
| 136 | + App::$Alias->addPlainCode('js', '$().ready(function() { $("#'.$this->name.'").validate(); });'); |
|
| 137 | 137 | App::$Alias->setCustomLibrary('js', '/vendor/bower/jquery-validation/dist/jquery.validate.min.js'); |
| 138 | 138 | if (App::$Request->getLanguage() !== 'en') { |
| 139 | - $localeFile = '/vendor/bower/jquery-validation/src/localization/messages_' . App::$Request->getLanguage() . '.js'; |
|
| 139 | + $localeFile = '/vendor/bower/jquery-validation/src/localization/messages_'.App::$Request->getLanguage().'.js'; |
|
| 140 | 140 | if (File::exist($localeFile)) { |
| 141 | 141 | App::$Alias->setCustomLibrary('js', $localeFile); |
| 142 | 142 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $formName = $this->model->getFormName(); |
| 148 | 148 | if (Any::isArray($badAttr) && count($badAttr) > 0) { |
| 149 | 149 | foreach ($badAttr as $attr) { |
| 150 | - $itemId = $formName . '-' . $attr; |
|
| 150 | + $itemId = $formName.'-'.$attr; |
|
| 151 | 151 | try { |
| 152 | 152 | $render = App::$View->render(static::$structLayer['jsnotify'], ['itemId' => $itemId]); |
| 153 | 153 | App::$Alias->addPlainCode('js', $render); |
@@ -50,8 +50,9 @@ discard block |
||
| 50 | 50 | public function __construct($model, array $property = null, array $layerFiles = null) |
| 51 | 51 | { |
| 52 | 52 | // prevent white-screen locks when model is not passed or passed wrong |
| 53 | - if (!$model instanceof Model) |
|
| 54 | - throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()'); |
|
| 53 | + if (!$model instanceof Model) { |
|
| 54 | + throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()'); |
|
| 55 | + } |
|
| 55 | 56 | |
| 56 | 57 | $this->model = $model; |
| 57 | 58 | $this->name = $model->getFormName(); |
@@ -59,8 +60,9 @@ discard block |
||
| 59 | 60 | // check if passed custom layer file |
| 60 | 61 | if (Any::isArray($layerFiles) && count($layerFiles) > 0) { |
| 61 | 62 | foreach (array_keys(static::$structLayer) as $type) { |
| 62 | - if (isset($layerFiles[$type]) && Any::isStr($layerFiles[$type])) |
|
| 63 | - static::$structLayer[$type] = $layerFiles[$type]; |
|
| 63 | + if (isset($layerFiles[$type]) && Any::isStr($layerFiles[$type])) { |
|
| 64 | + static::$structLayer[$type] = $layerFiles[$type]; |
|
| 65 | + } |
|
| 64 | 66 | } |
| 65 | 67 | } |
| 66 | 68 | // initialize field selector helper |
@@ -71,8 +73,9 @@ discard block |
||
| 71 | 73 | |
| 72 | 74 | $property['id'] = $this->name; // define form id |
| 73 | 75 | // if action is not defined - define it |
| 74 | - if (!$property['action']) |
|
| 75 | - $property['action'] = App::$Request->getFullUrl(); |
|
| 76 | + if (!$property['action']) { |
|
| 77 | + $property['action'] = App::$Request->getFullUrl(); |
|
| 78 | + } |
|
| 76 | 79 | |
| 77 | 80 | // set property global for this form |
| 78 | 81 | $this->formProperty = $property; |
@@ -85,8 +88,9 @@ discard block |
||
| 85 | 88 | public function start() |
| 86 | 89 | { |
| 87 | 90 | $form = self::buildSingleTag('form', $this->formProperty, false); |
| 88 | - if ($this->model->_tokenRequired) |
|
| 89 | - $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]); |
|
| 91 | + if ($this->model->_tokenRequired) { |
|
| 92 | + $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]); |
|
| 93 | + } |
|
| 90 | 94 | |
| 91 | 95 | return $form; |
| 92 | 96 | } |
@@ -152,8 +156,9 @@ discard block |
||
| 152 | 156 | $render = App::$View->render(static::$structLayer['jsnotify'], ['itemId' => $itemId]); |
| 153 | 157 | App::$Alias->addPlainCode('js', $render); |
| 154 | 158 | } catch (SyntaxException $e) { |
| 155 | - if (App::$Debug) |
|
| 156 | - App::$Debug->addException($e); |
|
| 159 | + if (App::$Debug) { |
|
| 160 | + App::$Debug->addException($e); |
|
| 161 | + } |
|
| 157 | 162 | } |
| 158 | 163 | } |
| 159 | 164 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | try { |
| 52 | 52 | $this->message = App::$View->render($tpl, $params, $dir); |
| 53 | - } catch (SyntaxException $e){} |
|
| 53 | + } catch (SyntaxException $e) {} |
|
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } catch (\Exception $e) { |
| 74 | 74 | if (App::$Debug) { |
| 75 | 75 | App::$Debug->addException($e); |
| 76 | - App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error'); |
|
| 76 | + App::$Debug->addMessage('Send mail failed! Info: '.$e->getMessage(), 'error'); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -57,12 +57,14 @@ |
||
| 57 | 57 | public function send(string $to, string $subject, ?string $message = null) |
| 58 | 58 | { |
| 59 | 59 | // try to get message from global if not passed direct |
| 60 | - if ($message === null) |
|
| 61 | - $message = $this->message; |
|
| 60 | + if ($message === null) { |
|
| 61 | + $message = $this->message; |
|
| 62 | + } |
|
| 62 | 63 | |
| 63 | 64 | try { |
| 64 | - if ($message === null) |
|
| 65 | - throw new \Exception('Message body is empty!'); |
|
| 65 | + if ($message === null) { |
|
| 66 | + throw new \Exception('Message body is empty!'); |
|
| 67 | + } |
|
| 66 | 68 | |
| 67 | 69 | // try to build message and send it |
| 68 | 70 | $message = (new \Swift_Message($subject)) |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | // check if model has attribute |
| 78 | 78 | if (!property_exists($this->model, $rootName)) { |
| 79 | 79 | if (App::$Debug) |
| 80 | - App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
| 80 | + App::$Debug->addMessage('Field "'.$name.'" ('.$field.') is not defined in model: ['.get_class($this->model).']', 'error'); |
|
| 81 | 81 | |
| 82 | 82 | return null; |
| 83 | 83 | } |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | // prepare default layer if not passed |
| 86 | 86 | $layer = $this->findFieldLayer($field, $layer); |
| 87 | 87 | // prepare html attributes, object value |
| 88 | - $attr = $this->model->getFormName() . '-' . $rootName; |
|
| 88 | + $attr = $this->model->getFormName().'-'.$rootName; |
|
| 89 | 89 | $label = $this->model->getLabel($name); |
| 90 | 90 | $value = $this->model->{$rootName}; |
| 91 | 91 | // check if dot-nested array used and update attr name |
| 92 | 92 | if ($rootName !== $name) { |
| 93 | 93 | $nesting = trim(strstr($name, '.'), '.'); |
| 94 | - $attr .= '-' . Str::replace('.', '-', $nesting); |
|
| 94 | + $attr .= '-'.Str::replace('.', '-', $nesting); |
|
| 95 | 95 | $value = Arr::getByPath($nesting, $value); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -52,32 +52,38 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function __call(string $field, ?array $arguments = null): ?string |
| 54 | 54 | { |
| 55 | - if ($arguments === null || count($arguments) < 1) |
|
| 56 | - return null; |
|
| 55 | + if ($arguments === null || count($arguments) < 1) { |
|
| 56 | + return null; |
|
| 57 | + } |
|
| 57 | 58 | |
| 58 | 59 | // get named arguments from passed array |
| 59 | 60 | $name = (string)$arguments[0]; |
| 60 | 61 | $rootName = $name; |
| 61 | 62 | // set root element name if array dot-nested notation found |
| 62 | - if (Str::contains('.', $name)) |
|
| 63 | - $rootName = strstr($rootName, '.', true); |
|
| 63 | + if (Str::contains('.', $name)) { |
|
| 64 | + $rootName = strstr($rootName, '.', true); |
|
| 65 | + } |
|
| 64 | 66 | // define properties, helper and layer |
| 65 | 67 | $properties = null; |
| 66 | 68 | $helper = null; |
| 67 | 69 | $layer = null; |
| 68 | - if (isset($arguments[1])) |
|
| 69 | - $properties = (array)$arguments[1]; |
|
| 70 | + if (isset($arguments[1])) { |
|
| 71 | + $properties = (array)$arguments[1]; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | - if (isset($arguments[2])) |
|
| 72 | - $helper = (string)$arguments[2]; |
|
| 74 | + if (isset($arguments[2])) { |
|
| 75 | + $helper = (string)$arguments[2]; |
|
| 76 | + } |
|
| 73 | 77 | |
| 74 | - if (isset($arguments[3])) |
|
| 75 | - $layer = (string)$arguments[3]; |
|
| 78 | + if (isset($arguments[3])) { |
|
| 79 | + $layer = (string)$arguments[3]; |
|
| 80 | + } |
|
| 76 | 81 | |
| 77 | 82 | // check if model has attribute |
| 78 | 83 | if (!property_exists($this->model, $rootName)) { |
| 79 | - if (App::$Debug) |
|
| 80 | - App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
| 84 | + if (App::$Debug) { |
|
| 85 | + App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
| 86 | + } |
|
| 81 | 87 | |
| 82 | 88 | return null; |
| 83 | 89 | } |
@@ -100,8 +106,9 @@ discard block |
||
| 100 | 106 | $elementDOM = $constructor->makeTag($name, $value, $properties); |
| 101 | 107 | |
| 102 | 108 | // if item is hidden - return tag without assign of global template |
| 103 | - if ($field === 'hidden') |
|
| 104 | - return $elementDOM; |
|
| 109 | + if ($field === 'hidden') { |
|
| 110 | + return $elementDOM; |
|
| 111 | + } |
|
| 105 | 112 | |
| 106 | 113 | // prepare output html |
| 107 | 114 | try { |
@@ -112,8 +119,9 @@ discard block |
||
| 112 | 119 | 'help' => self::nohtml($helper) |
| 113 | 120 | ]); |
| 114 | 121 | } catch (SyntaxException $e) { |
| 115 | - if (App::$Debug) |
|
| 116 | - App::$Debug->addException($e); |
|
| 122 | + if (App::$Debug) { |
|
| 123 | + App::$Debug->addException($e); |
|
| 124 | + } |
|
| 117 | 125 | return null; |
| 118 | 126 | } |
| 119 | 127 | } |
@@ -126,8 +134,9 @@ discard block |
||
| 126 | 134 | */ |
| 127 | 135 | private function findFieldLayer(?string $type = null, ?string $layer = null): ?string |
| 128 | 136 | { |
| 129 | - if ($layer !== null) |
|
| 130 | - return $layer; |
|
| 137 | + if ($layer !== null) { |
|
| 138 | + return $layer; |
|
| 139 | + } |
|
| 131 | 140 | |
| 132 | 141 | switch ($type) { |
| 133 | 142 | case 'checkbox': |
@@ -30,8 +30,9 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | public function make() |
| 32 | 32 | { |
| 33 | - if (isset($this->properties['value'])) |
|
| 34 | - unset($this->properties['value']); |
|
| 33 | + if (isset($this->properties['value'])) { |
|
| 34 | + unset($this->properties['value']); |
|
| 35 | + } |
|
| 35 | 36 | |
| 36 | 37 | $this->properties['type'] = 'password'; |
| 37 | 38 | |