@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | public function __construct(array $aOptions, array $aAnnotations) |
| 81 | 81 | { |
| 82 | 82 | [$bExcluded, $aAnnotationOptions, $aAnnotationProtected] = $aAnnotations; |
| 83 | - $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
| 84 | - if($this->bExcluded) |
|
| 83 | + $this->bExcluded = $bExcluded || (bool) ($aOptions['excluded'] ?? false); |
|
| 84 | + if ($this->bExcluded) |
|
| 85 | 85 | { |
| 86 | 86 | return; |
| 87 | 87 | } |
@@ -89,15 +89,15 @@ discard block |
||
| 89 | 89 | $this->addOption('separator', $aOptions['separator']); |
| 90 | 90 | $this->addOption('protected', array_merge($aOptions['protected'], $aAnnotationProtected)); |
| 91 | 91 | |
| 92 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 92 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 93 | 93 | { |
| 94 | 94 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
| 95 | - foreach($aFunctionNames as $sFunctionName) |
|
| 95 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 96 | 96 | { |
| 97 | 97 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - foreach($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 100 | + foreach ($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 101 | 101 | { |
| 102 | 102 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 103 | 103 | } |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | private function setHookMethods(array &$aHookMethods, $xValue) |
| 173 | 173 | { |
| 174 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 174 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 175 | 175 | { |
| 176 | - if(is_array($xMethodToCall)) |
|
| 176 | + if (is_array($xMethodToCall)) |
|
| 177 | 177 | { |
| 178 | 178 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
| 179 | 179 | } |
| 180 | - elseif(is_string($xMethodToCall)) |
|
| 180 | + elseif (is_string($xMethodToCall)) |
|
| 181 | 181 | { |
| 182 | 182 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
| 183 | 183 | } |
@@ -202,18 +202,18 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function addOption(string $sName, $xValue) |
| 204 | 204 | { |
| 205 | - switch($sName) |
|
| 205 | + switch ($sName) |
|
| 206 | 206 | { |
| 207 | 207 | // Set the separator |
| 208 | 208 | case 'separator': |
| 209 | - if($xValue === '_' || $xValue === '.') |
|
| 209 | + if ($xValue === '_' || $xValue === '.') |
|
| 210 | 210 | { |
| 211 | 211 | $this->sSeparator = $xValue; |
| 212 | 212 | } |
| 213 | 213 | break; |
| 214 | 214 | // Set the protected methods |
| 215 | 215 | case 'protected': |
| 216 | - if(is_array($xValue)) |
|
| 216 | + if (is_array($xValue)) |
|
| 217 | 217 | { |
| 218 | 218 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
| 219 | 219 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $this->addDiOption($xValue); |
| 232 | 232 | break; |
| 233 | 233 | case 'excluded': |
| 234 | - $this->bExcluded = (bool)$xValue; |
|
| 234 | + $this->bExcluded = (bool) $xValue; |
|
| 235 | 235 | break; |
| 236 | 236 | default: |
| 237 | 237 | break; |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
| 249 | 249 | { |
| 250 | - if(is_string($xOptionValue)) |
|
| 250 | + if (is_string($xOptionValue)) |
|
| 251 | 251 | { |
| 252 | 252 | $xOptionValue = [$xOptionValue]; |
| 253 | 253 | } |
| 254 | - if(!is_array($xOptionValue)) |
|
| 254 | + if (!is_array($xOptionValue)) |
|
| 255 | 255 | { |
| 256 | 256 | return; // Do not save. |
| 257 | 257 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
| 282 | 282 | { |
| 283 | - switch($sOptionName) |
|
| 283 | + switch ($sOptionName) |
|
| 284 | 284 | { |
| 285 | 285 | // For databags, all the value are merged in a single array. |
| 286 | 286 | case 'bags': |
@@ -301,12 +301,11 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions) |
| 303 | 303 | { |
| 304 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 304 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 305 | 305 | { |
| 306 | 306 | substr($sOptionName, 0, 2) === '__' ? |
| 307 | 307 | // Options for PHP classes. They start with "__". |
| 308 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 309 | - // Options for javascript code. |
|
| 308 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 310 | 309 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 311 | 310 | } |
| 312 | 311 | } |
@@ -322,12 +321,11 @@ discard block |
||
| 322 | 321 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 323 | 322 | // Then add the method options. |
| 324 | 323 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 325 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 324 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 326 | 325 | { |
| 327 | 326 | // For databags, merge the values in a single array. |
| 328 | 327 | // For all the other options, including callback, keep the last value. |
| 329 | - $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : |
|
| 330 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 328 | + $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 331 | 329 | } |
| 332 | 330 | return $aOptions; |
| 333 | 331 | } |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function checkOptions(string $sCallable, $xOptions): array |
| 135 | 135 | { |
| 136 | - if(!$this->xValidator->validateClass(trim($sCallable))) |
|
| 136 | + if (!$this->xValidator->validateClass(trim($sCallable))) |
|
| 137 | 137 | { |
| 138 | 138 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 139 | 139 | } |
| 140 | - if(is_string($xOptions)) |
|
| 140 | + if (is_string($xOptions)) |
|
| 141 | 141 | { |
| 142 | 142 | $xOptions = ['include' => $xOptions]; |
| 143 | 143 | } |
| 144 | - elseif(!is_array($xOptions)) |
|
| 144 | + elseif (!is_array($xOptions)) |
|
| 145 | 145 | { |
| 146 | 146 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 147 | 147 | } |
@@ -186,16 +186,16 @@ discard block |
||
| 186 | 186 | $sCode = ''; |
| 187 | 187 | $aJsClasses = []; |
| 188 | 188 | $aNamespaces = $this->xRepository->getNamespaces(); |
| 189 | - foreach($aNamespaces as $sNamespace) |
|
| 189 | + foreach ($aNamespaces as $sNamespace) |
|
| 190 | 190 | { |
| 191 | 191 | $offset = 0; |
| 192 | 192 | $sJsNamespace = str_replace('\\', '.', $sNamespace); |
| 193 | 193 | $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop. |
| 194 | - while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
| 194 | + while (($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
| 195 | 195 | { |
| 196 | 196 | $sJsClass = substr($sJsNamespace, 0, $dotPosition); |
| 197 | 197 | // Generate code for this object |
| 198 | - if(!isset($aJsClasses[$sJsClass])) |
|
| 198 | + if (!isset($aJsClasses[$sJsClass])) |
|
| 199 | 199 | { |
| 200 | 200 | $sCode .= $this->sPrefix . "$sJsClass = {};\n"; |
| 201 | 201 | $aJsClasses[$sJsClass] = $sJsClass; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | private function getCallableScript(CallableObject $xCallableObject): string |
| 217 | 217 | { |
| 218 | - if($xCallableObject->excluded()) |
|
| 218 | + if ($xCallableObject->excluded()) |
|
| 219 | 219 | { |
| 220 | 220 | return ''; |
| 221 | 221 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
| 254 | 254 | { |
| 255 | 255 | $aBody = $xRequest->getParsedBody(); |
| 256 | - if(is_array($aBody)) |
|
| 256 | + if (is_array($aBody)) |
|
| 257 | 257 | { |
| 258 | 258 | return isset($aBody['jxncls']) && isset($aBody['jxnmthd']); |
| 259 | 259 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | public function setTarget(ServerRequestInterface $xRequest) |
| 268 | 268 | { |
| 269 | 269 | $aBody = $xRequest->getParsedBody(); |
| 270 | - if(is_array($aBody)) |
|
| 270 | + if (is_array($aBody)) |
|
| 271 | 271 | { |
| 272 | 272 | $this->xTarget = Target::makeClass(trim($aBody['jxncls']), trim($aBody['jxnmthd'])); |
| 273 | 273 | return; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $sMethodName = $this->xTarget->getMethodName(); |
| 287 | 287 | $this->xTarget->setMethodArgs($this->xParameterReader->args()); |
| 288 | 288 | |
| 289 | - if(!$this->xValidator->validateClass($sClassName) || !$this->xValidator->validateMethod($sMethodName)) |
|
| 289 | + if (!$this->xValidator->validateClass($sClassName) || !$this->xValidator->validateMethod($sMethodName)) |
|
| 290 | 290 | { |
| 291 | 291 | // Unable to find the requested object or method |
| 292 | 292 | throw new RequestException($this->xTranslator->trans('errors.objects.invalid', |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $xCallableObject = $this->xRegistry->getCallableObject($sClassName); |
| 300 | 300 | return $xCallableObject->call($this->xTarget); |
| 301 | 301 | } |
| 302 | - catch(ReflectionException|SetupException $e) |
|
| 302 | + catch (ReflectionException | SetupException $e) |
|
| 303 | 303 | { |
| 304 | 304 | // Unable to find the requested class or method |
| 305 | 305 | $this->di->getLogger()->error($e->getMessage()); |
@@ -298,11 +298,11 @@ |
||
| 298 | 298 | $sMethod = $this->xTarget->getMethodName(); |
| 299 | 299 | // The hooks defined at method level are merged with those defined at class level. |
| 300 | 300 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
| 301 | - foreach($aMethods as $xKey => $xValue) |
|
| 301 | + foreach ($aMethods as $xKey => $xValue) |
|
| 302 | 302 | { |
| 303 | 303 | $sHookName = $xValue; |
| 304 | 304 | $aHookArgs = []; |
| 305 | - if(is_string($xKey)) |
|
| 305 | + if (is_string($xKey)) |
|
| 306 | 306 | { |
| 307 | 307 | $sHookName = $xKey; |
| 308 | 308 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |