@@ -63,7 +63,7 @@ |
||
| 63 | 63 | public function ajaxResponse(): ResponseInterface |
| 64 | 64 | { |
| 65 | 65 | $xPsrResponse = $this->xPsr17Factory->createResponse(200); |
| 66 | - if($this->xRequest->getMethod() === 'GET') |
|
| 66 | + if ($this->xRequest->getMethod() === 'GET') |
|
| 67 | 67 | { |
| 68 | 68 | $xPsrResponse = $xPsrResponse |
| 69 | 69 | ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
@@ -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. |
@@ -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; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function configure(string $sName, string $sValue): void |
| 106 | 106 | { |
| 107 | - switch($sName) |
|
| 107 | + switch ($sName) |
|
| 108 | 108 | { |
| 109 | 109 | case 'class': // The user function is a method in the given class |
| 110 | 110 | $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function call(array $aArgs = []): void |
| 130 | 130 | { |
| 131 | - if($this->sInclude !== '') |
|
| 131 | + if ($this->sInclude !== '') |
|
| 132 | 132 | { |
| 133 | 133 | require_once $this->sInclude; |
| 134 | 134 | } |
| 135 | 135 | // If the function is an alias for a class method, then instantiate the class |
| 136 | - if(is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
| 136 | + if (is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
| 137 | 137 | { |
| 138 | 138 | $sClassName = $this->xPhpFunction[0]; |
| 139 | 139 | $this->xPhpFunction[0] = $this->di->h($sClassName) ? |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function checkOptions(string $sCallable, $xOptions): array |
| 87 | 87 | { |
| 88 | - if(!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 88 | + if (!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 89 | 89 | { |
| 90 | 90 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 91 | 91 | } |
| 92 | - if(is_string($xOptions)) |
|
| 92 | + if (is_string($xOptions)) |
|
| 93 | 93 | { |
| 94 | 94 | $xOptions = ['include' => $xOptions]; |
| 95 | 95 | } |
| 96 | - elseif(!is_array($xOptions)) |
|
| 96 | + elseif (!is_array($xOptions)) |
|
| 97 | 97 | { |
| 98 | 98 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 99 | 99 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $sPhpFunction = trim($sCallable); |
| 115 | 115 | $sFunction = $sPhpFunction; |
| 116 | 116 | // Check if an alias is defined |
| 117 | - if(isset($aOptions['alias'])) |
|
| 117 | + if (isset($aOptions['alias'])) |
|
| 118 | 118 | { |
| 119 | 119 | $sFunction = (string)$aOptions['alias']; |
| 120 | 120 | unset($aOptions['alias']); |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | public function getCallable(string $sCallable): CallableFunction|null |
| 139 | 139 | { |
| 140 | 140 | $sFunction = trim($sCallable); |
| 141 | - if(!isset($this->aFunctions[$sFunction])) |
|
| 141 | + if (!isset($this->aFunctions[$sFunction])) |
|
| 142 | 142 | { |
| 143 | 143 | return null; |
| 144 | 144 | } |
| 145 | 145 | $xCallable = new CallableFunction($this->di, $sFunction, |
| 146 | 146 | $this->sPrefix . $sFunction, $this->aFunctions[$sFunction]); |
| 147 | - foreach($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 147 | + foreach ($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 148 | 148 | { |
| 149 | 149 | $xCallable->configure($sName, $sValue); |
| 150 | 150 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | public function getScript(): string |
| 174 | 174 | { |
| 175 | 175 | $code = ''; |
| 176 | - foreach(array_keys($this->aFunctions) as $sFunction) |
|
| 176 | + foreach (array_keys($this->aFunctions) as $sFunction) |
|
| 177 | 177 | { |
| 178 | 178 | $xFunction = $this->getCallable($sFunction); |
| 179 | 179 | $code .= $this->getCallableScript($xFunction); |
@@ -211,8 +211,7 @@ discard block |
||
| 211 | 211 | private function throwException(Exception $xException, string $sErrorMessage): void |
| 212 | 212 | { |
| 213 | 213 | $this->di->getLogger()->error($xException->getMessage()); |
| 214 | - throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : |
|
| 215 | - "\n" . $xException->getMessage())); |
|
| 214 | + throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : "\n" . $xException->getMessage())); |
|
| 216 | 215 | } |
| 217 | 216 | |
| 218 | 217 | /** |
@@ -224,7 +223,7 @@ discard block |
||
| 224 | 223 | $sRequestedFunction = $this->xTarget->getFunctionName(); |
| 225 | 224 | |
| 226 | 225 | // Security check: make sure the requested function was registered. |
| 227 | - if(!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 226 | + if (!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 228 | 227 | !isset($this->aFunctions[$sRequestedFunction])) |
| 229 | 228 | { |
| 230 | 229 | // Unable to find the requested function |
@@ -237,7 +236,7 @@ discard block |
||
| 237 | 236 | /** @var CallableFunction */ |
| 238 | 237 | $xFunction = $this->getCallable($sRequestedFunction); |
| 239 | 238 | } |
| 240 | - catch(Exception $e) |
|
| 239 | + catch (Exception $e) |
|
| 241 | 240 | { |
| 242 | 241 | // Unable to find the requested function |
| 243 | 242 | $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
@@ -247,7 +246,7 @@ discard block |
||
| 247 | 246 | { |
| 248 | 247 | $xFunction->call($this->xTarget->args()); |
| 249 | 248 | } |
| 250 | - catch(Exception $e) |
|
| 249 | + catch (Exception $e) |
|
| 251 | 250 | { |
| 252 | 251 | // Unable to execute the requested function |
| 253 | 252 | $this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | public function onChange(Config $xConfig, string $sName): void |
| 27 | 27 | { |
| 28 | 28 | // Set the library language any time the config is changed. |
| 29 | - if($sName === '' || $sName === 'core.language') |
|
| 29 | + if ($sName === '' || $sName === 'core.language') |
|
| 30 | 30 | { |
| 31 | 31 | $this->setLocale($xConfig->getOption('core.language')); |
| 32 | 32 | } |