@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private function initDataBag(): void |
| 36 | 36 | { |
| 37 | - if($this->xDataBag !== null) |
|
| 37 | + if ($this->xDataBag !== null) |
|
| 38 | 38 | { |
| 39 | 39 | return; |
| 40 | 40 | } |
@@ -44,8 +44,7 @@ discard block |
||
| 44 | 44 | $aBody = $xRequest->getParsedBody(); |
| 45 | 45 | $aParams = $xRequest->getQueryParams(); |
| 46 | 46 | $aData = is_array($aBody) ? |
| 47 | - $this->readData($aBody['jxnbags'] ?? []) : |
|
| 48 | - $this->readData($aParams['jxnbags'] ?? []); |
|
| 47 | + $this->readData($aBody['jxnbags'] ?? []) : $this->readData($aParams['jxnbags'] ?? []); |
|
| 49 | 48 | $this->xDataBag = new DataBag($this, $aData); |
| 50 | 49 | } |
| 51 | 50 | |
@@ -67,8 +66,7 @@ discard block |
||
| 67 | 66 | // Todo: clean input data. |
| 68 | 67 | // Todo: verify the checksums. |
| 69 | 68 | return is_string($xData) ? |
| 70 | - (json_decode($xData, true) ?: []) : |
|
| 71 | - (is_array($xData) ? $xData : []); |
|
| 69 | + (json_decode($xData, true) ?: []) : (is_array($xData) ? $xData : []); |
|
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | /** |
@@ -86,7 +84,7 @@ discard block |
||
| 86 | 84 | public function writeCommand(): void |
| 87 | 85 | { |
| 88 | 86 | $this->initDataBag(); |
| 89 | - if($this->xDataBag->touched()) |
|
| 87 | + if ($this->xDataBag->touched()) |
|
| 90 | 88 | { |
| 91 | 89 | // Todo: calculate the checksums. |
| 92 | 90 | $this->addCommand('databag.set', ['values' => $this->xDataBag]); |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | public function getScript(): string |
| 53 | 53 | { |
| 54 | 54 | // It is important to call $this->xParameterReader->uri() only if necessary. |
| 55 | - $sUri = $this->xConfigManager->getOption('core.request.uri') ?: |
|
| 56 | - $this->xParameterReader->uri(); |
|
| 55 | + $sUri = $this->xConfigManager->getOption('core.request.uri') ?: $this->xParameterReader->uri(); |
|
| 57 | 56 | $aOptions = [ |
| 58 | 57 | 'sResponseType' => 'JSON', |
| 59 | 58 | 'sVersion' => $this->option('core.version'), |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function addCodeGenerator(string $sClassName, int $nPriority): void |
| 111 | 111 | { |
| 112 | - while(isset($this->aCodeGenerators[$nPriority])) |
|
| 112 | + while (isset($this->aCodeGenerators[$nPriority])) |
|
| 113 | 113 | { |
| 114 | 114 | $nPriority++; |
| 115 | 115 | } |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void |
| 165 | 165 | { |
| 166 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 166 | + if (!is_subclass_of($xGenerator, AbstractPlugin::class) || |
|
| 167 | 167 | $this->xAssetManager->shallIncludeAssets($xGenerator)) |
| 168 | 168 | { |
| 169 | 169 | // HTML tags for CSS |
| 170 | - if(($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 170 | + if (($sCss = trim($xGenerator->getCss(), " \n")) !== '') |
|
| 171 | 171 | { |
| 172 | 172 | $this->aCss[] = $sCss; |
| 173 | 173 | } |
| 174 | 174 | // HTML tags for js |
| 175 | - if(($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 175 | + if (($sJs = trim($xGenerator->getJs(), " \n")) !== '') |
|
| 176 | 176 | { |
| 177 | 177 | $this->aJs[] = $sJs; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Additional js codes |
| 182 | - if(($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 182 | + if (($xJsCode = $xGenerator->getJsCode()) !== null) |
|
| 183 | 183 | { |
| 184 | - if(($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 184 | + if (($sJs = trim($xJsCode->sJs, " \n")) !== '') |
|
| 185 | 185 | { |
| 186 | 186 | $this->aCodeJs[] = $sJs; |
| 187 | 187 | } |
| 188 | - if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 188 | + if (($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '') |
|
| 189 | 189 | { |
| 190 | 190 | $this->aCodeJsBefore[] = $sJsBefore; |
| 191 | 191 | } |
| 192 | - if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 192 | + if (($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '') |
|
| 193 | 193 | { |
| 194 | 194 | $this->aCodeJsAfter[] = $sJsAfter; |
| 195 | 195 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | private function generateCodes(): void |
| 207 | 207 | { |
| 208 | - if($this->bGenerated) |
|
| 208 | + if ($this->bGenerated) |
|
| 209 | 209 | { |
| 210 | 210 | return; |
| 211 | 211 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | // Sort the code generators by ascending priority |
| 217 | 217 | ksort($this->aCodeGenerators); |
| 218 | 218 | |
| 219 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 219 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 220 | 220 | { |
| 221 | 221 | $this->generatePluginCodes($this->getCodeGenerator($sClassName)); |
| 222 | 222 | } |
@@ -261,11 +261,11 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function getJsScript(): string |
| 263 | 263 | { |
| 264 | - foreach($this->aCodeGenerators as $sClassName) |
|
| 264 | + foreach ($this->aCodeGenerators as $sClassName) |
|
| 265 | 265 | { |
| 266 | 266 | $xGenerator = $this->getCodeGenerator($sClassName); |
| 267 | 267 | // Javascript code |
| 268 | - if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 268 | + if (($sJsScript = trim($xGenerator->getScript(), " \n")) !== '') |
|
| 269 | 269 | { |
| 270 | 270 | $aJsScript[] = $sJsScript; |
| 271 | 271 | } |
@@ -282,38 +282,36 @@ discard block |
||
| 282 | 282 | private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array |
| 283 | 283 | { |
| 284 | 284 | $aCodes = []; |
| 285 | - if($bIncludeCss) |
|
| 285 | + if ($bIncludeCss) |
|
| 286 | 286 | { |
| 287 | 287 | $aCodes[] = $this->getCss(); |
| 288 | 288 | } |
| 289 | - if($bIncludeJs) |
|
| 289 | + if ($bIncludeJs) |
|
| 290 | 290 | { |
| 291 | 291 | $aCodes[] = $this->getJs(); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : |
|
| 295 | - $this->xAssetManager->createJsFiles($this); |
|
| 294 | + $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' : $this->xAssetManager->createJsFiles($this); |
|
| 296 | 295 | // Wrap the js code into the corresponding HTML tag. |
| 297 | 296 | $aCodes[] = $sUrl !== '' ? |
| 298 | - $this->render('include.js', ['sUrl' => $sUrl]) : |
|
| 299 | - $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 297 | + $this->render('include.js', ['sUrl' => $sUrl]) : $this->render('wrapper.js', ['sScript' => $this->getJsScript()]); |
|
| 300 | 298 | |
| 301 | 299 | // Wrap the js codes into HTML tags. |
| 302 | - if(count($this->aCodeJsBefore) > 0) |
|
| 300 | + if (count($this->aCodeJsBefore) > 0) |
|
| 303 | 301 | { |
| 304 | 302 | $sScript = implode("\n\n", $this->aCodeJsBefore); |
| 305 | 303 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 306 | 304 | } |
| 307 | - if(count($this->aCodeJs) > 0) |
|
| 305 | + if (count($this->aCodeJs) > 0) |
|
| 308 | 306 | { |
| 309 | 307 | $sScript = implode("\n\n", $this->aCodeJs); |
| 310 | 308 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
| 311 | 309 | } |
| 312 | - if(count($this->aCodeJsFiles) > 0) |
|
| 310 | + if (count($this->aCodeJsFiles) > 0) |
|
| 313 | 311 | { |
| 314 | 312 | $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]); |
| 315 | 313 | } |
| 316 | - if(count($this->aCodeJsAfter) > 0) |
|
| 314 | + if (count($this->aCodeJsAfter) > 0) |
|
| 317 | 315 | { |
| 318 | 316 | $sScript = implode("\n\n", $this->aCodeJsAfter); |
| 319 | 317 | $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | public function shallIncludeAssets(AbstractPlugin $xPlugin): bool |
| 74 | 74 | { |
| 75 | 75 | $sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
| 76 | - if($this->hasLibOption($sPluginOptionName)) |
|
| 76 | + if ($this->hasLibOption($sPluginOptionName)) |
|
| 77 | 77 | { |
| 78 | 78 | return $this->getLibOption($sPluginOptionName); |
| 79 | 79 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"), |
| 98 | 98 | "$sJsLibUri/jaxon.core$sJsExtension", |
| 99 | 99 | ]; |
| 100 | - if($this->getLibOption('core.debug.on')) |
|
| 100 | + if ($this->getLibOption('core.debug.on')) |
|
| 101 | 101 | { |
| 102 | 102 | $sLanguage = $this->getLibOption('core.language'); |
| 103 | 103 | $aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension"; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | // Check config options |
| 118 | 118 | // - The js.app.export option must be set to true |
| 119 | 119 | // - The js.app.uri and js.app.dir options must be set to non null values |
| 120 | - if(!$this->getLibOption('js.app.export', false) || |
|
| 120 | + if (!$this->getLibOption('js.app.export', false) || |
|
| 121 | 121 | !$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir')) |
| 122 | 122 | { |
| 123 | 123 | return false; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash(); |
| 139 | 139 | $sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
| 140 | 140 | // - The js.app.dir must be writable |
| 141 | - if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 141 | + if (!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
| 142 | 142 | { |
| 143 | 143 | return ''; |
| 144 | 144 | } |
@@ -147,16 +147,16 @@ discard block |
||
| 147 | 147 | $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
| 148 | 148 | $sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName"; |
| 149 | 149 | |
| 150 | - if(!is_file($sJsFilePath) && |
|
| 150 | + if (!is_file($sJsFilePath) && |
|
| 151 | 151 | !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
| 152 | 152 | { |
| 153 | 153 | return ''; |
| 154 | 154 | } |
| 155 | - if(!$this->getLibOption('js.app.minify', false)) |
|
| 155 | + if (!$this->getLibOption('js.app.minify', false)) |
|
| 156 | 156 | { |
| 157 | 157 | return $sJsFileUri . '.js'; |
| 158 | 158 | } |
| 159 | - if(!is_file($sJsMinFilePath) && |
|
| 159 | + if (!is_file($sJsMinFilePath) && |
|
| 160 | 160 | !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
| 161 | 161 | { |
| 162 | 162 | // If the file cannot be minified, return the plain js file. |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function checkOptions(string $sCallable, $xOptions): array |
| 80 | 80 | { |
| 81 | - if(!$this->xValidator->validateClass(trim($sCallable))) |
|
| 81 | + if (!$this->xValidator->validateClass(trim($sCallable))) |
|
| 82 | 82 | { |
| 83 | 83 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 84 | 84 | } |
| 85 | - if(is_string($xOptions)) |
|
| 85 | + if (is_string($xOptions)) |
|
| 86 | 86 | { |
| 87 | 87 | $xOptions = ['include' => $xOptions]; |
| 88 | 88 | } |
| 89 | - elseif(!is_array($xOptions)) |
|
| 89 | + elseif (!is_array($xOptions)) |
|
| 90 | 90 | { |
| 91 | 91 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 92 | 92 | } |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | $sCode = ''; |
| 132 | 132 | $aJsClasses = []; |
| 133 | - foreach($this->xRegistry->getNamespaces() as $sNamespace) |
|
| 133 | + foreach ($this->xRegistry->getNamespaces() as $sNamespace) |
|
| 134 | 134 | { |
| 135 | 135 | $offset = 0; |
| 136 | 136 | $sJsNamespace = str_replace('\\', '.', $sNamespace); |
| 137 | 137 | $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop. |
| 138 | - while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
| 138 | + while (($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
| 139 | 139 | { |
| 140 | 140 | $sJsClass = substr($sJsNamespace, 0, $dotPosition); |
| 141 | 141 | // Generate code for this object |
| 142 | - if(!isset($aJsClasses[$sJsClass])) |
|
| 142 | + if (!isset($aJsClasses[$sJsClass])) |
|
| 143 | 143 | { |
| 144 | 144 | $sCode .= $this->sPrefix . "$sJsClass = {};\n"; |
| 145 | 145 | $aJsClasses[$sJsClass] = $sJsClass; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | private function getCallableScript(CallableObject $xCallableObject): string |
| 161 | 161 | { |
| 162 | - if($xCallableObject->excluded()) |
|
| 162 | + if ($xCallableObject->excluded()) |
|
| 163 | 163 | { |
| 164 | 164 | return ''; |
| 165 | 165 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | // Will be used to print a translated error message. |
| 240 | 240 | $aErrorParams = ['class' => $sClassName, 'method' => $sMethodName]; |
| 241 | 241 | |
| 242 | - if(!$this->xValidator->validateJsObject($sClassName) || |
|
| 242 | + if (!$this->xValidator->validateJsObject($sClassName) || |
|
| 243 | 243 | !$this->xValidator->validateMethod($sMethodName)) |
| 244 | 244 | { |
| 245 | 245 | // Unable to find the requested object or method |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $xCallableObject = $this->getCallable($sClassName); |
| 255 | 255 | |
| 256 | 256 | $sError = 'errors.objects.call'; |
| 257 | - if(!$xCallableObject->excluded($sMethodName)) |
|
| 257 | + if (!$xCallableObject->excluded($sMethodName)) |
|
| 258 | 258 | { |
| 259 | 259 | $xCallableObject->call($this->xTarget); |
| 260 | 260 | return; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | // Unable to find the requested class or method |
| 264 | 264 | $this->throwException('', 'errors.objects.excluded', $aErrorParams); |
| 265 | 265 | } |
| 266 | - catch(ReflectionException|SetupException $e) |
|
| 266 | + catch (ReflectionException|SetupException $e) |
|
| 267 | 267 | { |
| 268 | 268 | // Unable to execute the requested class or method |
| 269 | 269 | $this->throwException($e->getMessage(), $sError, $aErrorParams); |
@@ -85,8 +85,7 @@ discard block |
||
| 85 | 85 | if(is_string($xOptions)) |
| 86 | 86 | { |
| 87 | 87 | $xOptions = ['include' => $xOptions]; |
| 88 | - } |
|
| 89 | - elseif(!is_array($xOptions)) |
|
| 88 | + } elseif(!is_array($xOptions)) |
|
| 90 | 89 | { |
| 91 | 90 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 92 | 91 | } |
@@ -262,8 +261,7 @@ discard block |
||
| 262 | 261 | |
| 263 | 262 | // Unable to find the requested class or method |
| 264 | 263 | $this->throwException('', 'errors.objects.excluded', $aErrorParams); |
| 265 | - } |
|
| 266 | - catch(ReflectionException|SetupException $e) |
|
| 264 | + } catch(ReflectionException|SetupException $e) |
|
| 267 | 265 | { |
| 268 | 266 | // Unable to execute the requested class or method |
| 269 | 267 | $this->throwException($e->getMessage(), $sError, $aErrorParams); |
@@ -92,28 +92,28 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $this->bExcluded = ($xMetadata?->isExcluded() ?? false) || |
| 94 | 94 | (bool)($aOptions['excluded'] ?? false); |
| 95 | - if($this->bExcluded) |
|
| 95 | + if ($this->bExcluded) |
|
| 96 | 96 | { |
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $sSeparator = $aOptions['separator']; |
| 101 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 101 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
| 102 | 102 | { |
| 103 | 103 | $this->sSeparator = $sSeparator; |
| 104 | 104 | } |
| 105 | 105 | $this->addProtectedMethods($aOptions['protected']); |
| 106 | 106 | $this->addProtectedMethods($xMetadata?->getProtectedMethods() ?? []); |
| 107 | 107 | |
| 108 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 108 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 109 | 109 | { |
| 110 | 110 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
| 111 | - foreach($aFunctionNames as $sFunctionName) |
|
| 111 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 112 | 112 | { |
| 113 | 113 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - foreach($xMetadata?->getProperties() ?? [] as $sFunctionName => $aFunctionOptions) |
|
| 116 | + foreach ($xMetadata?->getProperties() ?? [] as $sFunctionName => $aFunctionOptions) |
|
| 117 | 117 | { |
| 118 | 118 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 119 | 119 | } |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | private function addProtectedMethods($xMethods): void |
| 128 | 128 | { |
| 129 | - if(!is_array($xMethods)) |
|
| 129 | + if (!is_array($xMethods)) |
|
| 130 | 130 | { |
| 131 | 131 | $this->aProtectedMethods[trim((string)$xMethods)] = true; |
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | - foreach($xMethods as $sMethod) |
|
| 134 | + foreach ($xMethods as $sMethod) |
|
| 135 | 135 | { |
| 136 | 136 | $this->aProtectedMethods[trim((string)$sMethod)] = true; |
| 137 | 137 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | public function isProtectedMethod(string $sMethodName, bool $bTakeAll): bool |
| 165 | 165 | { |
| 166 | 166 | // The public methods of the Component base classes are protected. |
| 167 | - if(($this->xReflectionClass->isSubclassOf(NodeComponent::class) && |
|
| 167 | + if (($this->xReflectionClass->isSubclassOf(NodeComponent::class) && |
|
| 168 | 168 | in_array($sMethodName, ['item', 'html'])) || |
| 169 | 169 | ($this->xReflectionClass->isSubclassOf(FuncComponent::class) && |
| 170 | 170 | in_array($sMethodName, ['paginator']))) |
@@ -217,17 +217,17 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | private function setHookMethods(array &$aHookMethods, $xValue): void |
| 219 | 219 | { |
| 220 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 220 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 221 | 221 | { |
| 222 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 222 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
| 223 | 223 | { |
| 224 | 224 | $aHookMethods[$sCalledMethod] = []; |
| 225 | 225 | } |
| 226 | - if(is_array($xMethodToCall)) |
|
| 226 | + if (is_array($xMethodToCall)) |
|
| 227 | 227 | { |
| 228 | 228 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 229 | 229 | } |
| 230 | - elseif(is_string($xMethodToCall)) |
|
| 230 | + elseif (is_string($xMethodToCall)) |
|
| 231 | 231 | { |
| 232 | 232 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 233 | 233 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | private function addOption(string $sName, $xValue): void |
| 254 | 254 | { |
| 255 | - switch($sName) |
|
| 255 | + switch ($sName) |
|
| 256 | 256 | { |
| 257 | 257 | // Set the methods to call before processing the request |
| 258 | 258 | case '__before': |
@@ -280,11 +280,11 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 282 | 282 | { |
| 283 | - if(is_string($xOptionValue)) |
|
| 283 | + if (is_string($xOptionValue)) |
|
| 284 | 284 | { |
| 285 | 285 | $xOptionValue = [$xOptionValue]; |
| 286 | 286 | } |
| 287 | - if(!is_array($xOptionValue)) |
|
| 287 | + if (!is_array($xOptionValue)) |
|
| 288 | 288 | { |
| 289 | 289 | return; // Do not save. |
| 290 | 290 | } |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 315 | 315 | { |
| 316 | - switch($sOptionName) |
|
| 316 | + switch ($sOptionName) |
|
| 317 | 317 | { |
| 318 | 318 | case 'excluded': |
| 319 | - if((bool)$xOptionValue) |
|
| 319 | + if ((bool)$xOptionValue) |
|
| 320 | 320 | { |
| 321 | 321 | $this->addProtectedMethods($sFunctionName); |
| 322 | 322 | } |
@@ -340,12 +340,11 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions): void |
| 342 | 342 | { |
| 343 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 343 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 344 | 344 | { |
| 345 | 345 | substr($sOptionName, 0, 2) === '__' ? |
| 346 | 346 | // Options for PHP classes. They start with "__". |
| 347 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 348 | - // Options for javascript code. |
|
| 347 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 349 | 348 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 350 | 349 | } |
| 351 | 350 | } |
@@ -361,16 +360,15 @@ discard block |
||
| 361 | 360 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 362 | 361 | // Then add the method options. |
| 363 | 362 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 364 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 363 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 365 | 364 | { |
| 366 | 365 | // For databags and callbacks, merge the values in a single array. |
| 367 | 366 | // For all the other options, keep the last value. |
| 368 | 367 | $aOptions[$sOptionName] = !in_array($sOptionName, ['bags', 'callback']) ? |
| 369 | - $xOptionValue : |
|
| 370 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 368 | + $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 371 | 369 | } |
| 372 | 370 | // Since callbacks are js object names, they need a special formatting. |
| 373 | - if(isset($aOptions['callback'])) |
|
| 371 | + if (isset($aOptions['callback'])) |
|
| 374 | 372 | { |
| 375 | 373 | $aOptions['callback'] = str_replace('"', '', json_encode($aOptions['callback'])); |
| 376 | 374 | } |
@@ -226,8 +226,7 @@ |
||
| 226 | 226 | if(is_array($xMethodToCall)) |
| 227 | 227 | { |
| 228 | 228 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 229 | - } |
|
| 230 | - elseif(is_string($xMethodToCall)) |
|
| 229 | + } elseif(is_string($xMethodToCall)) |
|
| 231 | 230 | { |
| 232 | 231 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 233 | 232 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | public function __construct(protected ComponentContainer $cdi) |
| 112 | 112 | { |
| 113 | 113 | // Set the composer autoloader |
| 114 | - if(file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
| 114 | + if (file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
| 115 | 115 | file_exists(($sAutoloadFile = __DIR__ . '/../../../../../vendor/autoload.php')) || |
| 116 | 116 | file_exists(($sAutoloadFile = __DIR__ . '/../../../../vendor/autoload.php'))) |
| 117 | 117 | { |
@@ -180,15 +180,15 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | private function makeClassOptions(string $sClassName, array $aClassOptions, array $aDirectoryOptions): array |
| 182 | 182 | { |
| 183 | - foreach($this->aDefaultClassOptions as $sOption => $xValue) |
|
| 183 | + foreach ($this->aDefaultClassOptions as $sOption => $xValue) |
|
| 184 | 184 | { |
| 185 | - if(!isset($aClassOptions[$sOption])) |
|
| 185 | + if (!isset($aClassOptions[$sOption])) |
|
| 186 | 186 | { |
| 187 | 187 | $aClassOptions[$sOption] = $xValue; |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | $aClassOptions['excluded'] = (bool)($aClassOptions['excluded'] ?? false); // Convert to bool. |
| 191 | - if(is_string($aClassOptions['protected'])) |
|
| 191 | + if (is_string($aClassOptions['protected'])) |
|
| 192 | 192 | { |
| 193 | 193 | $aClassOptions['protected'] = [$aClassOptions['protected']]; // Convert to array. |
| 194 | 194 | } |
@@ -199,30 +199,30 @@ discard block |
||
| 199 | 199 | $aDirectoryOptions['classes']['*'] ?? [], // Options for all classes |
| 200 | 200 | $aDirectoryOptions['classes'][$sClassName] ?? [], // Options for this specific class |
| 201 | 201 | ]; |
| 202 | - foreach($aOptionGroups as $aOptionGroup) |
|
| 202 | + foreach ($aOptionGroups as $aOptionGroup) |
|
| 203 | 203 | { |
| 204 | - if(isset($aOptionGroup['separator'])) |
|
| 204 | + if (isset($aOptionGroup['separator'])) |
|
| 205 | 205 | { |
| 206 | 206 | $aClassOptions['separator'] = (string)$aOptionGroup['separator']; |
| 207 | 207 | } |
| 208 | - if(isset($aOptionGroup['excluded'])) |
|
| 208 | + if (isset($aOptionGroup['excluded'])) |
|
| 209 | 209 | { |
| 210 | 210 | $aClassOptions['excluded'] = (bool)$aOptionGroup['excluded']; |
| 211 | 211 | } |
| 212 | - if(isset($aOptionGroup['protected'])) |
|
| 212 | + if (isset($aOptionGroup['protected'])) |
|
| 213 | 213 | { |
| 214 | - if(is_string($aOptionGroup['protected'])) |
|
| 214 | + if (is_string($aOptionGroup['protected'])) |
|
| 215 | 215 | { |
| 216 | 216 | $aOptionGroup['protected'] = [$aOptionGroup['protected']]; // Convert to array. |
| 217 | 217 | } |
| 218 | 218 | $aClassOptions['protected'] = array_merge($aClassOptions['protected'], $aOptionGroup['protected']); |
| 219 | 219 | } |
| 220 | - if(isset($aOptionGroup['functions'])) |
|
| 220 | + if (isset($aOptionGroup['functions'])) |
|
| 221 | 221 | { |
| 222 | 222 | $aClassOptions['functions'] = array_merge($aClassOptions['functions'], $aOptionGroup['functions']); |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | - if(isset($aDirectoryOptions['config']) && !isset($aClassOptions['config'])) |
|
| 225 | + if (isset($aDirectoryOptions['config']) && !isset($aClassOptions['config'])) |
|
| 226 | 226 | { |
| 227 | 227 | $aClassOptions['config'] = $aDirectoryOptions['config']; |
| 228 | 228 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $aOptions = $this->makeClassOptions($sClassName, $aClassOptions, $aDirectoryOptions); |
| 246 | 246 | $this->cdi->registerComponent($sClassName, $aOptions); |
| 247 | - if($this->bUpdateHash) |
|
| 247 | + if ($this->bUpdateHash) |
|
| 248 | 248 | { |
| 249 | 249 | $this->sHash .= $sClassName . $aOptions['timestamp']; |
| 250 | 250 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public function registerComponent(string $sClassName, array $aClassOptions): void |
| 262 | 262 | { |
| 263 | - if($this->xPackageConfig !== null) |
|
| 263 | + if ($this->xPackageConfig !== null) |
|
| 264 | 264 | { |
| 265 | 265 | $aClassOptions['config'] = $this->xPackageConfig; |
| 266 | 266 | } |
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | public function getNamespaceComponentOptions(string $sClassName): ?array |
| 278 | 278 | { |
| 279 | 279 | // Find the corresponding namespace |
| 280 | - foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
| 280 | + foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
| 281 | 281 | { |
| 282 | 282 | // Check if the namespace matches the class. |
| 283 | - if(strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
| 283 | + if (strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
| 284 | 284 | { |
| 285 | 285 | // Save the class options |
| 286 | 286 | $aClassOptions = ['namespace' => $sNamespace]; |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | public function registerDirectory(string $sDirectory, array $aOptions): void |
| 302 | 302 | { |
| 303 | 303 | // Set the autoload option default value |
| 304 | - if(!isset($aOptions['autoload'])) |
|
| 304 | + if (!isset($aOptions['autoload'])) |
|
| 305 | 305 | { |
| 306 | 306 | $aOptions['autoload'] = true; |
| 307 | 307 | } |
| 308 | - if($this->xPackageConfig !== null) |
|
| 308 | + if ($this->xPackageConfig !== null) |
|
| 309 | 309 | { |
| 310 | 310 | $aOptions['config'] = $this->xPackageConfig; |
| 311 | 311 | } |
@@ -337,30 +337,30 @@ discard block |
||
| 337 | 337 | public function registerNamespace(string $sNamespace, array $aOptions): void |
| 338 | 338 | { |
| 339 | 339 | // Separator default value |
| 340 | - if(!isset($aOptions['separator'])) |
|
| 340 | + if (!isset($aOptions['separator'])) |
|
| 341 | 341 | { |
| 342 | 342 | $aOptions['separator'] = '.'; |
| 343 | 343 | } |
| 344 | 344 | $aOptions['separator'] = trim($aOptions['separator']); |
| 345 | - if(!in_array($aOptions['separator'], ['.', '_'])) |
|
| 345 | + if (!in_array($aOptions['separator'], ['.', '_'])) |
|
| 346 | 346 | { |
| 347 | 347 | $aOptions['separator'] = '.'; |
| 348 | 348 | } |
| 349 | - if($aOptions['separator'] === '_') |
|
| 349 | + if ($aOptions['separator'] === '_') |
|
| 350 | 350 | { |
| 351 | 351 | $this->cdi->useUnderscore(); |
| 352 | 352 | } |
| 353 | 353 | // Set the autoload option default value |
| 354 | - if(!isset($aOptions['autoload'])) |
|
| 354 | + if (!isset($aOptions['autoload'])) |
|
| 355 | 355 | { |
| 356 | 356 | $aOptions['autoload'] = true; |
| 357 | 357 | } |
| 358 | - if($this->xPackageConfig !== null) |
|
| 358 | + if ($this->xPackageConfig !== null) |
|
| 359 | 359 | { |
| 360 | 360 | $aOptions['config'] = $this->xPackageConfig; |
| 361 | 361 | } |
| 362 | 362 | // Register the dir with PSR4 autoloading |
| 363 | - if(($aOptions['autoload']) && $this->xAutoloader != null) |
|
| 363 | + if (($aOptions['autoload']) && $this->xAutoloader != null) |
|
| 364 | 364 | { |
| 365 | 365 | $this->xAutoloader->setPsr4($sNamespace . '\\', $aOptions['directory']); |
| 366 | 366 | } |
@@ -376,28 +376,28 @@ discard block |
||
| 376 | 376 | public function registerComponentsInDirectories(): void |
| 377 | 377 | { |
| 378 | 378 | // This is to be done only once. |
| 379 | - if($this->bDirectoriesParsed) |
|
| 379 | + if ($this->bDirectoriesParsed) |
|
| 380 | 380 | { |
| 381 | 381 | return; |
| 382 | 382 | } |
| 383 | 383 | $this->bDirectoriesParsed = true; |
| 384 | 384 | |
| 385 | 385 | // Browse directories without namespaces and read all the files. |
| 386 | - foreach($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions) |
|
| 386 | + foreach ($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions) |
|
| 387 | 387 | { |
| 388 | 388 | $itFile = new SortedFileIterator($sDirectory); |
| 389 | 389 | // Iterate on dir content |
| 390 | - foreach($itFile as $xFile) |
|
| 390 | + foreach ($itFile as $xFile) |
|
| 391 | 391 | { |
| 392 | 392 | // Skip everything except PHP files |
| 393 | - if(!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
| 393 | + if (!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
| 394 | 394 | { |
| 395 | 395 | continue; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | $sClassName = $xFile->getBasename('.php'); |
| 399 | 399 | $aClassOptions = ['timestamp' => $xFile->getMTime()]; |
| 400 | - if(($aDirectoryOptions['autoload']) && $this->xAutoloader !== null) |
|
| 400 | + if (($aDirectoryOptions['autoload']) && $this->xAutoloader !== null) |
|
| 401 | 401 | { |
| 402 | 402 | // Set classmap autoloading. Must be done before registering the class. |
| 403 | 403 | $this->xAutoloader->addClassMap([$sClassName => $xFile->getPathname()]); |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | public function registerComponentsInNamespaces(): void |
| 416 | 416 | { |
| 417 | 417 | // This is to be done only once. |
| 418 | - if($this->bNamespacesParsed) |
|
| 418 | + if ($this->bNamespacesParsed) |
|
| 419 | 419 | { |
| 420 | 420 | return; |
| 421 | 421 | } |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | // Browse directories with namespaces and read all the files. |
| 425 | 425 | $sDS = DIRECTORY_SEPARATOR; |
| 426 | - foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
| 426 | + foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
| 427 | 427 | { |
| 428 | 428 | $this->addNamespace($sNamespace, ['separator' => $aDirectoryOptions['separator']]); |
| 429 | 429 | |
| 430 | 430 | // Iterate on dir content |
| 431 | 431 | $sDirectory = $aDirectoryOptions['directory']; |
| 432 | 432 | $itFile = new SortedFileIterator($sDirectory); |
| 433 | - foreach($itFile as $xFile) |
|
| 433 | + foreach ($itFile as $xFile) |
|
| 434 | 434 | { |
| 435 | 435 | // skip everything except PHP files |
| 436 | - if(!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
| 436 | + if (!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
| 437 | 437 | { |
| 438 | 438 | continue; |
| 439 | 439 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | $sClassPath = $sNamespace; |
| 443 | 443 | $sRelativePath = substr($xFile->getPath(), strlen($sDirectory)); |
| 444 | 444 | $sRelativePath = trim(str_replace($sDS, '\\', $sRelativePath), '\\'); |
| 445 | - if($sRelativePath !== '') |
|
| 445 | + if ($sRelativePath !== '') |
|
| 446 | 446 | { |
| 447 | 447 | $sClassPath .= '\\' . $sRelativePath; |
| 448 | 448 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | public function __construct(string $sDirectory) |
| 29 | 29 | { |
| 30 | 30 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
| 31 | - foreach($itFile as $xFile) |
|
| 31 | + foreach ($itFile as $xFile) |
|
| 32 | 32 | { |
| 33 | 33 | $this->insert($xFile); |
| 34 | 34 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | private function checkDirectory(string $sDirectory): string |
| 69 | 69 | { |
| 70 | 70 | $sDirectory = rtrim(trim($sDirectory), '/\\'); |
| 71 | - if(!is_dir($sDirectory)) |
|
| 71 | + if (!is_dir($sDirectory)) |
|
| 72 | 72 | { |
| 73 | 73 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 74 | 74 | } |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function checkOptions(string $sCallable, $xOptions): array |
| 83 | 83 | { |
| 84 | - if(is_string($xOptions)) |
|
| 84 | + if (is_string($xOptions)) |
|
| 85 | 85 | { |
| 86 | 86 | $xOptions = ['namespace' => $xOptions]; |
| 87 | 87 | } |
| 88 | - if(!is_array($xOptions)) |
|
| 88 | + if (!is_array($xOptions)) |
|
| 89 | 89 | { |
| 90 | 90 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 91 | 91 | } |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | $xOptions['directory'] = $this->checkDirectory($sCallable); |
| 94 | 94 | // Check the namespace |
| 95 | 95 | $sNamespace = $xOptions['namespace'] ?? ''; |
| 96 | - if(!($xOptions['namespace'] = trim($sNamespace, ' \\'))) |
|
| 96 | + if (!($xOptions['namespace'] = trim($sNamespace, ' \\'))) |
|
| 97 | 97 | { |
| 98 | 98 | $xOptions['namespace'] = ''; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Change the keys in $xOptions to have "\" as separator |
| 102 | 102 | $_aOptions = []; |
| 103 | - foreach($xOptions as $sName => $aOption) |
|
| 103 | + foreach ($xOptions as $sName => $aOption) |
|
| 104 | 104 | { |
| 105 | 105 | $sName = trim(str_replace('.', '\\', $sName), ' \\'); |
| 106 | 106 | $_aOptions[$sName] = $aOption; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | public function register(string $sType, string $sCallable, array $aOptions): bool |
| 115 | 115 | { |
| 116 | 116 | // The $sCallable var is not used here because the checkOptions() method copied it into the $aOptions array. |
| 117 | - if(($aOptions['namespace'])) |
|
| 117 | + if (($aOptions['namespace'])) |
|
| 118 | 118 | { |
| 119 | 119 | $this->xRegistry->registerNamespace($aOptions['namespace'], $aOptions); |
| 120 | 120 | return true; |