@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @param ComponentList $component_list |
| 61 | 61 | */ |
| 62 | - public function __construct( ComponentList $component_list = null ) |
|
| 62 | + public function __construct(ComponentList $component_list = null) |
|
| 63 | 63 | { |
| 64 | - if(null === $component_list) |
|
| 64 | + if (null === $component_list) |
|
| 65 | 65 | { |
| 66 | 66 | $component_list = new ComponentList(); |
| 67 | 67 | } |
@@ -85,16 +85,16 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return array The updated values array. |
| 87 | 87 | */ |
| 88 | - public function update( array $new_instance = array(), array $old_instance = array() ) |
|
| 88 | + public function update(array $new_instance = array(), array $old_instance = array()) |
|
| 89 | 89 | { |
| 90 | - $this->old_instance = array_merge($this->get_defaults(),$old_instance); |
|
| 91 | - $this->new_instance = array_merge($this->old_instance,$new_instance); |
|
| 90 | + $this->old_instance = array_merge($this->get_defaults(), $old_instance); |
|
| 91 | + $this->new_instance = array_merge($this->old_instance, $new_instance); |
|
| 92 | 92 | $this->final_instance = $this->new_instance; |
| 93 | 93 | |
| 94 | - foreach ( $this->component_list->get_value_components() as $component ) |
|
| 94 | + foreach ($this->component_list->get_value_components() as $component) |
|
| 95 | 95 | { |
| 96 | 96 | // Update individual fields, as well as the composite parent field. |
| 97 | - $this->update_component( $component ); |
|
| 97 | + $this->update_component($component); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $this->final_instance; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function reset() |
| 109 | 109 | { |
| 110 | - foreach( $this->component_list->get_value_components() as $c ) |
|
| 110 | + foreach ($this->component_list->get_value_components() as $c) |
|
| 111 | 111 | { |
| 112 | 112 | $c->value = $c->default; |
| 113 | 113 | $this->final_instance[$c->name] = $c->default; |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @param ValueComponentInterface $component The component to validate. |
| 145 | 145 | */ |
| 146 | - private function update_component( ValueComponentInterface $component ) |
|
| 146 | + private function update_component(ValueComponentInterface $component) |
|
| 147 | 147 | { |
| 148 | 148 | $component->value = $this->final_instance[$component->name]; |
| 149 | 149 | |
| 150 | 150 | // Skip if this field is disabled |
| 151 | - if( $this->is_disabled($component) ) |
|
| 151 | + if ($this->is_disabled($component)) |
|
| 152 | 152 | { |
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // Apply user-defined filter |
| 157 | - $this->filter( $component ); |
|
| 157 | + $this->filter($component); |
|
| 158 | 158 | |
| 159 | 159 | // Validate value |
| 160 | - $this->validate( $component ); |
|
| 160 | + $this->validate($component); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param UI\AbstractComponent $component |
| 167 | 167 | * @return boolean |
| 168 | 168 | */ |
| 169 | - private function is_disabled( $component ) |
|
| 169 | + private function is_disabled($component) |
|
| 170 | 170 | { |
| 171 | 171 | return |
| 172 | 172 | $component instanceof DisableableComponentInterface && |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @param UI\AbstractComponent $component |
| 183 | 183 | */ |
| 184 | - private function filter( $component ) |
|
| 184 | + private function filter($component) |
|
| 185 | 185 | { |
| 186 | - if( $component instanceof FilterableComponentInterface ) |
|
| 186 | + if ($component instanceof FilterableComponentInterface) |
|
| 187 | 187 | { |
| 188 | 188 | $filter = $component->filter; |
| 189 | 189 | |
| 190 | - if( is_callable( $filter ) ) |
|
| 190 | + if (is_callable($filter)) |
|
| 191 | 191 | { |
| 192 | 192 | $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name])); |
| 193 | 193 | $this->final_instance[$component->name] = $component->value; |
@@ -203,22 +203,22 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param UI\AbstractComponent $component The component to validate. |
| 205 | 205 | */ |
| 206 | - private function validate( $component ) |
|
| 206 | + private function validate($component) |
|
| 207 | 207 | { |
| 208 | - if( !($component instanceof ValidatableComponentInterface) ) return; |
|
| 208 | + if (!($component instanceof ValidatableComponentInterface)) return; |
|
| 209 | 209 | |
| 210 | 210 | $name = $component->name; |
| 211 | 211 | $validate = $component->validation; |
| 212 | 212 | |
| 213 | 213 | $component->validity = $component::VALID; |
| 214 | 214 | |
| 215 | - if(is_callable($validate)) |
|
| 215 | + if (is_callable($validate)) |
|
| 216 | 216 | { |
| 217 | 217 | $error = ''; |
| 218 | 218 | $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error)); |
| 219 | 219 | |
| 220 | 220 | // Invalid input, use old instance or default value |
| 221 | - if ( true !== $valid ) |
|
| 221 | + if (true !== $valid) |
|
| 222 | 222 | { |
| 223 | 223 | $this->errors[$name] = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE; |
| 224 | 224 | $component->value = $this->old_instance[$name]; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | { |
| 238 | 238 | $defaults = array(); |
| 239 | 239 | |
| 240 | - foreach( $this->component_list->get_value_components() as $component ) |
|
| 240 | + foreach ($this->component_list->get_value_components() as $component) |
|
| 241 | 241 | { |
| 242 | 242 | $defaults[$component->name] = $component->default; |
| 243 | 243 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param array $model |
| 40 | 40 | */ |
| 41 | - public function __construct( array $model = array() ) |
|
| 41 | + public function __construct(array $model = array()) |
|
| 42 | 42 | { |
| 43 | 43 | parent::__construct($model); |
| 44 | 44 | |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - public function set_model( $model ) |
|
| 82 | + public function set_model($model) |
|
| 83 | 83 | { |
| 84 | 84 | // Check that the required arguments are provided. |
| 85 | - foreach( $this->required_arguments() as $key ) |
|
| 85 | + foreach ($this->required_arguments() as $key) |
|
| 86 | 86 | { |
| 87 | - if ( !isset($model[$key]) ) |
|
| 87 | + if (!isset($model[$key])) |
|
| 88 | 88 | { |
| 89 | 89 | throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class()); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Assign the name of the component as the id if no id was specified |
| 94 | - if( !isset($model['id']) && isset($model['name']) ) |
|
| 94 | + if (!isset($model['id']) && isset($model['name'])) |
|
| 95 | 95 | { |
| 96 | 96 | $model['id'] = $model['name']; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $this->model = array_merge( $this->default_model(), $model ); |
|
| 99 | + $this->model = array_merge($this->default_model(), $model); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @param string $class |
| 117 | 117 | */ |
| 118 | - public function add_html_class( $class ) |
|
| 118 | + public function add_html_class($class) |
|
| 119 | 119 | { |
| 120 | - if( !in_array($class, $this->html_classes) ) |
|
| 120 | + if (!in_array($class, $this->html_classes)) |
|
| 121 | 121 | { |
| 122 | 122 | $this->html_classes[] = $class; |
| 123 | 123 | } |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @param string $class |
| 131 | 131 | */ |
| 132 | - public function remove_html_class( $class ) |
|
| 132 | + public function remove_html_class($class) |
|
| 133 | 133 | { |
| 134 | 134 | $i = 0; |
| 135 | - foreach( $this->html_classes as $c ) |
|
| 135 | + foreach ($this->html_classes as $c) |
|
| 136 | 136 | { |
| 137 | - if( $c === $class ) |
|
| 137 | + if ($c === $class) |
|
| 138 | 138 | { |
| 139 | - array_splice($this->html_classes,$i,1); |
|
| 139 | + array_splice($this->html_classes, $i, 1); |
|
| 140 | 140 | break; |
| 141 | 141 | } |
| 142 | 142 | $i++; |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @param type $validity |
| 150 | 150 | */ |
| 151 | - Public function set_validity( $validity ) |
|
| 151 | + Public function set_validity($validity) |
|
| 152 | 152 | { |
| 153 | 153 | $this->validity = $validity; |
| 154 | - if($validity === $this::INVALID) |
|
| 154 | + if ($validity === $this::INVALID) |
|
| 155 | 155 | { |
| 156 | 156 | $this->add_html_class('amarkal-ui-component-error'); |
| 157 | 157 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * {@inheritdoc} |
| 176 | 176 | */ |
| 177 | - public function render( $echo = false ) |
|
| 177 | + public function render($echo = false) |
|
| 178 | 178 | { |
| 179 | 179 | $this->enqueue_scripts(); |
| 180 | 180 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | include dirname(__FILE__).'/AbstractComponent.phtml'; |
| 183 | 183 | $html = ob_get_clean(); |
| 184 | 184 | |
| 185 | - if( !$echo ) |
|
| 185 | + if (!$echo) |
|
| 186 | 186 | { |
| 187 | 187 | return $html; |
| 188 | 188 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | 'disabled' => false, |
| 22 | 22 | 'readonly' => false, |
| 23 | 23 | 'default' => null, |
| 24 | - 'filter' => array( $this, 'filter' ) |
|
| 24 | + 'filter' => array($this, 'filter') |
|
| 25 | 25 | ); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function filter($v) |
| 48 | 48 | { |
| 49 | - if($v !== 'on') return 'off'; |
|
| 49 | + if ($v !== 'on') return 'off'; |
|
| 50 | 50 | return 'on'; |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | * The __set magic method is overridden here to apply value & name 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 | } |
| 36 | 36 | |
| 37 | - if( 'name' === $name ) |
|
| 37 | + if ('name' === $name) |
|
| 38 | 38 | { |
| 39 | 39 | $this->set_name($value); |
| 40 | 40 | } |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * @param array $value |
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | - public function set_value( array $value ) |
|
| 49 | + public function set_value(array $value) |
|
| 50 | 50 | { |
| 51 | - foreach($value as $n => $v) |
|
| 51 | + foreach ($value as $n => $v) |
|
| 52 | 52 | { |
| 53 | 53 | $component = $this->get_component($n); |
| 54 | 54 | $component->value = $v; |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | * @param string $name |
| 62 | 62 | * @return void |
| 63 | 63 | */ |
| 64 | - public function set_name( $name ) |
|
| 64 | + public function set_name($name) |
|
| 65 | 65 | { |
| 66 | - foreach($this->components as $c) |
|
| 66 | + foreach ($this->components as $c) |
|
| 67 | 67 | { |
| 68 | 68 | $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template); |
| 69 | 69 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function required_arguments() |
| 93 | 93 | { |
| 94 | - return array('name','components','template'); |
|
| 94 | + return array('name', 'components', 'template'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function parse_template() |
| 111 | 111 | { |
| 112 | - return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a){ |
|
| 112 | + return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a) { |
|
| 113 | 113 | $component = $this->get_component($a[1]); |
| 114 | 114 | return $component->render(); |
| 115 | 115 | }, $this->model['template']); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function get_name() |
| 126 | 126 | { |
| 127 | - if('' !== $this->parent_name) |
|
| 127 | + if ('' !== $this->parent_name) |
|
| 128 | 128 | { |
| 129 | 129 | return "{$this->parent_name}[{$this->name}]"; |
| 130 | 130 | } |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | public function filter($v) |
| 135 | 135 | { |
| 136 | - foreach($this->components as $component) |
|
| 136 | + foreach ($this->components as $component) |
|
| 137 | 137 | { |
| 138 | - if($component instanceof FilterableComponentInterface && |
|
| 138 | + if ($component instanceof FilterableComponentInterface && |
|
| 139 | 139 | \is_callable($component->filter)) |
| 140 | 140 | { |
| 141 | 141 | $n = $component->name; |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | return $v; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - public function validation($v,&$e) |
|
| 149 | + public function validation($v, &$e) |
|
| 150 | 150 | { |
| 151 | - foreach($this->components as $component) |
|
| 151 | + foreach ($this->components as $component) |
|
| 152 | 152 | { |
| 153 | - if($component instanceof ValidatableComponentInterface && |
|
| 153 | + if ($component instanceof ValidatableComponentInterface && |
|
| 154 | 154 | \is_callable($component->validation)) |
| 155 | 155 | { |
| 156 | 156 | $n = $component->name; |
| 157 | - if(!$component->validation($v[$n],$e)) |
|
| 157 | + if (!$component->validation($v[$n], $e)) |
|
| 158 | 158 | { |
| 159 | 159 | return false; |
| 160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | protected function on_created() |
| 170 | 170 | { |
| 171 | - foreach( $this->model['components'] as $args ) |
|
| 171 | + foreach ($this->model['components'] as $args) |
|
| 172 | 172 | { |
| 173 | 173 | $this->components[$args['name']] = $this->create_component($args); |
| 174 | 174 | } |
@@ -179,16 +179,16 @@ discard block |
||
| 179 | 179 | * @param type $args |
| 180 | 180 | * @return type |
| 181 | 181 | */ |
| 182 | - private function create_component( $args ) |
|
| 182 | + private function create_component($args) |
|
| 183 | 183 | { |
| 184 | 184 | $type = $args['type']; |
| 185 | 185 | |
| 186 | - if('composite' === $type) |
|
| 186 | + if ('composite' === $type) |
|
| 187 | 187 | { |
| 188 | 188 | $args['parent_name'] = $this->get_name(); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - $c = \Amarkal\UI\ComponentFactory::create( $type, $args ); |
|
| 191 | + $c = \Amarkal\UI\ComponentFactory::create($type, $args); |
|
| 192 | 192 | |
| 193 | 193 | // Apply the composite name template |
| 194 | 194 | $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template); |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | * @return UI\AbstractComponent |
| 204 | 204 | * @throws \RuntimeException If there's no child component corresponding to the given name |
| 205 | 205 | */ |
| 206 | - private function get_component( $name ) |
|
| 206 | + private function get_component($name) |
|
| 207 | 207 | { |
| 208 | - if(!array_key_exists($name, $this->components)) |
|
| 208 | + if (!array_key_exists($name, $this->components)) |
|
| 209 | 209 | { |
| 210 | 210 | throw new \RuntimeException("Composite sub-component not found with name $name"); |
| 211 | 211 | } |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | 'multi' => false, |
| 25 | 25 | 'data' => array(), |
| 26 | 26 | 'default' => array(), |
| 27 | - 'filter' => array( $this, 'filter' ) |
|
| 27 | + 'filter' => array($this, 'filter') |
|
| 28 | 28 | ); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function required_arguments() |
| 32 | 32 | { |
| 33 | - return array('name','data'); |
|
| 33 | + return array('name', 'data'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function get_template_path() |
@@ -49,16 +49,16 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function filter($v) |
| 51 | 51 | { |
| 52 | - if($this->multi && !\is_array($v)) |
|
| 52 | + if ($this->multi && !\is_array($v)) |
|
| 53 | 53 | { |
| 54 | 54 | return \explode(',', $v); |
| 55 | 55 | } |
| 56 | 56 | return $v; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - protected function is_selected( $value ) |
|
| 59 | + protected function is_selected($value) |
|
| 60 | 60 | { |
| 61 | - if($this->multi) |
|
| 61 | + if ($this->multi) |
|
| 62 | 62 | { |
| 63 | 63 | return \in_array($value, $this->value); |
| 64 | 64 | } |