@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | private function setDiAttributes($xRegisteredObject, array $aDiOptions) |
| 35 | 35 | { |
| 36 | - foreach($aDiOptions as $sName => $sClass) |
|
| 36 | + foreach ($aDiOptions as $sName => $sClass) |
|
| 37 | 37 | { |
| 38 | 38 | // Set the protected attributes of the object |
| 39 | 39 | $cSetter = function($xInjectedObject) use($sName) { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $this->setDiAttributes($xRegisteredObject, $aDiOptions); |
| 64 | 64 | |
| 65 | 65 | // Set the Jaxon request target in the helper |
| 66 | - if($xRegisteredObject instanceof CallableClass) |
|
| 66 | + if ($xRegisteredObject instanceof CallableClass) |
|
| 67 | 67 | { |
| 68 | 68 | // Set the protected attributes of the object |
| 69 | 69 | $cSetter = function() use($xTarget) { |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | $sReflectionClass = $sClassName . '_ReflectionClass'; |
| 92 | 92 | |
| 93 | 93 | // Prevent duplication |
| 94 | - if($this->h($sReflectionClass)) // It's important not to use the class name here. |
|
| 94 | + if ($this->h($sReflectionClass)) // It's important not to use the class name here. |
|
| 95 | 95 | { |
| 96 | 96 | return; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Make sure the registered class exists |
| 100 | - if(isset($aOptions['include'])) |
|
| 100 | + if (isset($aOptions['include'])) |
|
| 101 | 101 | { |
| 102 | 102 | require_once($aOptions['include']); |
| 103 | 103 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | { |
| 107 | 107 | $this->val($sReflectionClass, new ReflectionClass($sClassName)); |
| 108 | 108 | } |
| 109 | - catch(ReflectionException $e) |
|
| 109 | + catch (ReflectionException $e) |
|
| 110 | 110 | { |
| 111 | 111 | $xTranslator = $this->g(Translator::class); |
| 112 | 112 | $sMessage = $xTranslator->trans('errors.class.invalid', ['name' => $sClassName]); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | }); |
| 131 | 131 | |
| 132 | 132 | // Register the user class, but only if the user already didn't. |
| 133 | - if(!$this->h($sClassName)) |
|
| 133 | + if (!$this->h($sClassName)) |
|
| 134 | 134 | { |
| 135 | 135 | $this->set($sClassName, function($c) use($sReflectionClass) { |
| 136 | 136 | return $this->make($c->g($sReflectionClass)); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | // Initialize the user class instance |
| 140 | 140 | $this->extend($sClassName, function($xRegisteredObject, $c) use($sCallableObject, $sClassName) { |
| 141 | - if($xRegisteredObject instanceof CallableClass) |
|
| 141 | + if ($xRegisteredObject instanceof CallableClass) |
|
| 142 | 142 | { |
| 143 | 143 | // Set the protected attributes of the object |
| 144 | 144 | $cSetter = function($c, $sClassName) { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Run the callbacks for class initialisation |
| 153 | 153 | $aCallbacks = $c->g(CallbackManager::class)->getInitCallbacks(); |
| 154 | - foreach($aCallbacks as $xCallback) |
|
| 154 | + foreach ($aCallbacks as $xCallback) |
|
| 155 | 155 | { |
| 156 | 156 | call_user_func($xCallback, $xRegisteredObject); |
| 157 | 157 | } |
@@ -173,36 +173,36 @@ discard block |
||
| 173 | 173 | switch($sName) |
| 174 | 174 | { |
| 175 | 175 | // Set the separator |
| 176 | - case 'separator': |
|
| 177 | - if($xValue === '_' || $xValue === '.') |
|
| 178 | - { |
|
| 179 | - $this->sSeparator = $xValue; |
|
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - // Set the protected methods |
|
| 183 | - case 'protected': |
|
| 184 | - if(is_array($xValue)) |
|
| 185 | - { |
|
| 186 | - $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
| 187 | - } |
|
| 188 | - break; |
|
| 189 | - // Set the methods to call before processing the request |
|
| 190 | - case '__before': |
|
| 191 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 192 | - break; |
|
| 193 | - // Set the methods to call after processing the request |
|
| 194 | - case '__after': |
|
| 195 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 196 | - break; |
|
| 197 | - // Set the attributes to inject in the callable object |
|
| 198 | - case '__di': |
|
| 199 | - $this->addDiOption($xValue); |
|
| 200 | - break; |
|
| 201 | - case 'excluded': |
|
| 202 | - $this->bExcluded = (bool)$xValue; |
|
| 203 | - break; |
|
| 204 | - default: |
|
| 205 | - break; |
|
| 176 | + case 'separator': |
|
| 177 | + if($xValue === '_' || $xValue === '.') |
|
| 178 | + { |
|
| 179 | + $this->sSeparator = $xValue; |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + // Set the protected methods |
|
| 183 | + case 'protected': |
|
| 184 | + if(is_array($xValue)) |
|
| 185 | + { |
|
| 186 | + $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
| 187 | + } |
|
| 188 | + break; |
|
| 189 | + // Set the methods to call before processing the request |
|
| 190 | + case '__before': |
|
| 191 | + $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 192 | + break; |
|
| 193 | + // Set the methods to call after processing the request |
|
| 194 | + case '__after': |
|
| 195 | + $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 196 | + break; |
|
| 197 | + // Set the attributes to inject in the callable object |
|
| 198 | + case '__di': |
|
| 199 | + $this->addDiOption($xValue); |
|
| 200 | + break; |
|
| 201 | + case 'excluded': |
|
| 202 | + $this->bExcluded = (bool)$xValue; |
|
| 203 | + break; |
|
| 204 | + default: |
|
| 205 | + break; |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | switch($sOptionName) |
| 252 | 252 | { |
| 253 | 253 | // For databags, all the value are merged in a single array. |
| 254 | - case 'bags': |
|
| 255 | - $this->_addJsArrayOption($sFunctionName, $sOptionName, $xOptionValue); |
|
| 256 | - return; |
|
| 257 | - // For all the other options, including callback, only the last value is kept. |
|
| 258 | - case 'callback': |
|
| 259 | - default: |
|
| 260 | - $this->_setJsOption($sFunctionName, $sOptionName, $xOptionValue); |
|
| 254 | + case 'bags': |
|
| 255 | + $this->_addJsArrayOption($sFunctionName, $sOptionName, $xOptionValue); |
|
| 256 | + return; |
|
| 257 | + // For all the other options, including callback, only the last value is kept. |
|
| 258 | + case 'callback': |
|
| 259 | + default: |
|
| 260 | + $this->_setJsOption($sFunctionName, $sOptionName, $xOptionValue); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | private function setHookMethods(array &$aHookMethods, $xValue) |
| 141 | 141 | { |
| 142 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 142 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 143 | 143 | { |
| 144 | - if(is_array($xMethodToCall)) |
|
| 144 | + if (is_array($xMethodToCall)) |
|
| 145 | 145 | { |
| 146 | 146 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
| 147 | 147 | } |
| 148 | - elseif(is_string($xMethodToCall)) |
|
| 148 | + elseif (is_string($xMethodToCall)) |
|
| 149 | 149 | { |
| 150 | 150 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
| 151 | 151 | } |
@@ -170,18 +170,18 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function addOption(string $sName, $xValue) |
| 172 | 172 | { |
| 173 | - switch($sName) |
|
| 173 | + switch ($sName) |
|
| 174 | 174 | { |
| 175 | 175 | // Set the separator |
| 176 | 176 | case 'separator': |
| 177 | - if($xValue === '_' || $xValue === '.') |
|
| 177 | + if ($xValue === '_' || $xValue === '.') |
|
| 178 | 178 | { |
| 179 | 179 | $this->sSeparator = $xValue; |
| 180 | 180 | } |
| 181 | 181 | break; |
| 182 | 182 | // Set the protected methods |
| 183 | 183 | case 'protected': |
| 184 | - if(is_array($xValue)) |
|
| 184 | + if (is_array($xValue)) |
|
| 185 | 185 | { |
| 186 | 186 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
| 187 | 187 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $this->addDiOption($xValue); |
| 200 | 200 | break; |
| 201 | 201 | case 'excluded': |
| 202 | - $this->bExcluded = (bool)$xValue; |
|
| 202 | + $this->bExcluded = (bool) $xValue; |
|
| 203 | 203 | break; |
| 204 | 204 | default: |
| 205 | 205 | break; |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
| 217 | 217 | { |
| 218 | - if(is_string($xOptionValue)) |
|
| 218 | + if (is_string($xOptionValue)) |
|
| 219 | 219 | { |
| 220 | 220 | $xOptionValue = [$xOptionValue]; |
| 221 | 221 | } |
| 222 | - if(!is_array($xOptionValue)) |
|
| 222 | + if (!is_array($xOptionValue)) |
|
| 223 | 223 | { |
| 224 | 224 | return; // Do not save. |
| 225 | 225 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
| 250 | 250 | { |
| 251 | - switch($sOptionName) |
|
| 251 | + switch ($sOptionName) |
|
| 252 | 252 | { |
| 253 | 253 | // For databags, all the value are merged in a single array. |
| 254 | 254 | case 'bags': |
@@ -269,12 +269,11 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions) |
| 271 | 271 | { |
| 272 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 272 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 273 | 273 | { |
| 274 | 274 | substr($sOptionName, 0, 2) === '__' ? |
| 275 | 275 | // Options for PHP classes. They start with "__". |
| 276 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 277 | - // Options for javascript code. |
|
| 276 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 278 | 277 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 279 | 278 | } |
| 280 | 279 | } |
@@ -292,15 +291,15 @@ discard block |
||
| 292 | 291 | $this->addOption('separator', $aOptions['separator']); |
| 293 | 292 | $this->addOption('protected', array_merge($aOptions['protected'], $aAnnotationProtected)); |
| 294 | 293 | |
| 295 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 294 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 296 | 295 | { |
| 297 | 296 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
| 298 | - foreach($aFunctionNames as $sFunctionName) |
|
| 297 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 299 | 298 | { |
| 300 | 299 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 301 | 300 | } |
| 302 | 301 | } |
| 303 | - foreach($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 302 | + foreach ($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
| 304 | 303 | { |
| 305 | 304 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 306 | 305 | } |
@@ -317,12 +316,11 @@ discard block |
||
| 317 | 316 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 318 | 317 | // Then add the method options. |
| 319 | 318 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 320 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 319 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 321 | 320 | { |
| 322 | 321 | // For databags, merge the values in a single array. |
| 323 | 322 | // For all the other options, including callback, keep the last value. |
| 324 | - $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : |
|
| 325 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 323 | + $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 326 | 324 | } |
| 327 | 325 | return $aOptions; |
| 328 | 326 | } |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | $aMethods = $this->getPublicMethods($aProtectedMethods); |
| 114 | 114 | $aProperties = $this->getProperties(); |
| 115 | 115 | $aAnnotations = $xAnnotationReader->getAttributes($sClassName, $aMethods, $aProperties); |
| 116 | - [$bExcluded,] = $aAnnotations; |
|
| 117 | - if($bExcluded) |
|
| 116 | + [$bExcluded, ] = $aAnnotations; |
|
| 117 | + if ($bExcluded) |
|
| 118 | 118 | { |
| 119 | 119 | $this->configure('excluded', true); |
| 120 | 120 | return; |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | $sMethod = $this->xTarget->getMethodName(); |
| 305 | 305 | // The hooks defined at method level are merged with those defined at class level. |
| 306 | 306 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
| 307 | - foreach($aMethods as $xKey => $xValue) |
|
| 307 | + foreach ($aMethods as $xKey => $xValue) |
|
| 308 | 308 | { |
| 309 | 309 | $sHookName = $xValue; |
| 310 | 310 | $aHookArgs = []; |
| 311 | - if(is_string($xKey)) |
|
| 311 | + if (is_string($xKey)) |
|
| 312 | 312 | { |
| 313 | 313 | $sHookName = $xKey; |
| 314 | 314 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |