@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param array $components An array of arrays of component arguments |
61 | 61 | */ |
62 | - public function __construct( array $components = array() ) |
|
62 | + public function __construct(array $components = array()) |
|
63 | 63 | { |
64 | 64 | $this->add_components($components); |
65 | 65 | } |
@@ -81,18 +81,18 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return array The updated values array. |
83 | 83 | */ |
84 | - public function update( array $new_instance = array(), array $old_instance = array() ) |
|
84 | + public function update(array $new_instance = array(), array $old_instance = array()) |
|
85 | 85 | { |
86 | - $this->old_instance = array_merge($this->get_defaults(),$old_instance); |
|
87 | - $this->new_instance = array_merge($this->old_instance,$new_instance); |
|
86 | + $this->old_instance = array_merge($this->get_defaults(), $old_instance); |
|
87 | + $this->new_instance = array_merge($this->old_instance, $new_instance); |
|
88 | 88 | $this->final_instance = $this->new_instance; |
89 | 89 | |
90 | - foreach ( $this->components as $component ) |
|
90 | + foreach ($this->components as $component) |
|
91 | 91 | { |
92 | 92 | // Update individual fields, as well as the composite parent field. |
93 | - if ( $component instanceof ValueComponentInterface ) |
|
93 | + if ($component instanceof ValueComponentInterface) |
|
94 | 94 | { |
95 | - $this->update_component( $component ); |
|
95 | + $this->update_component($component); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function reset() |
108 | 108 | { |
109 | - foreach( $this->components as $c ) |
|
109 | + foreach ($this->components as $c) |
|
110 | 110 | { |
111 | 111 | $c->value = $c->default; |
112 | 112 | $this->final_instance[$c->name] = $c->default; |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * @param array $args The component arguments |
132 | 132 | * @throws \RuntimeException If a component with the same name has already been registered |
133 | 133 | */ |
134 | - public function add_component( array $args ) |
|
134 | + public function add_component(array $args) |
|
135 | 135 | { |
136 | 136 | $name = $args['name']; |
137 | - if(array_key_exists($name, $this->components)) |
|
137 | + if (array_key_exists($name, $this->components)) |
|
138 | 138 | { |
139 | 139 | throw new \RuntimeException("A component with the name <b>$name</b> has already been created"); |
140 | 140 | } |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param array $components |
148 | 148 | */ |
149 | - public function add_components( array $components ) |
|
149 | + public function add_components(array $components) |
|
150 | 150 | { |
151 | - foreach( $components as $component ) |
|
151 | + foreach ($components as $component) |
|
152 | 152 | { |
153 | 153 | $this->add_component($component); |
154 | 154 | } |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * @param string $name |
161 | 161 | * @return UI\AbstractComponent |
162 | 162 | */ |
163 | - public function get_component( $name ) |
|
163 | + public function get_component($name) |
|
164 | 164 | { |
165 | - if(!array_key_exists($name, $this->components)) |
|
165 | + if (!array_key_exists($name, $this->components)) |
|
166 | 166 | { |
167 | 167 | throw new \RuntimeException("Can't find a component with the name <b>$name</b>"); |
168 | 168 | } |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @param ValueComponentInterface $component The component to validate. |
188 | 188 | */ |
189 | - private function update_component( ValueComponentInterface $component ) |
|
189 | + private function update_component(ValueComponentInterface $component) |
|
190 | 190 | { |
191 | 191 | $component->value = $this->final_instance[$component->name]; |
192 | 192 | |
193 | 193 | // Skip if this field is disabled |
194 | - if( $this->is_disabled($component) ) |
|
194 | + if ($this->is_disabled($component)) |
|
195 | 195 | { |
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | 199 | // Apply user-defined filter |
200 | - $this->filter( $component ); |
|
200 | + $this->filter($component); |
|
201 | 201 | |
202 | 202 | // Validate value |
203 | - $this->validate( $component ); |
|
203 | + $this->validate($component); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param UI\AbstractComponent $component |
210 | 210 | * @return boolean |
211 | 211 | */ |
212 | - private function is_disabled( $component ) |
|
212 | + private function is_disabled($component) |
|
213 | 213 | { |
214 | 214 | return |
215 | 215 | $component instanceof DisableableComponentInterface && |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @param UI\AbstractComponent $component |
226 | 226 | */ |
227 | - private function filter( $component ) |
|
227 | + private function filter($component) |
|
228 | 228 | { |
229 | - if( $component instanceof FilterableComponentInterface ) |
|
229 | + if ($component instanceof FilterableComponentInterface) |
|
230 | 230 | { |
231 | 231 | $filter = $component->filter; |
232 | 232 | |
233 | - if( is_callable( $filter ) ) |
|
233 | + if (is_callable($filter)) |
|
234 | 234 | { |
235 | 235 | $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name])); |
236 | 236 | $this->final_instance[$component->name] = $component->value; |
@@ -246,22 +246,22 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @param UI\AbstractComponent $component The component to validate. |
248 | 248 | */ |
249 | - private function validate( $component ) |
|
249 | + private function validate($component) |
|
250 | 250 | { |
251 | - if( !($component instanceof ValidatableComponentInterface) ) return; |
|
251 | + if (!($component instanceof ValidatableComponentInterface)) return; |
|
252 | 252 | |
253 | 253 | $name = $component->name; |
254 | 254 | $validate = $component->validation; |
255 | 255 | |
256 | 256 | $component->validity = $component::VALID; |
257 | 257 | |
258 | - if(is_callable($validate)) |
|
258 | + if (is_callable($validate)) |
|
259 | 259 | { |
260 | 260 | $error = ''; |
261 | 261 | $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error)); |
262 | 262 | |
263 | 263 | // Invalid input, use old instance or default value |
264 | - if ( true !== $valid ) |
|
264 | + if (true !== $valid) |
|
265 | 265 | { |
266 | 266 | $this->errors[$name] = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE; |
267 | 267 | $component->value = $this->old_instance[$name]; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | { |
281 | 281 | $defaults = array(); |
282 | 282 | |
283 | - foreach( $this->components as $component ) |
|
283 | + foreach ($this->components as $component) |
|
284 | 284 | { |
285 | 285 | $defaults[$component->name] = $component->default; |
286 | 286 | } |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | * The __set magic method is overridden here to apply value changes to |
26 | 26 | * child components. |
27 | 27 | */ |
28 | - public function __set( $name, $value ) |
|
28 | + public function __set($name, $value) |
|
29 | 29 | { |
30 | 30 | parent::__set($name, $value); |
31 | 31 | |
32 | - if( 'value' === $name ) |
|
32 | + if ('value' === $name) |
|
33 | 33 | { |
34 | 34 | $this->set_value($value); |
35 | 35 | } |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param array $value |
42 | 42 | */ |
43 | - public function set_value( array $value ) |
|
43 | + public function set_value(array $value) |
|
44 | 44 | { |
45 | - foreach($value as $n => $v) |
|
45 | + foreach ($value as $n => $v) |
|
46 | 46 | { |
47 | 47 | $component = $this->get_component($n); |
48 | 48 | $component->value = $v; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function required_arguments() |
73 | 73 | { |
74 | - return array('name','components','template'); |
|
74 | + return array('name', 'components', 'template'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function parse_template() |
91 | 91 | { |
92 | - return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a){ |
|
92 | + return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a) { |
|
93 | 93 | $component = $this->get_component($a[1]); |
94 | 94 | return $component->render(); |
95 | 95 | }, $this->model['template']); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function get_name() |
106 | 106 | { |
107 | - if('' !== $this->parent_name) |
|
107 | + if ('' !== $this->parent_name) |
|
108 | 108 | { |
109 | 109 | return "{$this->parent_name}[{$this->name}]"; |
110 | 110 | } |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | |
114 | 114 | public function filter($v) |
115 | 115 | { |
116 | - foreach($this->components as $component) |
|
116 | + foreach ($this->components as $component) |
|
117 | 117 | { |
118 | - if($component instanceof FilterableComponentInterface && |
|
118 | + if ($component instanceof FilterableComponentInterface && |
|
119 | 119 | \is_callable($component->filter)) |
120 | 120 | { |
121 | 121 | $n = $component->name; |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | return $v; |
127 | 127 | } |
128 | 128 | |
129 | - public function validation($v,&$e) |
|
129 | + public function validation($v, &$e) |
|
130 | 130 | { |
131 | - foreach($this->components as $component) |
|
131 | + foreach ($this->components as $component) |
|
132 | 132 | { |
133 | - if($component instanceof ValidatableComponentInterface && |
|
133 | + if ($component instanceof ValidatableComponentInterface && |
|
134 | 134 | \is_callable($component->validation)) |
135 | 135 | { |
136 | 136 | $n = $component->name; |
137 | - if(!$component->validation($v[$n],$e)) |
|
137 | + if (!$component->validation($v[$n], $e)) |
|
138 | 138 | { |
139 | 139 | return false; |
140 | 140 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function on_created() |
150 | 150 | { |
151 | - foreach( $this->model['components'] as $args ) |
|
151 | + foreach ($this->model['components'] as $args) |
|
152 | 152 | { |
153 | 153 | $this->components[$args['name']] = $this->create_component($args); |
154 | 154 | } |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | * @param type $args |
160 | 160 | * @return type |
161 | 161 | */ |
162 | - private function create_component( $args ) |
|
162 | + private function create_component($args) |
|
163 | 163 | { |
164 | 164 | $type = $args['type']; |
165 | 165 | |
166 | - if('composite' === $type) |
|
166 | + if ('composite' === $type) |
|
167 | 167 | { |
168 | 168 | $args['parent_name'] = $this->get_name(); |
169 | 169 | } |
170 | 170 | |
171 | - $c = \Amarkal\UI\ComponentFactory::create( $type, $args ); |
|
171 | + $c = \Amarkal\UI\ComponentFactory::create($type, $args); |
|
172 | 172 | |
173 | 173 | // Apply the composite name template |
174 | 174 | $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template); |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | * @return UI\AbstractComponent |
184 | 184 | * @throws \RuntimeException If there's no child component corresponding to the given name |
185 | 185 | */ |
186 | - private function get_component( $name ) |
|
186 | + private function get_component($name) |
|
187 | 187 | { |
188 | - if(!array_key_exists($name, $this->components)) |
|
188 | + if (!array_key_exists($name, $this->components)) |
|
189 | 189 | { |
190 | 190 | throw new \RuntimeException("Composite sub-component not found with name $name"); |
191 | 191 | } |