@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function has(string $sClass): bool |
| 143 | 143 | { |
| 144 | - if($this->xContainer != null && $this->xContainer->has($sClass)) |
|
| 144 | + if ($this->xContainer != null && $this->xContainer->has($sClass)) |
|
| 145 | 145 | { |
| 146 | 146 | return true; |
| 147 | 147 | } |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | { |
| 173 | 173 | try |
| 174 | 174 | { |
| 175 | - if($this->xContainer != null && $this->xContainer->has($sClass)) |
|
| 175 | + if ($this->xContainer != null && $this->xContainer->has($sClass)) |
|
| 176 | 176 | { |
| 177 | 177 | return $this->xContainer->get($sClass); |
| 178 | 178 | } |
| 179 | 179 | return $this->offsetGet($sClass); |
| 180 | 180 | } |
| 181 | - catch(Exception|Throwable $e) |
|
| 181 | + catch (Exception | Throwable $e) |
|
| 182 | 182 | { |
| 183 | 183 | $xTranslator = $this->g(Translator::class); |
| 184 | 184 | $sMessage = $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
@@ -238,22 +238,22 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | public function make($xClass) |
| 240 | 240 | { |
| 241 | - if(is_string($xClass)) |
|
| 241 | + if (is_string($xClass)) |
|
| 242 | 242 | { |
| 243 | 243 | $xClass = new ReflectionClass($xClass); // Create the reflection class instance |
| 244 | 244 | } |
| 245 | - if(!($xClass instanceof ReflectionClass)) |
|
| 245 | + if (!($xClass instanceof ReflectionClass)) |
|
| 246 | 246 | { |
| 247 | 247 | return null; |
| 248 | 248 | } |
| 249 | 249 | // Use the Reflection class to get the parameters of the constructor |
| 250 | - if(($constructor = $xClass->getConstructor()) === null) |
|
| 250 | + if (($constructor = $xClass->getConstructor()) === null) |
|
| 251 | 251 | { |
| 252 | 252 | return $xClass->newInstance(); |
| 253 | 253 | } |
| 254 | 254 | $parameters = $constructor->getParameters(); |
| 255 | 255 | $parameterInstances = []; |
| 256 | - foreach($parameters as $parameter) |
|
| 256 | + foreach ($parameters as $parameter) |
|
| 257 | 257 | { |
| 258 | 258 | // Get the parameter instance from the DI |
| 259 | 259 | $parameterInstances[] = $this->get($parameter->getClass()->getName()); |
@@ -177,8 +177,7 @@ |
||
| 177 | 177 | return $this->xContainer->get($sClass); |
| 178 | 178 | } |
| 179 | 179 | return $this->offsetGet($sClass); |
| 180 | - } |
|
| 181 | - catch(Exception|Throwable $e) |
|
| 180 | + } catch(Exception|Throwable $e) |
|
| 182 | 181 | { |
| 183 | 182 | $xTranslator = $this->g(Translator::class); |
| 184 | 183 | $sMessage = $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | private function getCallableObjectOptions(array $aConfigOptions, array $aAnnotationOptions): array |
| 37 | 37 | { |
| 38 | 38 | $aOptions = []; |
| 39 | - foreach($aConfigOptions as $sNames => $aFunctionOptions) |
|
| 39 | + foreach ($aConfigOptions as $sNames => $aFunctionOptions) |
|
| 40 | 40 | { |
| 41 | 41 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
| 42 | - foreach($aFunctionNames as $sFunctionName) |
|
| 42 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 43 | 43 | { |
| 44 | 44 | $aOptions[$sFunctionName] = array_merge($aOptions[$sFunctionName] ?? [], $aFunctionOptions); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - foreach($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 47 | + foreach ($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 48 | 48 | { |
| 49 | 49 | $aOptions[$sFunctionName] = array_merge($aOptions[$sFunctionName] ?? [], $aFunctionOptions); |
| 50 | 50 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $xAnnotationReader = $this->g(AnnotationReaderInterface::class); |
| 66 | 66 | [$bExcluded, $aAnnotationOptions, $aAnnotationProtected] = |
| 67 | 67 | $xAnnotationReader->getAttributes($sClassName, $xCallableObject->getPublicMethods($aProtectedMethods)); |
| 68 | - if($bExcluded) |
|
| 68 | + if ($bExcluded) |
|
| 69 | 69 | { |
| 70 | 70 | $xCallableObject->configure('excluded', true); |
| 71 | 71 | return; |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | // Functions options |
| 78 | 78 | $aCallableOptions = []; |
| 79 | 79 | $aOptions = $this->getCallableObjectOptions($aOptions['functions'], $aAnnotationOptions); |
| 80 | - foreach($aOptions as $sFunctionName => $aFunctionOptions) |
|
| 80 | + foreach ($aOptions as $sFunctionName => $aFunctionOptions) |
|
| 81 | 81 | { |
| 82 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 82 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 83 | 83 | { |
| 84 | - if(substr($sOptionName, 0, 2) !== '__') |
|
| 84 | + if (substr($sOptionName, 0, 2) !== '__') |
|
| 85 | 85 | { |
| 86 | 86 | // Options for javascript code. |
| 87 | 87 | $aCallableOptions[$sFunctionName][$sOptionName] = $xOptionValue; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $sReflectionClass = $sClassName . '_ReflectionClass'; |
| 111 | 111 | |
| 112 | 112 | // Make sure the registered class exists |
| 113 | - if(isset($aOptions['include'])) |
|
| 113 | + if (isset($aOptions['include'])) |
|
| 114 | 114 | { |
| 115 | 115 | require_once($aOptions['include']); |
| 116 | 116 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | $this->val($sReflectionClass, new ReflectionClass($sClassName)); |
| 121 | 121 | } |
| 122 | - catch(ReflectionException $e) |
|
| 122 | + catch (ReflectionException $e) |
|
| 123 | 123 | { |
| 124 | 124 | $xTranslator = $this->g(Translator::class); |
| 125 | 125 | $sMessage = $xTranslator->trans('errors.class.invalid', ['name' => $sClassName]); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $this->set($sClassName, function($c) use($sClassName, $sReflectionClass) { |
| 146 | 146 | $xRegisteredObject = $this->make($c->g($sReflectionClass)); |
| 147 | 147 | // Initialize the object |
| 148 | - if($xRegisteredObject instanceof CallableClass) |
|
| 148 | + if ($xRegisteredObject instanceof CallableClass) |
|
| 149 | 149 | { |
| 150 | 150 | // Set the protected attributes of the object |
| 151 | 151 | $cSetter = function($c, $sClassName) { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // Run the callback for class initialisation |
| 160 | 160 | $aCallbacks = $c->g(CallbackManager::class)->getInitCallbacks(); |
| 161 | - foreach($aCallbacks as $xCallback) |
|
| 161 | + foreach ($aCallbacks as $xCallback) |
|
| 162 | 162 | { |
| 163 | 163 | call_user_func($xCallback, $xRegisteredObject); |
| 164 | 164 | } |
@@ -118,8 +118,7 @@ |
||
| 118 | 118 | try |
| 119 | 119 | { |
| 120 | 120 | $this->val($sReflectionClass, new ReflectionClass($sClassName)); |
| 121 | - } |
|
| 122 | - catch(ReflectionException $e) |
|
| 121 | + } catch(ReflectionException $e) |
|
| 123 | 122 | { |
| 124 | 123 | $xTranslator = $this->g(Translator::class); |
| 125 | 124 | $sMessage = $xTranslator->trans('errors.class.invalid', ['name' => $sClassName]); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | }; |
| 31 | 31 | }); |
| 32 | 32 | |
| 33 | - if(class_exists(AnnotationReader::class)) |
|
| 33 | + if (class_exists(AnnotationReader::class)) |
|
| 34 | 34 | { |
| 35 | 35 | $sEventListenerKey = AnnotationReader::class . '\\ConfigListener'; |
| 36 | 36 | // The annotation package is installed, register the real annotation reader, |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | public function onChanges(Config $xConfig) |
| 42 | 42 | { |
| 43 | - if($xConfig->getOption('core.annotations.on')) |
|
| 43 | + if ($xConfig->getOption('core.annotations.on')) |
|
| 44 | 44 | { |
| 45 | 45 | AnnotationReader::register(jaxon()->di()); |
| 46 | 46 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function onChange(Config $xConfig, string $sName) |
| 50 | 50 | { |
| 51 | - if($sName === 'core.annotations.on' && $xConfig->getOption('core.annotations.on')) |
|
| 51 | + if ($sName === 'core.annotations.on' && $xConfig->getOption('core.annotations.on')) |
|
| 52 | 52 | { |
| 53 | 53 | AnnotationReader::register(jaxon()->di()); |
| 54 | 54 | } |
@@ -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; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | private function getCallableScript(string $sClassName, CallableObject $xCallableObject): string |
| 218 | 218 | { |
| 219 | - if($xCallableObject->excluded()) |
|
| 219 | + if ($xCallableObject->excluded()) |
|
| 220 | 220 | { |
| 221 | 221 | return ''; |
| 222 | 222 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | }); |
| 245 | 245 | |
| 246 | 246 | $sCode = $this->getNamespacesScript(); |
| 247 | - foreach($aCallableObjects as $sClassName => $xCallableObject) |
|
| 247 | + foreach ($aCallableObjects as $sClassName => $xCallableObject) |
|
| 248 | 248 | { |
| 249 | 249 | $sCode .= $this->getCallableScript($sClassName, $xCallableObject); |
| 250 | 250 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
| 258 | 258 | { |
| 259 | 259 | $aBody = $xRequest->getParsedBody(); |
| 260 | - if(is_array($aBody)) |
|
| 260 | + if (is_array($aBody)) |
|
| 261 | 261 | { |
| 262 | 262 | return isset($aBody['jxncls']) && isset($aBody['jxnmthd']); |
| 263 | 263 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | public function setTarget(ServerRequestInterface $xRequest) |
| 272 | 272 | { |
| 273 | 273 | $aBody = $xRequest->getParsedBody(); |
| 274 | - if(is_array($aBody)) |
|
| 274 | + if (is_array($aBody)) |
|
| 275 | 275 | { |
| 276 | 276 | $this->xTarget = Target::makeClass(trim($aBody['jxncls']), trim($aBody['jxnmthd'])); |
| 277 | 277 | return; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $sRequestedClass = $this->xTarget->getClassName(); |
| 290 | 290 | $sRequestedMethod = $this->xTarget->getMethodName(); |
| 291 | 291 | |
| 292 | - if(!$this->xValidator->validateClass($sRequestedClass) || |
|
| 292 | + if (!$this->xValidator->validateClass($sRequestedClass) || |
|
| 293 | 293 | !$this->xValidator->validateMethod($sRequestedMethod)) |
| 294 | 294 | { |
| 295 | 295 | // Unable to find the requested object or method |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $xCallableObject = $this->xRegistry->getCallableObject($sRequestedClass); |
| 304 | 304 | return $xCallableObject->call($sRequestedMethod, $this->xParameterReader->args()); |
| 305 | 305 | } |
| 306 | - catch(ReflectionException|SetupException $e) |
|
| 306 | + catch (ReflectionException | SetupException $e) |
|
| 307 | 307 | { |
| 308 | 308 | // Unable to find the requested class or method |
| 309 | 309 | $this->di->getLogger()->error($e->getMessage()); |
@@ -140,8 +140,7 @@ discard block |
||
| 140 | 140 | if(is_string($xOptions)) |
| 141 | 141 | { |
| 142 | 142 | $xOptions = ['include' => $xOptions]; |
| 143 | - } |
|
| 144 | - elseif(!is_array($xOptions)) |
|
| 143 | + } elseif(!is_array($xOptions)) |
|
| 145 | 144 | { |
| 146 | 145 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 147 | 146 | } |
@@ -302,8 +301,7 @@ discard block |
||
| 302 | 301 | { |
| 303 | 302 | $xCallableObject = $this->xRegistry->getCallableObject($sRequestedClass); |
| 304 | 303 | return $xCallableObject->call($sRequestedMethod, $this->xParameterReader->args()); |
| 305 | - } |
|
| 306 | - catch(ReflectionException|SetupException $e) |
|
| 304 | + } catch(ReflectionException|SetupException $e) |
|
| 307 | 305 | { |
| 308 | 306 | // Unable to find the requested class or method |
| 309 | 307 | $this->di->getLogger()->error($e->getMessage()); |
@@ -207,36 +207,36 @@ |
||
| 207 | 207 | switch($sName) |
| 208 | 208 | { |
| 209 | 209 | // Set the separator |
| 210 | - case 'separator': |
|
| 211 | - if($xValue === '_' || $xValue === '.') |
|
| 212 | - { |
|
| 213 | - $this->sSeparator = $xValue; |
|
| 214 | - } |
|
| 215 | - break; |
|
| 216 | - // Set the protected methods |
|
| 217 | - case 'protected': |
|
| 218 | - if(is_array($xValue)) |
|
| 219 | - { |
|
| 220 | - $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
| 221 | - } |
|
| 222 | - break; |
|
| 223 | - // Set the methods to call before processing the request |
|
| 224 | - case '__before': |
|
| 225 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 226 | - break; |
|
| 227 | - // Set the methods to call after processing the request |
|
| 228 | - case '__after': |
|
| 229 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 230 | - break; |
|
| 231 | - // Set the attributes to inject in the callable object |
|
| 232 | - case '__di': |
|
| 233 | - $this->aAttributes = array_merge($this->aAttributes, $xValue); |
|
| 234 | - break; |
|
| 235 | - case 'excluded': |
|
| 236 | - $this->bExcluded = (bool)$xValue; |
|
| 237 | - break; |
|
| 238 | - default: |
|
| 239 | - break; |
|
| 210 | + case 'separator': |
|
| 211 | + if($xValue === '_' || $xValue === '.') |
|
| 212 | + { |
|
| 213 | + $this->sSeparator = $xValue; |
|
| 214 | + } |
|
| 215 | + break; |
|
| 216 | + // Set the protected methods |
|
| 217 | + case 'protected': |
|
| 218 | + if(is_array($xValue)) |
|
| 219 | + { |
|
| 220 | + $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
| 221 | + } |
|
| 222 | + break; |
|
| 223 | + // Set the methods to call before processing the request |
|
| 224 | + case '__before': |
|
| 225 | + $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 226 | + break; |
|
| 227 | + // Set the methods to call after processing the request |
|
| 228 | + case '__after': |
|
| 229 | + $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 230 | + break; |
|
| 231 | + // Set the attributes to inject in the callable object |
|
| 232 | + case '__di': |
|
| 233 | + $this->aAttributes = array_merge($this->aAttributes, $xValue); |
|
| 234 | + break; |
|
| 235 | + case 'excluded': |
|
| 236 | + $this->bExcluded = (bool)$xValue; |
|
| 237 | + break; |
|
| 238 | + default: |
|
| 239 | + break; |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | private function setHookMethods(array &$aHookMethods, $xValue) |
| 183 | 183 | { |
| 184 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 184 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 185 | 185 | { |
| 186 | - if(is_array($xMethodToCall)) |
|
| 186 | + if (is_array($xMethodToCall)) |
|
| 187 | 187 | { |
| 188 | 188 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
| 189 | 189 | } |
| 190 | - elseif(is_string($xMethodToCall)) |
|
| 190 | + elseif (is_string($xMethodToCall)) |
|
| 191 | 191 | { |
| 192 | 192 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
| 193 | 193 | } |
@@ -204,18 +204,18 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function configure(string $sName, $xValue) |
| 206 | 206 | { |
| 207 | - switch($sName) |
|
| 207 | + switch ($sName) |
|
| 208 | 208 | { |
| 209 | 209 | // Set the separator |
| 210 | 210 | case 'separator': |
| 211 | - if($xValue === '_' || $xValue === '.') |
|
| 211 | + if ($xValue === '_' || $xValue === '.') |
|
| 212 | 212 | { |
| 213 | 213 | $this->sSeparator = $xValue; |
| 214 | 214 | } |
| 215 | 215 | break; |
| 216 | 216 | // Set the protected methods |
| 217 | 217 | case 'protected': |
| 218 | - if(is_array($xValue)) |
|
| 218 | + if (is_array($xValue)) |
|
| 219 | 219 | { |
| 220 | 220 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
| 221 | 221 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $this->aAttributes = array_merge($this->aAttributes, $xValue); |
| 234 | 234 | break; |
| 235 | 235 | case 'excluded': |
| 236 | - $this->bExcluded = (bool)$xValue; |
|
| 236 | + $this->bExcluded = (bool) $xValue; |
|
| 237 | 237 | break; |
| 238 | 238 | default: |
| 239 | 239 | break; |
@@ -339,11 +339,11 @@ discard block |
||
| 339 | 339 | private function callHookMethods(array $aHookMethods, string $sMethod) |
| 340 | 340 | { |
| 341 | 341 | $aMethods = $aHookMethods[$sMethod] ?? $aHookMethods['*'] ?? []; |
| 342 | - foreach($aMethods as $xKey => $xValue) |
|
| 342 | + foreach ($aMethods as $xKey => $xValue) |
|
| 343 | 343 | { |
| 344 | 344 | $sMethodName = $xValue; |
| 345 | 345 | $aMethodArgs = []; |
| 346 | - if(is_string($xKey)) |
|
| 346 | + if (is_string($xKey)) |
|
| 347 | 347 | { |
| 348 | 348 | $sMethodName = $xKey; |
| 349 | 349 | $aMethodArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | // Set attributes from the DI container |
| 370 | 370 | $aAttributes = $this->aAttributes[$sMethod] ?? $this->aAttributes['*'] ?? []; |
| 371 | - foreach($aAttributes as $sName => $sClass) |
|
| 371 | + foreach ($aAttributes as $sName => $sClass) |
|
| 372 | 372 | { |
| 373 | 373 | // Warning: dynamic properties will be deprecated in PHP8.2. |
| 374 | 374 | $this->xRegisteredObject->$sName = $this->di->get($sClass); |
@@ -186,8 +186,7 @@ |
||
| 186 | 186 | if(is_array($xMethodToCall)) |
| 187 | 187 | { |
| 188 | 188 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
| 189 | - } |
|
| 190 | - elseif(is_string($xMethodToCall)) |
|
| 189 | + } elseif(is_string($xMethodToCall)) |
|
| 191 | 190 | { |
| 192 | 191 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
| 193 | 192 | } |