@@ -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 | } |
@@ -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,13 +47,13 @@ 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 | |
56 | -if(!function_exists('amarkal_ui_register_scripts')) |
|
56 | +if (!function_exists('amarkal_ui_register_scripts')) |
|
57 | 57 | { |
58 | 58 | /** |
59 | 59 | * Register Amarkal UI styles & scripts. These scripts are later enqueued by |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | */ |
62 | 62 | function amarkal_ui_register_scripts() |
63 | 63 | { |
64 | - \wp_register_script('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-ui.min.js'),array('jquery'),false,true); |
|
65 | - \wp_register_script('ace-editor','https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.8/ace.js',array('jquery'),false,true); |
|
66 | - \wp_register_style('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-ui.min.css'),array()); |
|
64 | + \wp_register_script('amarkal-ui', Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-ui.min.js'), array('jquery'), false, true); |
|
65 | + \wp_register_script('ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.8/ace.js', array('jquery'), false, true); |
|
66 | + \wp_register_style('amarkal-ui', Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-ui.min.css'), array()); |
|
67 | 67 | } |
68 | - \add_action('admin_init','amarkal_ui_register_scripts'); |
|
68 | + \add_action('admin_init', 'amarkal_ui_register_scripts'); |
|
69 | 69 | } |
70 | 70 | \ No newline at end of file |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | public function required_arguments() |
34 | 34 | { |
35 | - return array('name','language'); |
|
35 | + return array('name', 'language'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function get_template_path() |