@@ -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 |
@@ -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 |
@@ -12,50 +12,50 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $path; |
|
15 | + protected $path; |
|
16 | 16 | |
17 | - /** |
|
17 | + /** |
|
18 | 18 | * Create a new plugin instance. |
19 | 19 | * |
20 | 20 | */ |
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->setPath(); |
|
24 | - } |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->setPath(); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
26 | + /** |
|
27 | 27 | * Set the plugin autoload path. |
28 | 28 | * |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function setPath() |
|
32 | - { |
|
31 | + public function setPath() |
|
32 | + { |
|
33 | 33 | $this->path = Reflect::getDirectory($this); |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
36 | + /** |
|
37 | 37 | * Get autoload path. |
38 | 38 | * |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public function path($append = null) |
|
42 | - { |
|
43 | - return is_null($append) ? $this->path |
|
44 | - : $this->path.'/'.ltrim(rtrim($append, '/'), '/').'/'; |
|
45 | - } |
|
41 | + public function path($append = null) |
|
42 | + { |
|
43 | + return is_null($append) ? $this->path |
|
44 | + : $this->path.'/'.ltrim(rtrim($append, '/'), '/').'/'; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
47 | + /** |
|
48 | 48 | * Get paths to templates. |
49 | 49 | * |
50 | 50 | * @return string |
51 | 51 | */ |
52 | - public function templatePaths() |
|
53 | - { |
|
54 | - $path = $this->path('templates'); |
|
55 | - return [$path]; |
|
56 | - } |
|
52 | + public function templatePaths() |
|
53 | + { |
|
54 | + $path = $this->path('templates'); |
|
55 | + return [$path]; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
58 | + /** |
|
59 | 59 | * Trigger an event callback. |
60 | 60 | * - onLoad |
61 | 61 | * - onDefine |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * - onValid |
68 | 68 | * - onInvalid |
69 | 69 | * |
70 | - * @param \Helmut\Forms\Form $form |
|
71 | - * @param string $name |
|
72 | - * @param array $params |
|
70 | + * @param \Helmut\Forms\Form $form |
|
71 | + * @param string $name |
|
72 | + * @param array $params |
|
73 | 73 | * @return mixed |
74 | 74 | */ |
75 | - public function event($form, $name, $params = []) |
|
76 | - { |
|
77 | - $name = Str::studly($name); |
|
75 | + public function event($form, $name, $params = []) |
|
76 | + { |
|
77 | + $name = Str::studly($name); |
|
78 | 78 | |
79 | - if (method_exists($this, 'on'.$name)) { |
|
80 | - return call_user_func_array(array($this, 'on'.$name), [$form, $params]); |
|
81 | - } |
|
79 | + if (method_exists($this, 'on'.$name)) { |
|
80 | + return call_user_func_array(array($this, 'on'.$name), [$form, $params]); |
|
81 | + } |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -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 |
@@ -113,7 +113,6 @@ |
||
113 | 113 | /** |
114 | 114 | * Set field value using provided default. |
115 | 115 | * |
116 | - * @param mixed $default |
|
117 | 116 | * @return void |
118 | 117 | */ |
119 | 118 | abstract public function setValueFromDefault(); |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace Helmut\Forms; |
4 | 4 | |
5 | -use Helmut\Forms\Utility\Str; |
|
6 | 5 | use Helmut\Forms\Utility\Reflect; |
6 | +use Helmut\Forms\Utility\Str; |
|
7 | 7 | |
8 | 8 | abstract class Field { |
9 | 9 |
@@ -179,9 +179,11 @@ discard block |
||
179 | 179 | { |
180 | 180 | $values = $this->getValue(); |
181 | 181 | |
182 | - if (is_null($values)) $values = []; |
|
183 | - |
|
184 | - else if ( ! is_array($values)) $values = [$this->name => $values]; |
|
182 | + if (is_null($values)) { |
|
183 | + $values = []; |
|
184 | + } else if ( ! is_array($values)) { |
|
185 | + $values = [$this->name => $values]; |
|
186 | + } |
|
185 | 187 | |
186 | 188 | return $values; |
187 | 189 | } |
@@ -196,7 +198,9 @@ discard block |
||
196 | 198 | { |
197 | 199 | $properties = $this->renderWith(); |
198 | 200 | |
199 | - if (is_null($properties)) $properties = []; |
|
201 | + if (is_null($properties)) { |
|
202 | + $properties = []; |
|
203 | + } |
|
200 | 204 | |
201 | 205 | return $properties; |
202 | 206 | } |
@@ -210,9 +214,11 @@ discard block |
||
210 | 214 | { |
211 | 215 | $buttons = $this->getButtonName(); |
212 | 216 | |
213 | - if (is_null($buttons)) $buttons = []; |
|
214 | - |
|
215 | - else if ( ! is_array($buttons)) $buttons = [$buttons]; |
|
217 | + if (is_null($buttons)) { |
|
218 | + $buttons = []; |
|
219 | + } else if ( ! is_array($buttons)) { |
|
220 | + $buttons = [$buttons]; |
|
221 | + } |
|
216 | 222 | |
217 | 223 | return $buttons; |
218 | 224 | } |
@@ -224,7 +230,9 @@ discard block |
||
224 | 230 | */ |
225 | 231 | public function setFromDefault() |
226 | 232 | { |
227 | - if ( ! is_null($this->default)) $this->setValueFromDefault(); |
|
233 | + if ( ! is_null($this->default)) { |
|
234 | + $this->setValueFromDefault(); |
|
235 | + } |
|
228 | 236 | } |
229 | 237 | |
230 | 238 | /** |
@@ -412,7 +420,9 @@ discard block |
||
412 | 420 | */ |
413 | 421 | public function error($message) |
414 | 422 | { |
415 | - if ( ! isset($this->errors['userDefined'])) $this->errors['userDefined'] = []; |
|
423 | + if ( ! isset($this->errors['userDefined'])) { |
|
424 | + $this->errors['userDefined'] = []; |
|
425 | + } |
|
416 | 426 | |
417 | 427 | $this->errors['userDefined'][] = $message; |
418 | 428 | } |
@@ -437,7 +447,9 @@ discard block |
||
437 | 447 | */ |
438 | 448 | protected function clearValidationError($method) |
439 | 449 | { |
440 | - if (isset($this->errors[$method])) unset($this->errors[$method]); |
|
450 | + if (isset($this->errors[$method])) { |
|
451 | + unset($this->errors[$method]); |
|
452 | + } |
|
441 | 453 | } |
442 | 454 | |
443 | 455 | /** |