@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | |
53 | 53 | /** |
54 | 54 | * |
55 | - * @param type $type |
|
56 | - * @param type $props |
|
55 | + * @param string $type |
|
56 | + * @param type string |
|
57 | 57 | * @throws \RuntimeException |
58 | 58 | */ |
59 | 59 | private static function create_core_component( $type, $props ) |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | |
80 | 80 | /** |
81 | 81 | * |
82 | - * @param type $type |
|
83 | - * @param type $props |
|
82 | + * @param string $type |
|
83 | + * @param type string |
|
84 | 84 | * @throws \RuntimeException |
85 | 85 | */ |
86 | 86 | private static function create_registered_component( $type, $props ) |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param array $props |
21 | 21 | * @return AbstractComponent |
22 | 22 | */ |
23 | - public static function create( $type, array $props ) |
|
23 | + public static function create($type, array $props) |
|
24 | 24 | { |
25 | 25 | try { |
26 | 26 | $component = self::create_registered_component($type, $props); |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * @param string $class_name |
42 | 42 | * @throws \RuntimeException |
43 | 43 | */ |
44 | - public static function register( $type, $class_name ) |
|
44 | + public static function register($type, $class_name) |
|
45 | 45 | { |
46 | - if( !in_array($type, self::$registered_components) ) |
|
46 | + if (!in_array($type, self::$registered_components)) |
|
47 | 47 | { |
48 | 48 | self::$registered_components[$type] = $class_name; |
49 | 49 | } |
@@ -56,15 +56,15 @@ discard block |
||
56 | 56 | * @param type $props |
57 | 57 | * @throws \RuntimeException |
58 | 58 | */ |
59 | - private static function create_core_component( $type, $props ) |
|
59 | + private static function create_core_component($type, $props) |
|
60 | 60 | { |
61 | 61 | $file_name = __DIR__."/components/$type/controller.php"; |
62 | 62 | $class_name = 'Amarkal\\UI\\Component_'.$type; |
63 | 63 | |
64 | 64 | // Load one of the core components |
65 | - if(!class_exists($class_name)) |
|
65 | + if (!class_exists($class_name)) |
|
66 | 66 | { |
67 | - if( file_exists( $file_name ) ) |
|
67 | + if (file_exists($file_name)) |
|
68 | 68 | { |
69 | 69 | require_once $file_name; |
70 | 70 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param type $props |
84 | 84 | * @throws \RuntimeException |
85 | 85 | */ |
86 | - private static function create_registered_component( $type, $props ) |
|
86 | + private static function create_registered_component($type, $props) |
|
87 | 87 | { |
88 | - if(in_array($type, self::$registered_components)) |
|
88 | + if (in_array($type, self::$registered_components)) |
|
89 | 89 | { |
90 | 90 | $class_name = self::$registered_components[$type]; |
91 | 91 | return new $class_name($props); |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | if( !in_array($type, self::$registered_components) ) |
47 | 47 | { |
48 | 48 | self::$registered_components[$type] = $class_name; |
49 | + } else { |
|
50 | + throw new \RuntimeException("A component of type '$type' has already been registered."); |
|
49 | 51 | } |
50 | - else throw new \RuntimeException("A component of type '$type' has already been registered."); |
|
51 | 52 | } |
52 | 53 | |
53 | 54 | /** |
@@ -67,8 +68,7 @@ discard block |
||
67 | 68 | if( file_exists( $file_name ) ) |
68 | 69 | { |
69 | 70 | require_once $file_name; |
70 | - } |
|
71 | - else |
|
71 | + } else |
|
72 | 72 | { |
73 | 73 | throw new \RuntimeException("A component of type '$type' does not exist."); |
74 | 74 | } |
@@ -182,7 +182,7 @@ |
||
182 | 182 | /** |
183 | 183 | * Filter the component's value using its filter function (if applicable) |
184 | 184 | * |
185 | - * @param UI\FilterableComponentInterface $component |
|
185 | + * @param FilterableComponentInterface $component |
|
186 | 186 | */ |
187 | 187 | private function filter( FilterableComponentInterface $component ) |
188 | 188 | { |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @param array $components An array of arrays of component arguments |
65 | 65 | */ |
66 | - public function __construct( array $components = array() ) |
|
66 | + public function __construct(array $components = array()) |
|
67 | 67 | { |
68 | - foreach( $components as $args ) |
|
68 | + foreach ($components as $args) |
|
69 | 69 | { |
70 | 70 | $name = $args['name']; |
71 | - if(array_key_exists($name, $components)) |
|
71 | + if (array_key_exists($name, $components)) |
|
72 | 72 | { |
73 | 73 | throw new \RuntimeException("A component with the name <b>$name</b> has already been created"); |
74 | 74 | } |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return array The updated values array. |
95 | 95 | */ |
96 | - public function update( array $new_instance, array $old_instance = array() ) |
|
96 | + public function update(array $new_instance, array $old_instance = array()) |
|
97 | 97 | { |
98 | - $this->old_instance = array_merge($this->get_defaults(),$old_instance); |
|
99 | - $this->new_instance = array_merge($this->old_instance,$new_instance); |
|
98 | + $this->old_instance = array_merge($this->get_defaults(), $old_instance); |
|
99 | + $this->new_instance = array_merge($this->old_instance, $new_instance); |
|
100 | 100 | $this->final_instance = $this->new_instance; |
101 | 101 | |
102 | - foreach ( $this->components as $component ) |
|
102 | + foreach ($this->components as $component) |
|
103 | 103 | { |
104 | 104 | // Update individual fields, as well as the composite parent field. |
105 | - if ( $component instanceof ValueComponentInterface ) |
|
105 | + if ($component instanceof ValueComponentInterface) |
|
106 | 106 | { |
107 | - $this->update_component( $component ); |
|
107 | + $this->update_component($component); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @param array $names List of component names to be set to their defaults. If no names are specified, all components will be reset |
118 | 118 | * @return array The updated values array. |
119 | 119 | */ |
120 | - public function reset( array $names = array() ) |
|
120 | + public function reset(array $names = array()) |
|
121 | 121 | { |
122 | - if( array() === $names ) |
|
122 | + if (array() === $names) |
|
123 | 123 | { |
124 | 124 | // Unset new instance to force reset |
125 | 125 | $this->new_instance = array(); |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - foreach( $this->components as $c ) |
|
130 | + foreach ($this->components as $c) |
|
131 | 131 | { |
132 | - if( in_array($c->name, $names) ) |
|
132 | + if (in_array($c->name, $names)) |
|
133 | 133 | { |
134 | 134 | $this->new_instance[$c->name] = $c->default; |
135 | 135 | } |
@@ -156,26 +156,26 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @param ValueComponentInterface $component The component to validate. |
158 | 158 | */ |
159 | - private function update_component( ValueComponentInterface $component ) |
|
159 | + private function update_component(ValueComponentInterface $component) |
|
160 | 160 | { |
161 | 161 | $component->value = $this->final_instance[$component->name]; |
162 | 162 | |
163 | 163 | // Skip if this field is disabled |
164 | - if($component instanceof DisableableComponentInterface && |
|
164 | + if ($component instanceof DisableableComponentInterface && |
|
165 | 165 | true === $component->disabled) { |
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | 169 | // Apply user-defined filter |
170 | - if( $component instanceof FilterableComponentInterface ) |
|
170 | + if ($component instanceof FilterableComponentInterface) |
|
171 | 171 | { |
172 | - $this->filter( $component ); |
|
172 | + $this->filter($component); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | // Validate value |
176 | - if( $component instanceof ValidatableComponentInterface ) |
|
176 | + if ($component instanceof ValidatableComponentInterface) |
|
177 | 177 | { |
178 | - $this->validate( $component ); |
|
178 | + $this->validate($component); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @param UI\FilterableComponentInterface $component |
186 | 186 | */ |
187 | - private function filter( FilterableComponentInterface $component ) |
|
187 | + private function filter(FilterableComponentInterface $component) |
|
188 | 188 | { |
189 | 189 | $filter = $component->filter; |
190 | 190 | |
191 | - if( is_callable( $filter ) ) |
|
191 | + if (is_callable($filter)) |
|
192 | 192 | { |
193 | - $component->value = $filter( $this->final_instance[$component->name] ); |
|
193 | + $component->value = $filter($this->final_instance[$component->name]); |
|
194 | 194 | $this->final_instance[$component->name] = $component->value; |
195 | 195 | } |
196 | 196 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param ValidatableComponentInterface $component The component to validate. |
205 | 205 | */ |
206 | - private function validate( ValidatableComponentInterface $component ) |
|
206 | + private function validate(ValidatableComponentInterface $component) |
|
207 | 207 | { |
208 | 208 | $name = $component->name; |
209 | 209 | $validate = $component->validation; |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | |
212 | 212 | $component->validity = $component::VALID; |
213 | 213 | |
214 | - if(is_callable($validate)) |
|
214 | + if (is_callable($validate)) |
|
215 | 215 | { |
216 | 216 | $valid = $validate($this->new_instance[$name]); |
217 | 217 | |
218 | 218 | // Invalid input, use old instance or default value |
219 | - if ( true !== $valid ) |
|
219 | + if (true !== $valid) |
|
220 | 220 | { |
221 | 221 | $this->errors[$name] = $valid; |
222 | 222 | $component->value = $this->old_instance[$name]; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | { |
231 | 231 | $defaults = array(); |
232 | 232 | |
233 | - foreach( $this->components as $component ) |
|
233 | + foreach ($this->components as $component) |
|
234 | 234 | { |
235 | 235 | $defaults[$component->name] = $component->default; |
236 | 236 | } |
@@ -124,8 +124,7 @@ |
||
124 | 124 | // Unset new instance to force reset |
125 | 125 | $this->new_instance = array(); |
126 | 126 | return $this->update(); |
127 | - } |
|
128 | - else |
|
127 | + } else |
|
129 | 128 | { |
130 | 129 | foreach( $this->components as $c ) |
131 | 130 | { |
@@ -8,9 +8,9 @@ |
||
8 | 8 | class Component_text |
9 | 9 | extends AbstractComponent |
10 | 10 | implements ValueComponentInterface, |
11 | - DisableableComponentInterface, |
|
12 | - FilterableComponentInterface, |
|
13 | - ValidatableComponentInterface |
|
11 | + DisableableComponentInterface, |
|
12 | + FilterableComponentInterface, |
|
13 | + ValidatableComponentInterface |
|
14 | 14 | { |
15 | 15 | public function default_model() |
16 | 16 | { |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Prevent direct file access |
15 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
15 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Prevent loading the library more than once |
19 | 19 | */ |
20 | -if( defined( 'AMARKAL_UI' ) ) return false; |
|
21 | -define( 'AMARKAL_UI', true ); |
|
20 | +if (defined('AMARKAL_UI')) return false; |
|
21 | +define('AMARKAL_UI', true); |
|
22 | 22 | |
23 | -if(!function_exists('amarkal_ui_render')) |
|
23 | +if (!function_exists('amarkal_ui_render')) |
|
24 | 24 | { |
25 | 25 | /** |
26 | 26 | * Render a UI component. |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | * @param array $props The component's properties |
31 | 31 | * @return string The rendered HTML |
32 | 32 | */ |
33 | - function amarkal_ui_render( $type, array $props = array() ) |
|
33 | + function amarkal_ui_render($type, array $props = array()) |
|
34 | 34 | { |
35 | - $component = Amarkal\UI\ComponentFactory::create( $type, $props ); |
|
35 | + $component = Amarkal\UI\ComponentFactory::create($type, $props); |
|
36 | 36 | return $component->render(); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | -if(!function_exists('amarkal_ui_register_component')) |
|
40 | +if (!function_exists('amarkal_ui_register_component')) |
|
41 | 41 | { |
42 | 42 | /** |
43 | 43 | * Register a custom UI component. The registered component's class should |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * to one of the core component's type, it will override the core component. |
48 | 48 | * @param string $class_name The component's class name. |
49 | 49 | */ |
50 | - function amarkal_ui_register_component( $type, $class_name ) |
|
50 | + function amarkal_ui_register_component($type, $class_name) |
|
51 | 51 | { |
52 | - Amarkal\UI\ComponentFactory::register( $type, $class_name ); |
|
52 | + Amarkal\UI\ComponentFactory::register($type, $class_name); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | \ No newline at end of file |