@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function required_arguments() |
| 23 | 23 | { |
| 24 | - return array('name','data'); |
|
| 24 | + return array('name', 'data'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function get_template_path() |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | class Component_select |
| 9 | 9 | extends AbstractComponent |
| 10 | 10 | implements ValueComponentInterface, |
| 11 | - DisableableComponentInterface |
|
| 11 | + DisableableComponentInterface |
|
| 12 | 12 | { |
| 13 | 13 | public $component_type = 'select'; |
| 14 | 14 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | // Prevent direct file access |
| 9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
| 9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
| 10 | 10 | |
| 11 | 11 | // Load module functions |
| 12 | 12 | require_once 'functions.php'; |
| 13 | 13 | \ No newline at end of file |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @param array $model |
| 26 | 26 | * @param string $template_path |
| 27 | 27 | */ |
| 28 | - public function __construct( array $model = array(), $template_path = null ) |
|
| 28 | + public function __construct(array $model = array(), $template_path = null) |
|
| 29 | 29 | { |
| 30 | - $this->set_model( $model ); |
|
| 30 | + $this->set_model($model); |
|
| 31 | 31 | $this->template = $template_path; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return mixed the argument's value. |
| 40 | 40 | */ |
| 41 | - public function __get( $name ) |
|
| 41 | + public function __get($name) |
|
| 42 | 42 | { |
| 43 | - if( isset( $this->model[$name] ) ) |
|
| 43 | + if (isset($this->model[$name])) |
|
| 44 | 44 | { |
| 45 | 45 | return $this->model[$name]; |
| 46 | 46 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return mixed the settings' argument value. |
| 56 | 56 | */ |
| 57 | - public function __set( $name, $value ) |
|
| 57 | + public function __set($name, $value) |
|
| 58 | 58 | { |
| 59 | 59 | $this->model[$name] = $value; |
| 60 | 60 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function set_model( $model ) |
|
| 77 | + public function set_model($model) |
|
| 78 | 78 | { |
| 79 | 79 | $this->model = $model; |
| 80 | 80 | } |
@@ -95,22 +95,22 @@ discard block |
||
| 95 | 95 | * @return string The rendered template. |
| 96 | 96 | * @throws TemplateNotFoundException Thrown if the template file cannot be found. |
| 97 | 97 | */ |
| 98 | - public function render( $echo = false ) |
|
| 98 | + public function render($echo = false) |
|
| 99 | 99 | { |
| 100 | 100 | $rendered_html = ''; |
| 101 | 101 | |
| 102 | - if( file_exists( $this->get_template_path() ) ) |
|
| 102 | + if (file_exists($this->get_template_path())) |
|
| 103 | 103 | { |
| 104 | 104 | ob_start(); |
| 105 | - include( $this->get_template_path() ); |
|
| 105 | + include($this->get_template_path()); |
|
| 106 | 106 | $rendered_html = ob_get_clean(); |
| 107 | 107 | } |
| 108 | 108 | else |
| 109 | 109 | { |
| 110 | - throw new \RuntimeException( "Error: cannot render HTML, template file not found at " . $this->get_template_path() ); |
|
| 110 | + throw new \RuntimeException("Error: cannot render HTML, template file not found at ".$this->get_template_path()); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if( !$echo ) |
|
| 113 | + if (!$echo) |
|
| 114 | 114 | { |
| 115 | 115 | return $rendered_html; |
| 116 | 116 | } |
@@ -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,7 +160,7 @@ 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 | 165 | return $this->components[$name]; |
| 166 | 166 | } |
@@ -182,21 +182,21 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | * @param ValueComponentInterface $component The component to validate. |
| 184 | 184 | */ |
| 185 | - private function update_component( ValueComponentInterface $component ) |
|
| 185 | + private function update_component(ValueComponentInterface $component) |
|
| 186 | 186 | { |
| 187 | 187 | $component->value = $this->final_instance[$component->name]; |
| 188 | 188 | |
| 189 | 189 | // Skip if this field is disabled |
| 190 | - if( $this->is_disabled($component) ) |
|
| 190 | + if ($this->is_disabled($component)) |
|
| 191 | 191 | { |
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Apply user-defined filter |
| 196 | - $this->filter( $component ); |
|
| 196 | + $this->filter($component); |
|
| 197 | 197 | |
| 198 | 198 | // Validate value |
| 199 | - $this->validate( $component ); |
|
| 199 | + $this->validate($component); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param UI\AbstractComponent $component |
| 206 | 206 | * @return boolean |
| 207 | 207 | */ |
| 208 | - private function is_disabled( $component ) |
|
| 208 | + private function is_disabled($component) |
|
| 209 | 209 | { |
| 210 | 210 | return |
| 211 | 211 | $component instanceof DisableableComponentInterface && |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @param UI\AbstractComponent $component |
| 222 | 222 | */ |
| 223 | - private function filter( $component ) |
|
| 223 | + private function filter($component) |
|
| 224 | 224 | { |
| 225 | - if( $component instanceof FilterableComponentInterface ) |
|
| 225 | + if ($component instanceof FilterableComponentInterface) |
|
| 226 | 226 | { |
| 227 | 227 | $filter = $component->filter; |
| 228 | 228 | |
| 229 | - if( is_callable( $filter ) ) |
|
| 229 | + if (is_callable($filter)) |
|
| 230 | 230 | { |
| 231 | 231 | $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name])); |
| 232 | 232 | $this->final_instance[$component->name] = $component->value; |
@@ -242,22 +242,22 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @param UI\AbstractComponent $component The component to validate. |
| 244 | 244 | */ |
| 245 | - private function validate( $component ) |
|
| 245 | + private function validate($component) |
|
| 246 | 246 | { |
| 247 | - if( !($component instanceof ValidatableComponentInterface) ) return; |
|
| 247 | + if (!($component instanceof ValidatableComponentInterface)) return; |
|
| 248 | 248 | |
| 249 | 249 | $name = $component->name; |
| 250 | 250 | $validate = $component->validation; |
| 251 | 251 | |
| 252 | 252 | $component->validity = $component::VALID; |
| 253 | 253 | |
| 254 | - if(is_callable($validate)) |
|
| 254 | + if (is_callable($validate)) |
|
| 255 | 255 | { |
| 256 | 256 | $error = ''; |
| 257 | 257 | $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error)); |
| 258 | 258 | |
| 259 | 259 | // Invalid input, use old instance or default value |
| 260 | - if ( true !== $valid ) |
|
| 260 | + if (true !== $valid) |
|
| 261 | 261 | { |
| 262 | 262 | $this->errors[$name] = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE; |
| 263 | 263 | $component->value = $this->old_instance[$name]; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | { |
| 277 | 277 | $defaults = array(); |
| 278 | 278 | |
| 279 | - foreach( $this->components as $component ) |
|
| 279 | + foreach ($this->components as $component) |
|
| 280 | 280 | { |
| 281 | 281 | $defaults[$component->name] = $component->default; |
| 282 | 282 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | // Prevent direct file access |
| 9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
| 9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Load module functions. If this amarkal module has not been loaded, |
| 13 | 13 | * functions.php will not return false. |
| 14 | 14 | */ |
| 15 | -if(false !== (require_once 'functions.php')) |
|
| 15 | +if (false !== (require_once 'functions.php')) |
|
| 16 | 16 | { |
| 17 | 17 | // Load required classes if not using composer |
| 18 | 18 | require_once 'AbstractComponent.php'; |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | class Component_checkbox |
| 9 | 9 | extends AbstractComponent |
| 10 | 10 | implements ValueComponentInterface, |
| 11 | - DisableableComponentInterface |
|
| 11 | + DisableableComponentInterface |
|
| 12 | 12 | { |
| 13 | 13 | public $name_template = '{{name}}[]'; |
| 14 | 14 | |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | 'required' => false, |
| 26 | 26 | 'readonly' => false, |
| 27 | 27 | 'default' => null, |
| 28 | - 'filter' => array( $this, 'filter' ), |
|
| 29 | - 'validation' => array( $this, 'validation' ) |
|
| 28 | + 'filter' => array($this, 'filter'), |
|
| 29 | + 'validation' => array($this, 'validation') |
|
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,17 +35,17 @@ discard block |
||
| 35 | 35 | return floatval($v); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function validation($v,&$e) |
|
| 38 | + public function validation($v, &$e) |
|
| 39 | 39 | { |
| 40 | 40 | $max = $this->max; |
| 41 | 41 | $min = $this->min; |
| 42 | 42 | |
| 43 | - if(null !== $max && $v > $max) |
|
| 43 | + if (null !== $max && $v > $max) |
|
| 44 | 44 | { |
| 45 | 45 | $e = "must be less than {$max}"; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if(null !== $min && $v < $min) |
|
| 48 | + if (null !== $min && $v < $min) |
|
| 49 | 49 | { |
| 50 | 50 | $e = "must be greater than {$min}"; |
| 51 | 51 | } |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | class Component_number |
| 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 $component_type = 'number'; |
| 16 | 16 | |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | class Component_composite |
| 9 | 9 | extends AbstractComponent |
| 10 | 10 | implements ValueComponentInterface, |
| 11 | - DisableableComponentInterface, |
|
| 12 | - FilterableComponentInterface, |
|
| 13 | - ValidatableComponentInterface |
|
| 11 | + DisableableComponentInterface, |
|
| 12 | + FilterableComponentInterface, |
|
| 13 | + ValidatableComponentInterface |
|
| 14 | 14 | { |
| 15 | 15 | /** |
| 16 | 16 | * The list of child components. |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | * The __set magic method is overridden here to apply value changes to |
| 24 | 24 | * child components. |
| 25 | 25 | */ |
| 26 | - public function __set( $name, $value ) |
|
| 26 | + public function __set($name, $value) |
|
| 27 | 27 | { |
| 28 | 28 | parent::__set($name, $value); |
| 29 | 29 | |
| 30 | - if( 'value' === $name ) |
|
| 30 | + if ('value' === $name) |
|
| 31 | 31 | { |
| 32 | 32 | $this->set_value($value); |
| 33 | 33 | } |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param array $value |
| 40 | 40 | */ |
| 41 | - public function set_value( array $value ) |
|
| 41 | + public function set_value(array $value) |
|
| 42 | 42 | { |
| 43 | - foreach($value as $n => $v) |
|
| 43 | + foreach ($value as $n => $v) |
|
| 44 | 44 | { |
| 45 | 45 | $component = $this->get_component($n); |
| 46 | 46 | $component->value = $v; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function required_arguments() |
| 71 | 71 | { |
| 72 | - return array('name','components','template'); |
|
| 72 | + return array('name', 'components', 'template'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function parse_template() |
| 89 | 89 | { |
| 90 | - return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a){ |
|
| 90 | + return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a) { |
|
| 91 | 91 | $component = $this->get_component($a[1]); |
| 92 | 92 | return $component->render(); |
| 93 | 93 | }, $this->model['template']); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function get_name() |
| 104 | 104 | { |
| 105 | - if('' !== $this->parent_name) |
|
| 105 | + if ('' !== $this->parent_name) |
|
| 106 | 106 | { |
| 107 | 107 | return "{$this->parent_name}[{$this->name}]"; |
| 108 | 108 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function on_created() |
| 116 | 116 | { |
| 117 | - foreach( $this->model['components'] as $args ) |
|
| 117 | + foreach ($this->model['components'] as $args) |
|
| 118 | 118 | { |
| 119 | 119 | $this->components[$args['name']] = $this->create_component($args); |
| 120 | 120 | } |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * @param type $args |
| 126 | 126 | * @return type |
| 127 | 127 | */ |
| 128 | - private function create_component( $args ) |
|
| 128 | + private function create_component($args) |
|
| 129 | 129 | { |
| 130 | 130 | $type = $args['type']; |
| 131 | 131 | |
| 132 | - if('composite' === $type) |
|
| 132 | + if ('composite' === $type) |
|
| 133 | 133 | { |
| 134 | 134 | $args['parent_name'] = $this->get_name(); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $c = \Amarkal\UI\ComponentFactory::create( $type, $args ); |
|
| 137 | + $c = \Amarkal\UI\ComponentFactory::create($type, $args); |
|
| 138 | 138 | |
| 139 | 139 | // Apply the composite name template |
| 140 | 140 | $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template); |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | * @return UI\AbstractComponent |
| 150 | 150 | * @throws \RuntimeException If there's no child component corresponding to the given name |
| 151 | 151 | */ |
| 152 | - private function get_component( $name ) |
|
| 152 | + private function get_component($name) |
|
| 153 | 153 | { |
| 154 | - if(!array_key_exists($name, $this->components)) |
|
| 154 | + if (!array_key_exists($name, $this->components)) |
|
| 155 | 155 | { |
| 156 | 156 | throw new \RuntimeException("Composite sub-component not found with name $name"); |
| 157 | 157 | } |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | class Component_textarea |
| 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 $component_type = 'textarea'; |
| 16 | 16 | |