@@ -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 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param string $name The argument's name. |
| 66 | 66 | * @return boolean Whether this arguments exists or not. |
| 67 | 67 | */ |
| 68 | - public function __isset( $name ) |
|
| 68 | + public function __isset($name) |
|
| 69 | 69 | { |
| 70 | 70 | return isset($this->model[$name]); |
| 71 | 71 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | - public function set_model( $model ) |
|
| 88 | + public function set_model($model) |
|
| 89 | 89 | { |
| 90 | 90 | $this->model = $model; |
| 91 | 91 | } |
@@ -106,22 +106,22 @@ discard block |
||
| 106 | 106 | * @return string The rendered template. |
| 107 | 107 | * @throws TemplateNotFoundException Thrown if the template file cannot be found. |
| 108 | 108 | */ |
| 109 | - public function render( $echo = false ) |
|
| 109 | + public function render($echo = false) |
|
| 110 | 110 | { |
| 111 | 111 | $rendered_html = ''; |
| 112 | 112 | |
| 113 | - if( file_exists( $this->get_template_path() ) ) |
|
| 113 | + if (file_exists($this->get_template_path())) |
|
| 114 | 114 | { |
| 115 | 115 | ob_start(); |
| 116 | - include( $this->get_template_path() ); |
|
| 116 | + include($this->get_template_path()); |
|
| 117 | 117 | $rendered_html = ob_get_clean(); |
| 118 | 118 | } |
| 119 | 119 | else |
| 120 | 120 | { |
| 121 | - throw new \RuntimeException( "Error: cannot render HTML, template file not found at " . $this->get_template_path() ); |
|
| 121 | + throw new \RuntimeException("Error: cannot render HTML, template file not found at ".$this->get_template_path()); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if( !$echo ) |
|
| 124 | + if (!$echo) |
|
| 125 | 125 | { |
| 126 | 126 | return $rendered_html; |
| 127 | 127 | } |
@@ -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 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function required_arguments() |
| 94 | 94 | { |
| 95 | - return array('name','components','template'); |
|
| 95 | + return array('name', 'components', 'template'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function get_name() |
| 128 | 128 | { |
| 129 | - if('' !== $this->parent_name) |
|
| 129 | + if ('' !== $this->parent_name) |
|
| 130 | 130 | { |
| 131 | 131 | return "{$this->parent_name}[{$this->name}]"; |
| 132 | 132 | } |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | public function filter($v) |
| 137 | 137 | { |
| 138 | - foreach($this->components as $component) |
|
| 138 | + foreach ($this->components as $component) |
|
| 139 | 139 | { |
| 140 | - if($component instanceof FilterableComponentInterface && |
|
| 140 | + if ($component instanceof FilterableComponentInterface && |
|
| 141 | 141 | \is_callable($component->filter)) |
| 142 | 142 | { |
| 143 | 143 | $n = $component->name; |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | return $v; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - public function validation($v,&$e) |
|
| 151 | + public function validation($v, &$e) |
|
| 152 | 152 | { |
| 153 | - foreach($this->components as $component) |
|
| 153 | + foreach ($this->components as $component) |
|
| 154 | 154 | { |
| 155 | - if($component instanceof ValidatableComponentInterface && |
|
| 155 | + if ($component instanceof ValidatableComponentInterface && |
|
| 156 | 156 | \is_callable($component->validation)) |
| 157 | 157 | { |
| 158 | 158 | $n = $component->name; |
| 159 | - if(!$component->validation($v[$n],$e)) |
|
| 159 | + if (!$component->validation($v[$n], $e)) |
|
| 160 | 160 | { |
| 161 | 161 | return false; |
| 162 | 162 | } |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * @return UI\AbstractComponent |
| 173 | 173 | * @throws \RuntimeException If there's no child component corresponding to the given name |
| 174 | 174 | */ |
| 175 | - public function get_component( $name ) |
|
| 175 | + public function get_component($name) |
|
| 176 | 176 | { |
| 177 | - if(!array_key_exists($name, $this->components)) |
|
| 177 | + if (!array_key_exists($name, $this->components)) |
|
| 178 | 178 | { |
| 179 | 179 | throw new \RuntimeException("Composite sub-component not found with name $name"); |
| 180 | 180 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function on_created() |
| 188 | 188 | { |
| 189 | - foreach( $this->model['components'] as $args ) |
|
| 189 | + foreach ($this->model['components'] as $args) |
|
| 190 | 190 | { |
| 191 | 191 | $this->components[$args['name']] = $this->create_component($args); |
| 192 | 192 | } |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | * @param type $args |
| 198 | 198 | * @return type |
| 199 | 199 | */ |
| 200 | - private function create_component( $args ) |
|
| 200 | + private function create_component($args) |
|
| 201 | 201 | { |
| 202 | 202 | $type = $args['type']; |
| 203 | 203 | |
| 204 | - if('composite' === $type) |
|
| 204 | + if ('composite' === $type) |
|
| 205 | 205 | { |
| 206 | 206 | $args['parent_name'] = $this->get_name(); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $c = \Amarkal\UI\ComponentFactory::create( $type, $args ); |
|
| 209 | + $c = \Amarkal\UI\ComponentFactory::create($type, $args); |
|
| 210 | 210 | |
| 211 | 211 | // Apply the composite name template |
| 212 | 212 | $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template); |
@@ -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 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $this->component_type |
| 48 | 48 | )); |
| 49 | 49 | |
| 50 | - if($this instanceof DisableableComponentInterface && $this->disabled) |
|
| 50 | + if ($this instanceof DisableableComponentInterface && $this->disabled) |
|
| 51 | 51 | { |
| 52 | 52 | $this->add_html_class('amarkal-ui-disabled'); |
| 53 | 53 | } |
@@ -84,30 +84,30 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return array |
| 86 | 86 | */ |
| 87 | - public function set_model( $model ) |
|
| 87 | + public function set_model($model) |
|
| 88 | 88 | { |
| 89 | 89 | // Check that the required arguments are provided. |
| 90 | - foreach( $this->required_arguments() as $key ) |
|
| 90 | + foreach ($this->required_arguments() as $key) |
|
| 91 | 91 | { |
| 92 | - if ( !isset($model[$key]) ) |
|
| 92 | + if (!isset($model[$key])) |
|
| 93 | 93 | { |
| 94 | 94 | throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class()); |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Assign the name of the component as the id if no id was specified |
| 99 | - if( !isset($model['id']) && isset($model['name']) ) |
|
| 99 | + if (!isset($model['id']) && isset($model['name'])) |
|
| 100 | 100 | { |
| 101 | 101 | $model['id'] = $model['name']; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // A name must be specified when a component has a visibility condition |
| 105 | - if( isset($model['show']) && !isset($model['name']) ) |
|
| 105 | + if (isset($model['show']) && !isset($model['name'])) |
|
| 106 | 106 | { |
| 107 | 107 | throw new \RuntimeException('Components with a visibility condition (a "show" argument) must have a name'); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $this->model = array_merge( $this->default_model(), $model ); |
|
| 110 | + $this->model = array_merge($this->default_model(), $model); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @param string $class |
| 128 | 128 | */ |
| 129 | - public function add_html_class( $class ) |
|
| 129 | + public function add_html_class($class) |
|
| 130 | 130 | { |
| 131 | - if( !in_array($class, $this->html_classes) ) |
|
| 131 | + if (!in_array($class, $this->html_classes)) |
|
| 132 | 132 | { |
| 133 | 133 | $this->html_classes[] = $class; |
| 134 | 134 | } |
@@ -140,14 +140,14 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @param string $class |
| 142 | 142 | */ |
| 143 | - public function remove_html_class( $class ) |
|
| 143 | + public function remove_html_class($class) |
|
| 144 | 144 | { |
| 145 | 145 | $i = 0; |
| 146 | - foreach( $this->html_classes as $c ) |
|
| 146 | + foreach ($this->html_classes as $c) |
|
| 147 | 147 | { |
| 148 | - if( $c === $class ) |
|
| 148 | + if ($c === $class) |
|
| 149 | 149 | { |
| 150 | - array_splice($this->html_classes,$i,1); |
|
| 150 | + array_splice($this->html_classes, $i, 1); |
|
| 151 | 151 | break; |
| 152 | 152 | } |
| 153 | 153 | $i++; |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @param type $validity |
| 161 | 161 | */ |
| 162 | - Public function set_validity( $validity ) |
|
| 162 | + Public function set_validity($validity) |
|
| 163 | 163 | { |
| 164 | 164 | $this->validity = $validity; |
| 165 | - if($validity === $this::INVALID) |
|
| 165 | + if ($validity === $this::INVALID) |
|
| 166 | 166 | { |
| 167 | 167 | $this->add_html_class('amarkal-ui-component-error'); |
| 168 | 168 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * {@inheritdoc} |
| 187 | 187 | */ |
| 188 | - public function render( $echo = false ) |
|
| 188 | + public function render($echo = false) |
|
| 189 | 189 | { |
| 190 | 190 | $this->enqueue_scripts(); |
| 191 | 191 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | include dirname(__FILE__).'/AbstractComponent.phtml'; |
| 194 | 194 | $html = ob_get_clean(); |
| 195 | 195 | |
| 196 | - if( !$echo ) |
|
| 196 | + if (!$echo) |
|
| 197 | 197 | { |
| 198 | 198 | return $html; |
| 199 | 199 | } |
@@ -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 | 'show' => null |
| 26 | 26 | ); |
| 27 | 27 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function filter($v) |
| 49 | 49 | { |
| 50 | - if($v !== 'on') return 'off'; |
|
| 50 | + if ($v !== 'on') return 'off'; |
|
| 51 | 51 | return 'on'; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | protected function on_created() |
| 17 | 17 | { |
| 18 | - if($this->multi && !\is_array($this->default) |
|
| 18 | + if ($this->multi && !\is_array($this->default) |
|
| 19 | 19 | || !$this->multi && \is_array($this->default)) |
| 20 | 20 | { |
| 21 | 21 | throw new \RuntimeException("The default value must be an array if multi is set to true, and must be a string otherwise."); |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | 'multi' => false, |
| 34 | 34 | 'data' => array(), |
| 35 | 35 | 'default' => array(), |
| 36 | - 'filter' => array( $this, 'filter' ), |
|
| 36 | + 'filter' => array($this, 'filter'), |
|
| 37 | 37 | 'show' => null |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function required_arguments() |
| 42 | 42 | { |
| 43 | - return array('name','data'); |
|
| 43 | + return array('name', 'data'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function get_template_path() |
@@ -59,16 +59,16 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function filter($v) |
| 61 | 61 | { |
| 62 | - if($this->multi && !\is_array($v)) |
|
| 62 | + if ($this->multi && !\is_array($v)) |
|
| 63 | 63 | { |
| 64 | 64 | return \explode(',', $v); |
| 65 | 65 | } |
| 66 | 66 | return $v; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - protected function is_selected( $value ) |
|
| 69 | + protected function is_selected($value) |
|
| 70 | 70 | { |
| 71 | - if($this->multi) |
|
| 71 | + if ($this->multi) |
|
| 72 | 72 | { |
| 73 | 73 | return \in_array($value, $this->value); |
| 74 | 74 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | 'min' => null, |
| 26 | 26 | 'max' => null, |
| 27 | 27 | 'step' => 1, |
| 28 | - 'filter' => array( $this, 'filter' ), |
|
| 28 | + 'filter' => array($this, 'filter'), |
|
| 29 | 29 | 'show' => null |
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function required_arguments() |
| 34 | 34 | { |
| 35 | - return array('name','min','max'); |
|
| 35 | + return array('name', 'min', 'max'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function get_template_path() |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | 'required' => false, |
| 28 | 28 | 'readonly' => false, |
| 29 | 29 | 'default' => null, |
| 30 | - 'filter' => array( $this, 'filter' ), |
|
| 31 | - 'validation' => array( $this, 'validation' ), |
|
| 30 | + 'filter' => array($this, 'filter'), |
|
| 31 | + 'validation' => array($this, 'validation'), |
|
| 32 | 32 | 'show' => null |
| 33 | 33 | ); |
| 34 | 34 | } |
@@ -38,19 +38,19 @@ discard block |
||
| 38 | 38 | return floatval($v); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function validation($v,&$e) |
|
| 41 | + public function validation($v, &$e) |
|
| 42 | 42 | { |
| 43 | 43 | $max = $this->max; |
| 44 | 44 | $min = $this->min; |
| 45 | 45 | |
| 46 | - if(null !== $max && $v > $max) |
|
| 46 | + if (null !== $max && $v > $max) |
|
| 47 | 47 | { |
| 48 | - $e = sprintf( __("Value must be less than %d",'amarkal'), $max); |
|
| 48 | + $e = sprintf(__("Value must be less than %d", 'amarkal'), $max); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if(null !== $min && $v < $min) |
|
| 51 | + if (null !== $min && $v < $min) |
|
| 52 | 52 | { |
| 53 | - $e = sprintf( __("Value must be greater than %d",'amarkal'), $min); |
|
| 53 | + $e = sprintf(__("Value must be greater than %d", 'amarkal'), $min); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $e ? false : true; |