Passed
Push — master ( ff41db...906736 )
by Jean-Christophe
02:27
created
Ajax/common/html/BaseHtml.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
  * @version 1.3.3
16 16
  */
17 17
 abstract class BaseHtml extends BaseWidget {
18
-	use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait;
18
+	use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait;
19 19
 
20 20
 	protected $_template;
21 21
 
22 22
 	protected $tagName;
23 23
 
24
-	protected $_wrapBefore = array();
24
+	protected $_wrapBefore=array();
25 25
 
26
-	protected $_wrapAfter = array();
26
+	protected $_wrapAfter=array();
27 27
 
28 28
 	protected $_bsComponent;
29 29
 
30
-	protected $_compiled = false;
30
+	protected $_compiled=false;
31 31
 
32
-	protected $_runned = false;
32
+	protected $_runned=false;
33 33
 
34 34
 	protected $_postCompile;
35 35
 
@@ -43,31 +43,31 @@  discard block
 block discarded – undo
43 43
 	abstract public function run(JsUtils $js);
44 44
 
45 45
 	private function _callSetter($setter, $key, $value, &$array) {
46
-		$result = false;
47
-		if (method_exists($this, $setter) && substr($setter, 0, 1) !== "_") {
46
+		$result=false;
47
+		if (method_exists($this, $setter) && substr($setter, 0, 1)!=="_") {
48 48
 			try {
49 49
 				$this->$setter($value);
50 50
 				unset($array[$key]);
51
-				$result = true;
52
-			} catch (\Exception $e) {
53
-				$result = false;
51
+				$result=true;
52
+			}catch (\Exception $e) {
53
+				$result=false;
54 54
 			}
55 55
 		}
56 56
 		return $result;
57 57
 	}
58 58
 
59
-	protected function getTemplate(JsUtils $js = NULL, $view = null) {
60
-		return PropertyWrapper::wrap($this->_wrapBefore, $js, $view) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js, $view);
59
+	protected function getTemplate(JsUtils $js=NULL, $view=null) {
60
+		return PropertyWrapper::wrap($this->_wrapBefore, $js, $view).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js, $view);
61 61
 	}
62 62
 
63 63
 	protected function ctrl($name, $value, $typeCtrl) {
64 64
 		if (\is_array($typeCtrl)) {
65
-			if (array_search($value, $typeCtrl) === false) {
66
-				throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}");
65
+			if (array_search($value, $typeCtrl)===false) {
66
+				throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}");
67 67
 			}
68 68
 		} else {
69
-			if (! $typeCtrl($value)) {
70
-				throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name);
69
+			if (!$typeCtrl($value)) {
70
+				throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name);
71 71
 			}
72 72
 		}
73 73
 		return true;
@@ -75,49 +75,49 @@  discard block
 block discarded – undo
75 75
 
76 76
 	protected function setMemberCtrl(&$name, $value, $typeCtrl) {
77 77
 		$this->ctrl($name, $value, $typeCtrl);
78
-		$name = $value;
78
+		$name=$value;
79 79
 		return $this;
80 80
 	}
81 81
 
82
-	protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator = " ") {
82
+	protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") {
83 83
 		if (\is_array($typeCtrl)) {
84 84
 			$this->removeOldValues($name, $typeCtrl);
85
-			$name .= $separator . $value;
85
+			$name.=$separator.$value;
86 86
 		}
87 87
 		return $this;
88 88
 	}
89 89
 
90
-	protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator = " ") {
90
+	protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") {
91 91
 		$this->ctrl($name, $value, $typeCtrl);
92 92
 		if (\is_array($typeCtrl)) {
93 93
 			$this->removeOldValues($name, $typeCtrl);
94 94
 		}
95
-		$name .= $separator . $value;
95
+		$name.=$separator.$value;
96 96
 		return $this;
97 97
 	}
98 98
 
99
-	protected function addToMember(&$name, $value, $separator = ' ') {
100
-		$name = \str_ireplace($value, '', $name??'') . $separator . $value;
99
+	protected function addToMember(&$name, $value, $separator=' ') {
100
+		$name=\str_ireplace($value, '', $name ?? '').$separator.$value;
101 101
 		return $this;
102 102
 	}
103 103
 
104 104
 	protected function removeOldValues(&$oldValue, $allValues) {
105
-		$oldValue = \str_ireplace($allValues, '', $oldValue??'');
106
-		$oldValue = \trim($oldValue);
105
+		$oldValue=\str_ireplace($allValues, '', $oldValue ?? '');
106
+		$oldValue=\trim($oldValue);
107 107
 	}
108 108
 
109 109
 	protected function _getElementBy($callback, $elements) {
110 110
 		if (\is_array($elements)) {
111
-			$elements = \array_values($elements);
112
-			$flag = false;
113
-			$index = 0;
114
-			while (! $flag && $index < sizeof($elements)) {
111
+			$elements=\array_values($elements);
112
+			$flag=false;
113
+			$index=0;
114
+			while (!$flag && $index<sizeof($elements)) {
115 115
 				if ($elements[$index] instanceof BaseHtml)
116
-					$flag = ($callback($elements[$index]));
117
-				$index ++;
116
+					$flag=($callback($elements[$index]));
117
+				$index++;
118 118
 			}
119
-			if ($flag === true)
120
-				return $elements[$index - 1];
119
+			if ($flag===true)
120
+				return $elements[$index-1];
121 121
 		} elseif ($elements instanceof BaseHtml) {
122 122
 			if ($callback($elements))
123 123
 				return $elements;
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 	}
127 127
 
128 128
 	protected function setWrapBefore($wrapBefore) {
129
-		$this->_wrapBefore = $wrapBefore;
129
+		$this->_wrapBefore=$wrapBefore;
130 130
 		return $this;
131 131
 	}
132 132
 
133 133
 	protected function setWrapAfter($wrapAfter) {
134
-		$this->_wrapAfter = $wrapAfter;
134
+		$this->_wrapAfter=$wrapAfter;
135 135
 		return $this;
136 136
 	}
137 137
 
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
 	}
141 141
 
142 142
 	public function setTagName($tagName) {
143
-		$this->tagName = $tagName;
143
+		$this->tagName=$tagName;
144 144
 		return $this;
145 145
 	}
146 146
 
147 147
 	public function fromArray($array) {
148 148
 		foreach ($this as $key => $value) {
149
-			if (array_key_exists($key, $array) === true)
150
-				$this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array);
149
+			if (array_key_exists($key, $array)===true)
150
+				$this->_callSetter("set".ucfirst($key), $key, $array[$key], $array);
151 151
 		}
152 152
 		foreach ($array as $key => $value) {
153
-			if ($this->_callSetter($key, $key, $value, $array) === false) {
154
-				$this->_callSetter("set" . ucfirst($key), $key, $value, $array);
153
+			if ($this->_callSetter($key, $key, $value, $array)===false) {
154
+				$this->_callSetter("set".ucfirst($key), $key, $value, $array);
155 155
 			}
156 156
 		}
157 157
 		return $array;
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
 
169 169
 	public function fromDatabaseObject($object, $function) {}
170 170
 
171
-	public function wrap($before, $after = "") {
171
+	public function wrap($before, $after="") {
172 172
 		if (isset($before)) {
173 173
 			array_unshift($this->_wrapBefore, $before);
174 174
 		}
175
-		$this->_wrapAfter[] = $after;
175
+		$this->_wrapAfter[]=$after;
176 176
 		return $this;
177 177
 	}
178 178
 
179 179
 	public function getElementById($identifier, $elements) {
180
-		return $this->_getElementBy(function (BaseWidget $element) use ($identifier) {
181
-			return $element->getIdentifier() === $identifier;
180
+		return $this->_getElementBy(function(BaseWidget $element) use ($identifier) {
181
+			return $element->getIdentifier()===$identifier;
182 182
 		}, $elements);
183 183
 	}
184 184
 
@@ -187,50 +187,50 @@  discard block
 block discarded – undo
187 187
 	}
188 188
 
189 189
 	public function setBsComponent($bsComponent) {
190
-		$this->_bsComponent = $bsComponent;
190
+		$this->_bsComponent=$bsComponent;
191 191
 		return $this;
192 192
 	}
193 193
 
194
-	protected function compile_once(JsUtils $js = NULL, &$view = NULL) {
195
-		if (! $this->_compiled) {
194
+	protected function compile_once(JsUtils $js=NULL, &$view=NULL) {
195
+		if (!$this->_compiled) {
196 196
 			if (isset($js)) {
197
-				$beforeCompile = $js->getParam("beforeCompileHtml");
197
+				$beforeCompile=$js->getParam("beforeCompileHtml");
198 198
 				if (\is_callable($beforeCompile)) {
199 199
 					$beforeCompile($this, $js, $view);
200 200
 				}
201 201
 			}
202 202
 			$this->callCallback($this->_preCompile);
203 203
 			unset($this->properties["jsCallback"]);
204
-			$this->_compiled = true;
204
+			$this->_compiled=true;
205 205
 		}
206 206
 	}
207 207
 
208
-	public function compile(JsUtils $js = NULL, &$view = NULL) {
208
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
209 209
 		$this->compile_once($js, $view);
210
-		$result = $this->getTemplate($js, $view);
210
+		$result=$this->getTemplate($js, $view);
211 211
 		foreach ($this as $key => $value) {
212
-			if (\strstr($result, "%{$key}%") !== false) {
212
+			if (\strstr($result, "%{$key}%")!==false) {
213 213
 				if (\is_array($value)) {
214
-					$v = PropertyWrapper::wrap($value, $js, $view);
214
+					$v=PropertyWrapper::wrap($value, $js, $view);
215 215
 				} elseif ($value instanceof \stdClass) {
216
-					$v = \print_r($value, true);
216
+					$v=\print_r($value, true);
217 217
 				} elseif ($value instanceof BaseHtml) {
218
-					$v = $value->compile($js, $view);
218
+					$v=$value->compile($js, $view);
219 219
 				} else {
220
-					$v = $value;
220
+					$v=$value;
221 221
 				}
222
-				$result = \str_replace("%{$key}%", $v ?? '', $result);
222
+				$result=\str_replace("%{$key}%", $v ?? '', $result);
223 223
 			}
224 224
 		}
225
-		if (isset($js) === true) {
225
+		if (isset($js)===true) {
226 226
 			$this->run($js);
227
-			if (isset($view) === true) {
227
+			if (isset($view)===true) {
228 228
 				$js->addViewElement($this->getLibraryId(), $result, $view);
229 229
 			}
230 230
 		}
231 231
 
232 232
 		if (\is_callable($this->_postCompile)) {
233
-			$pc = $this->_postCompile;
233
+			$pc=$this->_postCompile;
234 234
 			$pc($this);
235 235
 		}
236 236
 		return $result;
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
 	 *        	default: ["jsCallback"=>"","jqueryDone"=>"append"]
248 248
 	 * @return \Ajax\common\html\BaseHtml
249 249
 	 */
250
-	public function setDraggable($attr = "id", $dropZone = null, $parameters = []) {
250
+	public function setDraggable($attr="id", $dropZone=null, $parameters=[]) {
251 251
 		$this->setProperty("draggable", "true");
252 252
 		$this->addEvent("dragstart", Javascript::draggable($attr));
253 253
 		if (isset($dropZone) && $dropZone instanceof BaseHtml) {
254
-			$jqueryDone = "append";
255
-			$jsCallback = "";
254
+			$jqueryDone="append";
255
+			$jsCallback="";
256 256
 			extract($parameters);
257 257
 			$dropZone->asDropZone($jsCallback, $jqueryDone, $parameters);
258 258
 		}
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 	 * @param array $parameters
268 268
 	 * @return \Ajax\common\html\BaseHtml
269 269
 	 */
270
-	public function asDropZone($jsCallback = "", $jqueryDone = "append", $parameters = []) {
271
-		$stopPropagation = false;
270
+	public function asDropZone($jsCallback="", $jqueryDone="append", $parameters=[]) {
271
+		$stopPropagation=false;
272 272
 		$this->addEvent("dragover", '', $stopPropagation, true);
273 273
 		extract($parameters);
274 274
 		$this->addEvent("drop", Javascript::dropZone($jqueryDone, $jsCallback), $stopPropagation, true);
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 * @param array $parameters
286 286
 	 * @return \Ajax\common\html\BaseHtml
287 287
 	 */
288
-	public function asFileDropZone($responseElement = null, $url = null, $progress = null, $jsCallback = "", $parameters = []) {
289
-		$stopPropagation = false;
290
-		$defaultAjaxAttributes = [
288
+	public function asFileDropZone($responseElement=null, $url=null, $progress=null, $jsCallback="", $parameters=[]) {
289
+		$stopPropagation=false;
290
+		$defaultAjaxAttributes=[
291 291
 			'contentType' => 'false',
292 292
 			'processData' => 'false'
293 293
 		];
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 		extract($parameters);
296 296
 		$this->addEvent("drop", Javascript::fileDropZone($jsCallback), $stopPropagation, true);
297 297
 		if (isset($ajaxAttributes)) {
298
-			$ajaxAttributes += $defaultAjaxAttributes;
298
+			$ajaxAttributes+=$defaultAjaxAttributes;
299 299
 		} else {
300
-			$ajaxAttributes = $defaultAjaxAttributes;
300
+			$ajaxAttributes=$defaultAjaxAttributes;
301 301
 		}
302 302
 		if (isset($progress)) {
303
-			$progress = new HtmlProgress($this->_identifier . '-pg', 0, $progress);
303
+			$progress=new HtmlProgress($this->_identifier.'-pg', 0, $progress);
304 304
 			$progress->setTotal(100);
305 305
 			$this->wrap('', $progress);
306
-			$ajaxAttributes['upload'] = "$('#" . $this->_identifier . "-pg').progress('set percent', Math.ceil(event.loaded/event.total)*100);";
306
+			$ajaxAttributes['upload']="$('#".$this->_identifier."-pg').progress('set percent', Math.ceil(event.loaded/event.total)*100);";
307 307
 		}
308 308
 		if (isset($url)) {
309 309
 			$this->postOn('upload', $url, 'event.target.upload', $responseElement, $ajaxAttributes);
@@ -316,21 +316,21 @@  discard block
 block discarded – undo
316 316
 	}
317 317
 
318 318
 	public function onPostCompile($callback) {
319
-		$this->_postCompile = $callback;
319
+		$this->_postCompile=$callback;
320 320
 	}
321 321
 
322 322
 	public function onPreCompile($callback) {
323
-		$this->_preCompile = $this->addCallback($this->_preCompile, $callback);
323
+		$this->_preCompile=$this->addCallback($this->_preCompile, $callback);
324 324
 	}
325 325
 
326 326
 	private function addCallback($originalValue, $callback) {
327 327
 		if (isset($originalValue)) {
328
-			if (! is_array($originalValue)) {
329
-				$result = [
328
+			if (!is_array($originalValue)) {
329
+				$result=[
330 330
 					$originalValue
331 331
 				];
332 332
 			}
333
-			$result[] = $callback;
333
+			$result[]=$callback;
334 334
 			return $result;
335 335
 		}
336 336
 		return $callback;
Please login to merge, or discard this patch.