@@ -81,29 +81,29 @@ discard block |
||
81 | 81 | public function __construct(array $aOptions, array $aAnnotations) |
82 | 82 | { |
83 | 83 | [$bExcluded, $aAnnotationOptions, $aAnnotationProtected] = $aAnnotations; |
84 | - $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
85 | - if($this->bExcluded) |
|
84 | + $this->bExcluded = $bExcluded || (bool) ($aOptions['excluded'] ?? false); |
|
85 | + if ($this->bExcluded) |
|
86 | 86 | { |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $sSeparator = $aOptions['separator']; |
91 | - if($sSeparator === '_' || $sSeparator === '.') |
|
91 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
92 | 92 | { |
93 | 93 | $this->sSeparator = $sSeparator; |
94 | 94 | } |
95 | 95 | $this->addProtectedMethods($aOptions['protected']); |
96 | 96 | $this->addProtectedMethods($aAnnotationProtected); |
97 | 97 | |
98 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
98 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
99 | 99 | { |
100 | 100 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
101 | - foreach($aFunctionNames as $sFunctionName) |
|
101 | + foreach ($aFunctionNames as $sFunctionName) |
|
102 | 102 | { |
103 | 103 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
104 | 104 | } |
105 | 105 | } |
106 | - foreach($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
106 | + foreach ($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
107 | 107 | { |
108 | 108 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
109 | 109 | } |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function addProtectedMethods($xMethods) |
118 | 118 | { |
119 | - if(!is_array($xMethods)) |
|
119 | + if (!is_array($xMethods)) |
|
120 | 120 | { |
121 | - $this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
121 | + $this->aProtectedMethods[trim((string) $xMethods)] = true; |
|
122 | 122 | return; |
123 | 123 | } |
124 | - foreach($xMethods as $sMethod) |
|
124 | + foreach ($xMethods as $sMethod) |
|
125 | 125 | { |
126 | - $this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
126 | + $this->aProtectedMethods[trim((string) $sMethod)] = true; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | */ |
198 | 198 | private function setHookMethods(array &$aHookMethods, $xValue) |
199 | 199 | { |
200 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
200 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
201 | 201 | { |
202 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
202 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
203 | 203 | { |
204 | 204 | $aHookMethods[$sCalledMethod] = []; |
205 | 205 | } |
206 | - if(is_array($xMethodToCall)) |
|
206 | + if (is_array($xMethodToCall)) |
|
207 | 207 | { |
208 | 208 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
209 | 209 | } |
210 | - elseif(is_string($xMethodToCall)) |
|
210 | + elseif (is_string($xMethodToCall)) |
|
211 | 211 | { |
212 | 212 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
213 | 213 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | private function addOption(string $sName, $xValue) |
234 | 234 | { |
235 | - switch($sName) |
|
235 | + switch ($sName) |
|
236 | 236 | { |
237 | 237 | // Set the methods to call before processing the request |
238 | 238 | case '__before': |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | */ |
261 | 261 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
262 | 262 | { |
263 | - if(is_string($xOptionValue)) |
|
263 | + if (is_string($xOptionValue)) |
|
264 | 264 | { |
265 | 265 | $xOptionValue = [$xOptionValue]; |
266 | 266 | } |
267 | - if(!is_array($xOptionValue)) |
|
267 | + if (!is_array($xOptionValue)) |
|
268 | 268 | { |
269 | 269 | return; // Do not save. |
270 | 270 | } |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | */ |
294 | 294 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
295 | 295 | { |
296 | - switch($sOptionName) |
|
296 | + switch ($sOptionName) |
|
297 | 297 | { |
298 | 298 | case 'excluded': |
299 | - if((bool)$xOptionValue) |
|
299 | + if ((bool) $xOptionValue) |
|
300 | 300 | { |
301 | 301 | $this->addProtectedMethods($sFunctionName); |
302 | 302 | } |
@@ -320,12 +320,11 @@ discard block |
||
320 | 320 | */ |
321 | 321 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions) |
322 | 322 | { |
323 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
323 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
324 | 324 | { |
325 | 325 | substr($sOptionName, 0, 2) === '__' ? |
326 | 326 | // Options for PHP classes. They start with "__". |
327 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
328 | - // Options for javascript code. |
|
327 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
329 | 328 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
330 | 329 | } |
331 | 330 | } |
@@ -341,12 +340,11 @@ discard block |
||
341 | 340 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
342 | 341 | // Then add the method options. |
343 | 342 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
344 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
343 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
345 | 344 | { |
346 | 345 | // For databags, merge the values in a single array. |
347 | 346 | // For all the other options, including callback, keep the last value. |
348 | - $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : |
|
349 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
347 | + $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
350 | 348 | } |
351 | 349 | return $aOptions; |
352 | 350 | } |
@@ -206,8 +206,7 @@ |
||
206 | 206 | if(is_array($xMethodToCall)) |
207 | 207 | { |
208 | 208 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
209 | - } |
|
210 | - elseif(is_string($xMethodToCall)) |
|
209 | + } elseif(is_string($xMethodToCall)) |
|
211 | 210 | { |
212 | 211 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
213 | 212 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getOutput(): string |
84 | 84 | { |
85 | - if($this->getCommandCount() === 0) |
|
85 | + if ($this->getCommandCount() === 0) |
|
86 | 86 | { |
87 | 87 | return '{}'; |
88 | 88 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public function toPsr(): PsrResponseInterface |
153 | 153 | { |
154 | 154 | $xPsrResponse = $this->xPsr17Factory->createResponse(200); |
155 | - if($this->xRequest->getMethod() === 'GET') |
|
155 | + if ($this->xRequest->getMethod() === 'GET') |
|
156 | 156 | { |
157 | 157 | $xPsrResponse = $xPsrResponse |
158 | 158 | ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | public function appendCommands(array $aCommands, bool $bBefore = false) |
64 | 64 | { |
65 | 65 | $this->aCommands = ($bBefore) ? |
66 | - array_merge($aCommands, $this->aCommands) : |
|
67 | - array_merge($this->aCommands, $aCommands); |
|
66 | + array_merge($aCommands, $this->aCommands) : array_merge($this->aCommands, $aCommands); |
|
68 | 67 | } |
69 | 68 | |
70 | 69 | /** |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | public function addCommand(array $aAttributes, $mData): ResponseInterface |
108 | 107 | { |
109 | 108 | $aAttributes = array_map(function($xAttribute) { |
110 | - return is_integer($xAttribute) ? $xAttribute : trim((string)$xAttribute, " \t"); |
|
109 | + return is_integer($xAttribute) ? $xAttribute : trim((string) $xAttribute, " \t"); |
|
111 | 110 | }, $aAttributes); |
112 | 111 | return $this->addRawCommand($aAttributes, $mData); |
113 | 112 | } |
@@ -126,9 +125,9 @@ discard block |
||
126 | 125 | $mData, bool $bRemoveEmpty = false): ResponseInterface |
127 | 126 | { |
128 | 127 | $mData = is_array($mData) ? array_map(function($sData) { |
129 | - return trim((string)$sData, " \t\n"); |
|
130 | - }, $mData) : trim((string)$mData, " \t\n"); |
|
131 | - if($bRemoveEmpty) |
|
128 | + return trim((string) $sData, " \t\n"); |
|
129 | + }, $mData) : trim((string) $mData, " \t\n"); |
|
130 | + if ($bRemoveEmpty) |
|
132 | 131 | { |
133 | 132 | $aAttributes = array_filter($aAttributes, function($xValue) { |
134 | 133 | return $xValue === ''; |
@@ -124,17 +124,17 @@ |
||
124 | 124 | public function render(Call $xCall, Paginator $xPaginator, string $sWrapperId = '') |
125 | 125 | { |
126 | 126 | $aPages = $xPaginator->pages(); |
127 | - if(count($aPages) === 0) |
|
127 | + if (count($aPages) === 0) |
|
128 | 128 | { |
129 | 129 | return; |
130 | 130 | } |
131 | - if(!($xStore = $this->_render($aPages))) |
|
131 | + if (!($xStore = $this->_render($aPages))) |
|
132 | 132 | { |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Append the page number to the parameter list, if not yet given. |
137 | - if(!$xCall->hasPageNumber()) |
|
137 | + if (!$xCall->hasPageNumber()) |
|
138 | 138 | { |
139 | 139 | $xCall->addParameter(Parameter::PAGE_NUMBER, 0); |
140 | 140 | } |
@@ -166,29 +166,29 @@ |
||
166 | 166 | { |
167 | 167 | switch($this->getType()) |
168 | 168 | { |
169 | - case self::JS_CALL: |
|
170 | - return $this->getValue()->toArray(); |
|
171 | - case self::JS_VALUE: |
|
172 | - return [ |
|
173 | - '_type' => 'expr', |
|
174 | - 'calls' => [['_type' => 'attr', '_name' => $this->getValue()]], |
|
175 | - ]; |
|
176 | - case self::FORM_VALUES: |
|
177 | - return ['_type' => 'form', '_name' => $this->getValue()]; |
|
178 | - case self::INPUT_VALUE: |
|
179 | - return ['_type' => 'input', '_name' => $this->getValue()]; |
|
180 | - case self::CHECKED_VALUE: |
|
181 | - return ['_type' => 'checked', '_name' => $this->getValue()]; |
|
182 | - case self::ELEMENT_INNERHTML: |
|
183 | - return ['_type' => 'html', '_name' => $this->getValue()]; |
|
184 | - case self::QUOTED_VALUE: |
|
185 | - case self::BOOL_VALUE: |
|
186 | - case self::NUMERIC_VALUE: |
|
187 | - case self::JSON_VALUE: |
|
188 | - case self::PAGE_NUMBER: |
|
189 | - default: |
|
190 | - // Return the value as is. |
|
191 | - return $this->getValue(); |
|
169 | + case self::JS_CALL: |
|
170 | + return $this->getValue()->toArray(); |
|
171 | + case self::JS_VALUE: |
|
172 | + return [ |
|
173 | + '_type' => 'expr', |
|
174 | + 'calls' => [['_type' => 'attr', '_name' => $this->getValue()]], |
|
175 | + ]; |
|
176 | + case self::FORM_VALUES: |
|
177 | + return ['_type' => 'form', '_name' => $this->getValue()]; |
|
178 | + case self::INPUT_VALUE: |
|
179 | + return ['_type' => 'input', '_name' => $this->getValue()]; |
|
180 | + case self::CHECKED_VALUE: |
|
181 | + return ['_type' => 'checked', '_name' => $this->getValue()]; |
|
182 | + case self::ELEMENT_INNERHTML: |
|
183 | + return ['_type' => 'html', '_name' => $this->getValue()]; |
|
184 | + case self::QUOTED_VALUE: |
|
185 | + case self::BOOL_VALUE: |
|
186 | + case self::NUMERIC_VALUE: |
|
187 | + case self::JSON_VALUE: |
|
188 | + case self::PAGE_NUMBER: |
|
189 | + default: |
|
190 | + // Return the value as is. |
|
191 | + return $this->getValue(); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -131,23 +131,23 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public static function make($xValue): ParameterInterface |
133 | 133 | { |
134 | - if($xValue instanceof ParameterInterface) |
|
134 | + if ($xValue instanceof ParameterInterface) |
|
135 | 135 | { |
136 | 136 | return $xValue; |
137 | 137 | } |
138 | - if(is_numeric($xValue)) |
|
138 | + if (is_numeric($xValue)) |
|
139 | 139 | { |
140 | 140 | return new Parameter(self::NUMERIC_VALUE, $xValue); |
141 | 141 | } |
142 | - if(is_string($xValue)) |
|
142 | + if (is_string($xValue)) |
|
143 | 143 | { |
144 | 144 | return new Parameter(self::QUOTED_VALUE, $xValue); |
145 | 145 | } |
146 | - if(is_bool($xValue)) |
|
146 | + if (is_bool($xValue)) |
|
147 | 147 | { |
148 | 148 | return new Parameter(self::BOOL_VALUE, $xValue); |
149 | 149 | } |
150 | - if($xValue instanceof JsCall) |
|
150 | + if ($xValue instanceof JsCall) |
|
151 | 151 | { |
152 | 152 | return new Parameter(self::JS_CALL, $xValue); |
153 | 153 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function forArray() |
166 | 166 | { |
167 | - switch($this->getType()) |
|
167 | + switch ($this->getType()) |
|
168 | 168 | { |
169 | 169 | case self::JS_CALL: |
170 | 170 | return $this->getValue()->toArray(); |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | public function toArray(): array |
318 | 318 | { |
319 | 319 | $aCall = parent::toArray(); |
320 | - if($this->bConfirm) |
|
320 | + if ($this->bConfirm) |
|
321 | 321 | { |
322 | 322 | $aCall['confirm'] = $this->aConfirmArgs; |
323 | 323 | } |
324 | - if(($this->aCondition)) |
|
324 | + if (($this->aCondition)) |
|
325 | 325 | { |
326 | 326 | $aCall['condition'] = $this->aCondition; |
327 | - if(($this->aMessageArgs)) |
|
327 | + if (($this->aMessageArgs)) |
|
328 | 328 | { |
329 | 329 | $aCall['else'] = $this->getMessage(); |
330 | 330 | } |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | */ |
340 | 340 | private function findPageNumber(): ?ParameterInterface |
341 | 341 | { |
342 | - foreach($this->aParameters as $xParameter) |
|
342 | + foreach ($this->aParameters as $xParameter) |
|
343 | 343 | { |
344 | - if($xParameter->getType() === Parameter::PAGE_NUMBER) |
|
344 | + if ($xParameter->getType() === Parameter::PAGE_NUMBER) |
|
345 | 345 | { |
346 | 346 | return $xParameter; |
347 | 347 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | { |
371 | 371 | /** @var Parameter */ |
372 | 372 | $xParameter = $this->findPageNumber(); |
373 | - if($xParameter !== null) |
|
373 | + if ($xParameter !== null) |
|
374 | 374 | { |
375 | 375 | $xParameter->setValue($nPageNumber); |
376 | 376 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function addParameters(array $aParameters): JsCall |
125 | 125 | { |
126 | - foreach($aParameters as $xParameter) |
|
126 | + foreach ($aParameters as $xParameter) |
|
127 | 127 | { |
128 | 128 | $this->pushParameter(Parameter::make($xParameter)); |
129 | 129 | } |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | return $xParam->forArray(); |
145 | 145 | }, $this->aParameters), |
146 | 146 | ]]; |
147 | - if($this->bToInt) |
|
147 | + if ($this->bToInt) |
|
148 | 148 | { |
149 | 149 | $aCalls[] = [ |
150 | 150 | '_type' => 'func', |
151 | 151 | '_name' => 'jaxon.utils.string.toInt', |
152 | - 'params' => [[ '_type' => '_', '_name' => 'this' ]], |
|
152 | + 'params' => [['_type' => '_', '_name' => 'this']], |
|
153 | 153 | ]; |
154 | 154 | } |
155 | 155 | return [ |