@@ -10,134 +10,134 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @var array |
| 12 | 12 | */ |
| 13 | - protected $engines = [ |
|
| 14 | - '.mustache.php' => 'Helmut\Forms\Engines\Mustache', |
|
| 15 | - '.twig.php' => 'Helmut\Forms\Engines\Twig', |
|
| 16 | - '.blade.php' => 'Helmut\Forms\Engines\Blade', |
|
| 17 | - ]; |
|
| 13 | + protected $engines = [ |
|
| 14 | + '.mustache.php' => 'Helmut\Forms\Engines\Mustache', |
|
| 15 | + '.twig.php' => 'Helmut\Forms\Engines\Twig', |
|
| 16 | + '.blade.php' => 'Helmut\Forms\Engines\Blade', |
|
| 17 | + ]; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Cache of running engines. |
| 21 | 21 | * |
| 22 | 22 | * @var array |
| 23 | 23 | */ |
| 24 | - protected $running = []; |
|
| 24 | + protected $running = []; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Cache of template files. |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - protected $templates = []; |
|
| 31 | + protected $templates = []; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Add a new engine implementation. |
| 35 | 35 | * |
| 36 | - * @param string $extension |
|
| 37 | - * @param string $class |
|
| 36 | + * @param string $extension |
|
| 37 | + * @param string $class |
|
| 38 | 38 | * @return void |
| 39 | 39 | */ |
| 40 | - public function addEngine($extension, $class) |
|
| 41 | - { |
|
| 42 | - array_unshift($this->engines, [$extension => $class]); |
|
| 43 | - } |
|
| 40 | + public function addEngine($extension, $class) |
|
| 41 | + { |
|
| 42 | + array_unshift($this->engines, [$extension => $class]); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Get an engine implementation. |
| 47 | 47 | * |
| 48 | - * @param string $key |
|
| 48 | + * @param string $key |
|
| 49 | 49 | * @return \Helmut\Forms\Engine |
| 50 | 50 | */ |
| 51 | - public function start($key) |
|
| 52 | - { |
|
| 53 | - if ( ! isset($this->running[$key])) { |
|
| 54 | - $this->running[$key] = new $this->engines[$key]; |
|
| 55 | - } |
|
| 51 | + public function start($key) |
|
| 52 | + { |
|
| 53 | + if ( ! isset($this->running[$key])) { |
|
| 54 | + $this->running[$key] = new $this->engines[$key]; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $this->running[$key]; |
|
| 58 | - } |
|
| 57 | + return $this->running[$key]; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Get engine file extensions. |
| 62 | 62 | * |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function extensions() |
|
| 66 | - { |
|
| 67 | - return array_keys($this->engines); |
|
| 68 | - } |
|
| 65 | + public function extensions() |
|
| 66 | + { |
|
| 67 | + return array_keys($this->engines); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Create a template cache key. |
| 72 | 72 | * |
| 73 | - * @param string $template |
|
| 74 | - * @param array $paths |
|
| 73 | + * @param string $template |
|
| 74 | + * @param array $paths |
|
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public function key($template, $paths) |
|
| 78 | - { |
|
| 79 | - return $template.'-'.md5(serialize($paths)); |
|
| 80 | - } |
|
| 77 | + public function key($template, $paths) |
|
| 78 | + { |
|
| 79 | + return $template.'-'.md5(serialize($paths)); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Render a template. |
| 84 | 84 | * |
| 85 | - * @param string $template |
|
| 86 | - * @param array $properties |
|
| 87 | - * @param array $paths |
|
| 85 | + * @param string $template |
|
| 86 | + * @param array $properties |
|
| 87 | + * @param array $paths |
|
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function render($template, $properties, $paths) |
|
| 91 | - { |
|
| 92 | - if ($this->has($template, $paths)) { |
|
| 90 | + public function render($template, $properties, $paths) |
|
| 91 | + { |
|
| 92 | + if ($this->has($template, $paths)) { |
|
| 93 | 93 | |
| 94 | - $template = $this->findTemplate($template, $paths); |
|
| 94 | + $template = $this->findTemplate($template, $paths); |
|
| 95 | 95 | |
| 96 | - return $this->start($template['engine'])->render($template['path'], $properties); |
|
| 97 | - } |
|
| 98 | - } |
|
| 96 | + return $this->start($template['engine'])->render($template['path'], $properties); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Check if a template exists. |
| 102 | 102 | * |
| 103 | - * @param string $template |
|
| 104 | - * @param array $paths |
|
| 103 | + * @param string $template |
|
| 104 | + * @param array $paths |
|
| 105 | 105 | * @return boolean |
| 106 | 106 | */ |
| 107 | - public function has($template, $paths) |
|
| 108 | - { |
|
| 109 | - return ! is_null($this->findTemplate($template, $paths)); |
|
| 110 | - } |
|
| 107 | + public function has($template, $paths) |
|
| 108 | + { |
|
| 109 | + return ! is_null($this->findTemplate($template, $paths)); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Find template file with engine. |
| 114 | 114 | * |
| 115 | - * @param string $template |
|
| 116 | - * @param array $paths |
|
| 115 | + * @param string $template |
|
| 116 | + * @param array $paths |
|
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | - public function findTemplate($template, $paths) |
|
| 120 | - { |
|
| 121 | - $key = $this->key($template, $paths); |
|
| 122 | - |
|
| 123 | - if ( ! isset($this->templates[$key])) { |
|
| 124 | - |
|
| 125 | - $this->templates[$key] = null; |
|
| 126 | - |
|
| 127 | - $extensions = $this->extensions(); |
|
| 128 | - foreach ($paths as $path) { |
|
| 129 | - foreach ($extensions as $extension) { |
|
| 130 | - if (file_exists($path.$template.$extension)) { |
|
| 131 | - return $this->templates[$key] = [ |
|
| 132 | - 'engine' => $extension, |
|
| 133 | - 'path' => $path.$template.$extension, |
|
| 134 | - ]; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $this->templates[$key]; |
|
| 141 | - } |
|
| 119 | + public function findTemplate($template, $paths) |
|
| 120 | + { |
|
| 121 | + $key = $this->key($template, $paths); |
|
| 122 | + |
|
| 123 | + if ( ! isset($this->templates[$key])) { |
|
| 124 | + |
|
| 125 | + $this->templates[$key] = null; |
|
| 126 | + |
|
| 127 | + $extensions = $this->extensions(); |
|
| 128 | + foreach ($paths as $path) { |
|
| 129 | + foreach ($extensions as $extension) { |
|
| 130 | + if (file_exists($path.$template.$extension)) { |
|
| 131 | + return $this->templates[$key] = [ |
|
| 132 | + 'engine' => $extension, |
|
| 133 | + 'path' => $path.$template.$extension, |
|
| 134 | + ]; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $this->templates[$key]; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | } |
@@ -8,41 +8,41 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Twig implements Engine { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * The twig compiler engine. |
|
| 13 | - * |
|
| 14 | - * @var \Twig_Environment |
|
| 15 | - */ |
|
| 16 | - protected $compiler; |
|
| 17 | - |
|
| 18 | - /** |
|
| 11 | + /** |
|
| 12 | + * The twig compiler engine. |
|
| 13 | + * |
|
| 14 | + * @var \Twig_Environment |
|
| 15 | + */ |
|
| 16 | + protected $compiler; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | 19 | * Fetch the compiler. |
| 20 | 20 | * |
| 21 | 21 | * @return \Twig_Environment |
| 22 | 22 | */ |
| 23 | - public function compiler() |
|
| 24 | - { |
|
| 25 | - if ( ! $this->compiler) { |
|
| 26 | - $this->compiler = new Twig_Environment(new Twig_Loader_Array([])); |
|
| 27 | - } |
|
| 23 | + public function compiler() |
|
| 24 | + { |
|
| 25 | + if ( ! $this->compiler) { |
|
| 26 | + $this->compiler = new Twig_Environment(new Twig_Loader_Array([])); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - return $this->compiler; |
|
| 30 | - } |
|
| 29 | + return $this->compiler; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | + /** |
|
| 33 | 33 | * Render the template content. |
| 34 | 34 | * |
| 35 | - * @param string $path |
|
| 36 | - * @param array $properties |
|
| 35 | + * @param string $path |
|
| 36 | + * @param array $properties |
|
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - public function render($path, $properties = []) |
|
| 40 | - { |
|
| 41 | - $content = file_get_contents($path); |
|
| 39 | + public function render($path, $properties = []) |
|
| 40 | + { |
|
| 41 | + $content = file_get_contents($path); |
|
| 42 | 42 | |
| 43 | 43 | $template = $this->compiler()->createTemplate($content); |
| 44 | 44 | |
| 45 | - return $template->render($properties); |
|
| 46 | - } |
|
| 45 | + return $template->render($properties); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
@@ -6,19 +6,19 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Basic implements Request { |
| 8 | 8 | |
| 9 | - public function all() |
|
| 10 | - { |
|
| 11 | - return isset($_POST) ? $_POST : []; |
|
| 12 | - } |
|
| 9 | + public function all() |
|
| 10 | + { |
|
| 11 | + return isset($_POST) ? $_POST : []; |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function get($key) |
|
| 15 | - { |
|
| 16 | - return isset($_POST[$key]) ? $_POST[$key] : null; |
|
| 17 | - } |
|
| 14 | + public function get($key) |
|
| 15 | + { |
|
| 16 | + return isset($_POST[$key]) ? $_POST[$key] : null; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function csrf() |
|
| 20 | - { |
|
| 21 | - return []; |
|
| 22 | - } |
|
| 19 | + public function csrf() |
|
| 20 | + { |
|
| 21 | + return []; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'plugins' => [ |
|
| 5 | - 'feedback', |
|
| 6 | - ], |
|
| 4 | + 'plugins' => [ |
|
| 5 | + 'feedback', |
|
| 6 | + ], |
|
| 7 | 7 | ]; |
| 8 | 8 | \ No newline at end of file |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | |
| 54 | 54 | $method = new ReflectionMethod($class, $method); |
| 55 | 55 | |
| 56 | - foreach($method->getParameters() as $param) { |
|
| 56 | + foreach ($method->getParameters() as $param) { |
|
| 57 | 57 | $params[] = $param->getName(); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -253,7 +253,9 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function fields($names = null) |
| 255 | 255 | { |
| 256 | - if (is_null($names)) return $this->fields; |
|
| 256 | + if (is_null($names)) { |
|
| 257 | + return $this->fields; |
|
| 258 | + } |
|
| 257 | 259 | |
| 258 | 260 | return array_filter($this->fields, function($field) use ($names) { |
| 259 | 261 | return array_key_exists($field->name, $names); |
@@ -473,7 +475,9 @@ discard block |
||
| 473 | 475 | $class = '\\Fields\\'.ucwords($class).'\\'.ucwords($class); |
| 474 | 476 | |
| 475 | 477 | foreach ($this->namespaces as $namespace) { |
| 476 | - if (class_exists($namespace.$class)) return $namespace.$class; |
|
| 478 | + if (class_exists($namespace.$class)) { |
|
| 479 | + return $namespace.$class; |
|
| 480 | + } |
|
| 477 | 481 | } |
| 478 | 482 | } |
| 479 | 483 | |
@@ -486,9 +490,13 @@ discard block |
||
| 486 | 490 | */ |
| 487 | 491 | public function errors($name = null) |
| 488 | 492 | { |
| 489 | - if ($this->submitted()) $this->validate(); |
|
| 493 | + if ($this->submitted()) { |
|
| 494 | + $this->validate(); |
|
| 495 | + } |
|
| 490 | 496 | |
| 491 | - if ( ! is_null($name)) return $this->field($name)->errors(); |
|
| 497 | + if ( ! is_null($name)) { |
|
| 498 | + return $this->field($name)->errors(); |
|
| 499 | + } |
|
| 492 | 500 | |
| 493 | 501 | $errors = []; |
| 494 | 502 | |
@@ -680,8 +688,12 @@ discard block |
||
| 680 | 688 | $message = $this->translate($error, $field); |
| 681 | 689 | |
| 682 | 690 | foreach($parameters as $key => $value) { |
| 683 | - if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value; |
|
| 684 | - if (is_array($value)) $value = implode(', ', $value); |
|
| 691 | + if (is_object($value) && method_exists($value, '__toString')) { |
|
| 692 | + $value = (string) $value; |
|
| 693 | + } |
|
| 694 | + if (is_array($value)) { |
|
| 695 | + $value = implode(', ', $value); |
|
| 696 | + } |
|
| 685 | 697 | $message = str_replace('['.$key.']', $value, $message); |
| 686 | 698 | } |
| 687 | 699 | $properties['errors'][] = ['error' => $message]; |
@@ -701,7 +713,9 @@ discard block |
||
| 701 | 713 | */ |
| 702 | 714 | public function renderField($field, $properties = null) |
| 703 | 715 | { |
| 704 | - if (is_null($properties)) $properties = $this->fieldProperties($field); |
|
| 716 | + if (is_null($properties)) { |
|
| 717 | + $properties = $this->fieldProperties($field); |
|
| 718 | + } |
|
| 705 | 719 | |
| 706 | 720 | return $this->renderTemplate($field->type, $properties, $field); |
| 707 | 721 | } |
@@ -715,7 +729,9 @@ discard block |
||
| 715 | 729 | */ |
| 716 | 730 | public function renderFieldErrors($field, $properties = null) |
| 717 | 731 | { |
| 718 | - if (is_null($properties)) $properties = $this->fieldProperties($field); |
|
| 732 | + if (is_null($properties)) { |
|
| 733 | + $properties = $this->fieldProperties($field); |
|
| 734 | + } |
|
| 719 | 735 | |
| 720 | 736 | return $this->renderTemplate('errors', $properties, $field); |
| 721 | 737 | } |
@@ -732,9 +748,13 @@ discard block |
||
| 732 | 748 | |
| 733 | 749 | $this->setValues(); |
| 734 | 750 | |
| 735 | - if ($this->submitted()) $this->validate(); |
|
| 751 | + if ($this->submitted()) { |
|
| 752 | + $this->validate(); |
|
| 753 | + } |
|
| 736 | 754 | |
| 737 | - if ( ! is_null($template)) $this->setTemplate($template); |
|
| 755 | + if ( ! is_null($template)) { |
|
| 756 | + $this->setTemplate($template); |
|
| 757 | + } |
|
| 738 | 758 | |
| 739 | 759 | $properties = []; |
| 740 | 760 | $properties['id'] = $this->id; |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | public function completed($name = null) |
| 353 | 353 | { |
| 354 | - if($this->submitted($name) && $this->valid()) { |
|
| 354 | + if ($this->submitted($name) && $this->valid()) { |
|
| 355 | 355 | $this->broadcast('completed'); |
| 356 | 356 | return true; |
| 357 | 357 | } |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | $errors = []; |
| 494 | 494 | |
| 495 | 495 | foreach ($this->fields as $field) { |
| 496 | - foreach($field->errors() as $error) { |
|
| 496 | + foreach ($field->errors() as $error) { |
|
| 497 | 497 | $errors[] = $error; |
| 498 | 498 | } |
| 499 | 499 | } |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | { |
| 616 | 616 | $config = $this->templateConfig($template); |
| 617 | 617 | |
| 618 | - if ( isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 619 | - foreach($config['plugins'] as $key => $plugin) { |
|
| 618 | + if (isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 619 | + foreach ($config['plugins'] as $key => $plugin) { |
|
| 620 | 620 | if (is_array($plugin)) { |
| 621 | 621 | $this->addPlugin($key, $plugin); |
| 622 | 622 | } else { |
@@ -636,8 +636,8 @@ discard block |
||
| 636 | 636 | { |
| 637 | 637 | $config = $this->templateConfig($template); |
| 638 | 638 | |
| 639 | - if ( isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 640 | - foreach($config['plugins'] as $plugin) { |
|
| 639 | + if (isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 640 | + foreach ($config['plugins'] as $plugin) { |
|
| 641 | 641 | $this->removePlugin($plugin); |
| 642 | 642 | } |
| 643 | 643 | } |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | foreach ($field->errors() as $error => $parameters) { |
| 675 | 675 | |
| 676 | 676 | if ($error == 'userDefined') { |
| 677 | - foreach($parameters as $message) { |
|
| 677 | + foreach ($parameters as $message) { |
|
| 678 | 678 | $properties['errors'][] = ['error' => $message]; |
| 679 | 679 | } |
| 680 | 680 | } else { |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | |
| 684 | 684 | $message = $this->translate($error, $field); |
| 685 | 685 | |
| 686 | - foreach($parameters as $key => $value) { |
|
| 686 | + foreach ($parameters as $key => $value) { |
|
| 687 | 687 | if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value; |
| 688 | 688 | if (is_array($value)) $value = implode(', ', $value); |
| 689 | 689 | $message = str_replace('['.$key.']', $value, $message); |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | */ |
| 950 | 950 | private function broadcast($event, $params = []) |
| 951 | 951 | { |
| 952 | - foreach($this->plugins as $plugin) { |
|
| 952 | + foreach ($this->plugins as $plugin) { |
|
| 953 | 953 | $plugin->event($this, $event, $params); |
| 954 | 954 | } |
| 955 | 955 | } |
@@ -1090,7 +1090,7 @@ discard block |
||
| 1090 | 1090 | { |
| 1091 | 1091 | if ( ! method_exists($this, $method)) |
| 1092 | 1092 | { |
| 1093 | - if ( $this->typeExists($method)) { |
|
| 1093 | + if ($this->typeExists($method)) { |
|
| 1094 | 1094 | return $this->addField($method, array_shift($parameters)); |
| 1095 | 1095 | } |
| 1096 | 1096 | } |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | |
| 29 | 29 | public static function alphaNum($var) |
| 30 | 30 | { |
| 31 | - if (! is_string($var) && ! is_numeric($var)) return false; |
|
| 31 | + if ( ! is_string($var) && ! is_numeric($var)) return false; |
|
| 32 | 32 | return preg_match('/^[\pL\pM\pN]+$/u', $var); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public static function alphaDash($var) |
| 36 | 36 | { |
| 37 | - if (! is_string($var) && ! is_numeric($var)) return false; |
|
| 37 | + if ( ! is_string($var) && ! is_numeric($var)) return false; |
|
| 38 | 38 | return preg_match('/^[\pL\pM\pN_-]+$/u', $var); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -6,8 +6,11 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | public static function required($var) |
| 8 | 8 | { |
| 9 | - if (is_null($var)) return false; |
|
| 10 | - else if (is_string($var) && trim($var) === '') return false; |
|
| 9 | + if (is_null($var)) { |
|
| 10 | + return false; |
|
| 11 | + } else if (is_string($var) && trim($var) === '') { |
|
| 12 | + return false; |
|
| 13 | + } |
|
| 11 | 14 | return true; |
| 12 | 15 | } |
| 13 | 16 | |
@@ -28,13 +31,17 @@ discard block |
||
| 28 | 31 | |
| 29 | 32 | public static function alphaNum($var) |
| 30 | 33 | { |
| 31 | - if (! is_string($var) && ! is_numeric($var)) return false; |
|
| 34 | + if (! is_string($var) && ! is_numeric($var)) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 32 | 37 | return preg_match('/^[\pL\pM\pN]+$/u', $var); |
| 33 | 38 | } |
| 34 | 39 | |
| 35 | 40 | public static function alphaDash($var) |
| 36 | 41 | { |
| 37 | - if (! is_string($var) && ! is_numeric($var)) return false; |
|
| 42 | + if (! is_string($var) && ! is_numeric($var)) { |
|
| 43 | + return false; |
|
| 44 | + } |
|
| 38 | 45 | return preg_match('/^[\pL\pM\pN_-]+$/u', $var); |
| 39 | 46 | } |
| 40 | 47 | |
@@ -84,14 +84,18 @@ discard block |
||
| 84 | 84 | public function setValueFromDefault() |
| 85 | 85 | { |
| 86 | 86 | foreach (array_keys($this->options) as $key) { |
| 87 | - if (isset($this->default[$key])) $this->values[$key] = $this->default[$key] ? true : false; |
|
| 87 | + if (isset($this->default[$key])) { |
|
| 88 | + $this->values[$key] = $this->default[$key] ? true : false; |
|
| 89 | + } |
|
| 88 | 90 | } |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | public function setValueFromModel($model) |
| 92 | 94 | { |
| 93 | 95 | foreach (array_keys($this->options) as $key) { |
| 94 | - if (property_exists($model, $this->name.'_'.$key)) $this->values[$key] = $model->{$this->name.'_'.$key} ? true : false; |
|
| 96 | + if (property_exists($model, $this->name.'_'.$key)) { |
|
| 97 | + $this->values[$key] = $model->{$this->name.'_'.$key} ? true : false; |
|
| 98 | + } |
|
| 95 | 99 | } |
| 96 | 100 | |
| 97 | 101 | } |
@@ -106,7 +110,9 @@ discard block |
||
| 106 | 110 | public function fillModelWithValue($model) |
| 107 | 111 | { |
| 108 | 112 | foreach (array_keys($this->options) as $key) { |
| 109 | - if (property_exists($model, $this->name.'_'.$key)) $model->{$this->name.'_'.$key} = $this->values[$key] ? 1 : 0; |
|
| 113 | + if (property_exists($model, $this->name.'_'.$key)) { |
|
| 114 | + $model->{$this->name.'_'.$key} = $this->values[$key] ? 1 : 0; |
|
| 115 | + } |
|
| 110 | 116 | } |
| 111 | 117 | } |
| 112 | 118 | |
@@ -115,7 +121,9 @@ discard block |
||
| 115 | 121 | $checked = false; |
| 116 | 122 | |
| 117 | 123 | foreach (array_keys($this->options) as $key) { |
| 118 | - if ($this->values[$key]) $checked = true; |
|
| 124 | + if ($this->values[$key]) { |
|
| 125 | + $checked = true; |
|
| 126 | + } |
|
| 119 | 127 | } |
| 120 | 128 | |
| 121 | 129 | return $checked; |
@@ -38,15 +38,23 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function setValueFromDefault() |
| 40 | 40 | { |
| 41 | - if (isset($this->default['first'])) $this->value_first = $this->default['first']; |
|
| 42 | - if (isset($this->default['surname'])) $this->value_surname = $this->default['surname']; |
|
| 41 | + if (isset($this->default['first'])) { |
|
| 42 | + $this->value_first = $this->default['first']; |
|
| 43 | + } |
|
| 44 | + if (isset($this->default['surname'])) { |
|
| 45 | + $this->value_surname = $this->default['surname']; |
|
| 46 | + } |
|
| 43 | 47 | $this->value = trim($this->value_first.' '.$this->value_surname); |
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | public function setValueFromModel($model) |
| 47 | 51 | { |
| 48 | - if (property_exists($model, $this->name.'_first')) $this->value_first = $model->{$this->name.'_first'}; |
|
| 49 | - if (property_exists($model, $this->name.'_surname')) $this->value_surname = $model->{$this->name.'_surname'}; |
|
| 52 | + if (property_exists($model, $this->name.'_first')) { |
|
| 53 | + $this->value_first = $model->{$this->name.'_first'}; |
|
| 54 | + } |
|
| 55 | + if (property_exists($model, $this->name.'_surname')) { |
|
| 56 | + $this->value_surname = $model->{$this->name.'_surname'}; |
|
| 57 | + } |
|
| 50 | 58 | $this->value = trim($this->value_first.' '.$this->value_surname); |
| 51 | 59 | } |
| 52 | 60 | |
@@ -59,9 +67,15 @@ discard block |
||
| 59 | 67 | |
| 60 | 68 | public function fillModelWithValue($model) |
| 61 | 69 | { |
| 62 | - if (property_exists($model, $this->name.'_first')) $model->{$this->name.'_first'} = $this->value_first; |
|
| 63 | - if (property_exists($model, $this->name.'_surname')) $model->{$this->name.'_surname'} = $this->value_surname; |
|
| 64 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 70 | + if (property_exists($model, $this->name.'_first')) { |
|
| 71 | + $model->{$this->name.'_first'} = $this->value_first; |
|
| 72 | + } |
|
| 73 | + if (property_exists($model, $this->name.'_surname')) { |
|
| 74 | + $model->{$this->name.'_surname'} = $this->value_surname; |
|
| 75 | + } |
|
| 76 | + if (property_exists($model, $this->name)) { |
|
| 77 | + $model->{$this->name} = $this->value; |
|
| 78 | + } |
|
| 65 | 79 | } |
| 66 | 80 | |
| 67 | 81 | public function validateRequired() |