@@ -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. |
@@ -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 | } |
@@ -88,29 +88,29 @@ discard block |
||
| 88 | 88 | array $aProtectedMethods = [], array $aProperties = []) |
| 89 | 89 | { |
| 90 | 90 | $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
| 91 | - if($this->bExcluded) |
|
| 91 | + if ($this->bExcluded) |
|
| 92 | 92 | { |
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $sSeparator = $aOptions['separator']; |
| 97 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 97 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
| 98 | 98 | { |
| 99 | 99 | $this->sSeparator = $sSeparator; |
| 100 | 100 | } |
| 101 | 101 | $this->addProtectedMethods($aOptions['protected']); |
| 102 | 102 | $this->addProtectedMethods($aProtectedMethods); |
| 103 | 103 | |
| 104 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 104 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 105 | 105 | { |
| 106 | 106 | // Names are in a comma-separated list. |
| 107 | 107 | $aFunctionNames = explode(',', $sNames); |
| 108 | - foreach($aFunctionNames as $sFunctionName) |
|
| 108 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 109 | 109 | { |
| 110 | 110 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | - foreach($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 113 | + foreach ($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 114 | 114 | { |
| 115 | 115 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 116 | 116 | } |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | private function addProtectedMethods(array|string $xMethods): void |
| 125 | 125 | { |
| 126 | - if(!is_array($xMethods)) |
|
| 126 | + if (!is_array($xMethods)) |
|
| 127 | 127 | { |
| 128 | 128 | $this->aProtectedMethods[trim((string)$xMethods)] = true; |
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - foreach($xMethods as $sMethod) |
|
| 132 | + foreach ($xMethods as $sMethod) |
|
| 133 | 133 | { |
| 134 | 134 | $this->aProtectedMethods[trim((string)$sMethod)] = true; |
| 135 | 135 | } |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | private function setHookMethods(array &$aHookMethods, $xValue): void |
| 208 | 208 | { |
| 209 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 209 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 210 | 210 | { |
| 211 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 211 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
| 212 | 212 | { |
| 213 | 213 | $aHookMethods[$sCalledMethod] = []; |
| 214 | 214 | } |
| 215 | - if(is_array($xMethodToCall)) |
|
| 215 | + if (is_array($xMethodToCall)) |
|
| 216 | 216 | { |
| 217 | 217 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 218 | 218 | } |
| 219 | - elseif(is_string($xMethodToCall)) |
|
| 219 | + elseif (is_string($xMethodToCall)) |
|
| 220 | 220 | { |
| 221 | 221 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 222 | 222 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | private function addOption(string $sName, $xValue): void |
| 243 | 243 | { |
| 244 | - switch($sName) |
|
| 244 | + switch ($sName) |
|
| 245 | 245 | { |
| 246 | 246 | // Set the methods to call before processing the request |
| 247 | 247 | case '__before': |
@@ -269,11 +269,11 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 271 | 271 | { |
| 272 | - if(is_string($xOptionValue)) |
|
| 272 | + if (is_string($xOptionValue)) |
|
| 273 | 273 | { |
| 274 | 274 | $xOptionValue = [$xOptionValue]; |
| 275 | 275 | } |
| 276 | - if(!is_array($xOptionValue)) |
|
| 276 | + if (!is_array($xOptionValue)) |
|
| 277 | 277 | { |
| 278 | 278 | return; // Do not save. |
| 279 | 279 | } |
@@ -303,10 +303,10 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 305 | 305 | { |
| 306 | - switch($sOptionName) |
|
| 306 | + switch ($sOptionName) |
|
| 307 | 307 | { |
| 308 | 308 | case 'excluded': |
| 309 | - if((bool)$xOptionValue) |
|
| 309 | + if ((bool)$xOptionValue) |
|
| 310 | 310 | { |
| 311 | 311 | $this->addProtectedMethods($sFunctionName); |
| 312 | 312 | } |
@@ -330,12 +330,11 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions): void |
| 332 | 332 | { |
| 333 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 333 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 334 | 334 | { |
| 335 | 335 | substr($sOptionName, 0, 2) === '__' ? |
| 336 | 336 | // Options for PHP classes. They start with "__". |
| 337 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 338 | - // Options for javascript code. |
|
| 337 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 339 | 338 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 340 | 339 | } |
| 341 | 340 | } |
@@ -351,16 +350,15 @@ discard block |
||
| 351 | 350 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 352 | 351 | // Then add the method options. |
| 353 | 352 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 354 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 353 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 355 | 354 | { |
| 356 | 355 | // For databags and callbacks, merge the values in a single array. |
| 357 | 356 | // For all the other options, keep the last value. |
| 358 | 357 | $aOptions[$sOptionName] = !in_array($sOptionName, ['bags', 'callback']) ? |
| 359 | - $xOptionValue : |
|
| 360 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 358 | + $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 361 | 359 | } |
| 362 | 360 | // Since callbacks are js object names, they need a special formatting. |
| 363 | - if(isset($aOptions['callback'])) |
|
| 361 | + if (isset($aOptions['callback'])) |
|
| 364 | 362 | { |
| 365 | 363 | $aOptions['callback'] = str_replace('"', '', json_encode($aOptions['callback'])); |
| 366 | 364 | } |
@@ -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; |
@@ -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', |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | if(is_string($xOptions)) |
| 93 | 93 | { |
| 94 | 94 | $xOptions = ['include' => $xOptions]; |
| 95 | - } |
|
| 96 | - elseif(!is_array($xOptions)) |
|
| 95 | + } elseif(!is_array($xOptions)) |
|
| 97 | 96 | { |
| 98 | 97 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 99 | 98 | } |
@@ -236,8 +235,7 @@ discard block |
||
| 236 | 235 | { |
| 237 | 236 | /** @var CallableFunction */ |
| 238 | 237 | $xFunction = $this->getCallable($sRequestedFunction); |
| 239 | - } |
|
| 240 | - catch(Exception $e) |
|
| 238 | + } catch(Exception $e) |
|
| 241 | 239 | { |
| 242 | 240 | // Unable to find the requested function |
| 243 | 241 | $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
@@ -246,8 +244,7 @@ discard block |
||
| 246 | 244 | try |
| 247 | 245 | { |
| 248 | 246 | $xFunction->call($this->xTarget->args()); |
| 249 | - } |
|
| 250 | - catch(Exception $e) |
|
| 247 | + } catch(Exception $e) |
|
| 251 | 248 | { |
| 252 | 249 | // Unable to execute the requested function |
| 253 | 250 | $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 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | public function get(string $key, mixed $default = null): mixed |
| 32 | 32 | { |
| 33 | 33 | $value = $this->values[$key] ?? $default; |
| 34 | - if(is_callable($value)) |
|
| 34 | + if (is_callable($value)) |
|
| 35 | 35 | { |
| 36 | 36 | $value = $value(); |
| 37 | 37 | // Save the value returned by the callback in the stash. |