@@ -124,28 +124,28 @@ discard block |
||
124 | 124 | { |
125 | 125 | $bIsUsed = false; |
126 | 126 | $aInterfaces = class_implements($sClassName); |
127 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
127 | + if (in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
128 | 128 | { |
129 | 129 | $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
130 | 130 | $bIsUsed = true; |
131 | 131 | } |
132 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
132 | + if (in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
133 | 133 | { |
134 | 134 | $this->aRegistryPlugins[$sPluginName] = $sClassName; |
135 | 135 | $bIsUsed = true; |
136 | 136 | } |
137 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
137 | + if (in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
138 | 138 | { |
139 | 139 | $this->aRequestHandlers[$sPluginName] = $sClassName; |
140 | 140 | $bIsUsed = true; |
141 | 141 | } |
142 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
142 | + if (in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
143 | 143 | { |
144 | 144 | $this->aResponsePlugins[$sPluginName] = $sClassName; |
145 | 145 | $bIsUsed = true; |
146 | 146 | } |
147 | 147 | |
148 | - if(!$bIsUsed) |
|
148 | + if (!$bIsUsed) |
|
149 | 149 | { |
150 | 150 | // The class is invalid. |
151 | 151 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | // Register the plugin in the DI container, if necessary |
156 | - if(!$this->di->has($sClassName)) |
|
156 | + if (!$this->di->has($sClassName)) |
|
157 | 157 | { |
158 | 158 | $this->di->auto($sClassName); |
159 | 159 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function registerCallable(string $sType, string $sCallable, $xOptions = []) |
188 | 188 | { |
189 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
189 | + if (isset($this->aRegistryPlugins[$sType]) && |
|
190 | 190 | ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
191 | 191 | { |
192 | 192 | $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
@@ -27,6 +27,6 @@ |
||
27 | 27 | * |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public function getAttributes(ReflectionClass|string $xReflectionClass, |
|
30 | + public function getAttributes(ReflectionClass | string $xReflectionClass, |
|
31 | 31 | array $aMethods = [], array $aProperties = []): array; |
32 | 32 | } |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function checkOptions(string $sCallable, $xOptions): array |
83 | 83 | { |
84 | - if(!$this->xValidator->validateClass(trim($sCallable))) |
|
84 | + if (!$this->xValidator->validateClass(trim($sCallable))) |
|
85 | 85 | { |
86 | 86 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
87 | 87 | } |
88 | - if(is_string($xOptions)) |
|
88 | + if (is_string($xOptions)) |
|
89 | 89 | { |
90 | 90 | $xOptions = ['include' => $xOptions]; |
91 | 91 | } |
92 | - elseif(!is_array($xOptions)) |
|
92 | + elseif (!is_array($xOptions)) |
|
93 | 93 | { |
94 | 94 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
95 | 95 | } |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | { |
134 | 134 | $sCode = ''; |
135 | 135 | $aJsClasses = []; |
136 | - foreach($this->xRegistry->getNamespaces() as $sNamespace) |
|
136 | + foreach ($this->xRegistry->getNamespaces() as $sNamespace) |
|
137 | 137 | { |
138 | 138 | $offset = 0; |
139 | 139 | $sJsNamespace = str_replace('\\', '.', $sNamespace); |
140 | 140 | $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop. |
141 | - while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
141 | + while (($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
142 | 142 | { |
143 | 143 | $sJsClass = substr($sJsNamespace, 0, $dotPosition); |
144 | 144 | // Generate code for this object |
145 | - if(!isset($aJsClasses[$sJsClass])) |
|
145 | + if (!isset($aJsClasses[$sJsClass])) |
|
146 | 146 | { |
147 | 147 | $sCode .= $this->sPrefix . "$sJsClass = {};\n"; |
148 | 148 | $aJsClasses[$sJsClass] = $sJsClass; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | private function getCallableScript(CallableObject $xCallableObject): string |
164 | 164 | { |
165 | - if($xCallableObject->excluded()) |
|
165 | + if ($xCallableObject->excluded()) |
|
166 | 166 | { |
167 | 167 | return ''; |
168 | 168 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
201 | 201 | { |
202 | 202 | $aBody = $xRequest->getParsedBody(); |
203 | - if(is_array($aBody)) |
|
203 | + if (is_array($aBody)) |
|
204 | 204 | { |
205 | 205 | return isset($aBody['jxncls']) && isset($aBody['jxnmthd']); |
206 | 206 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | public function setTarget(ServerRequestInterface $xRequest) |
215 | 215 | { |
216 | 216 | $aBody = $xRequest->getParsedBody(); |
217 | - if(is_array($aBody)) |
|
217 | + if (is_array($aBody)) |
|
218 | 218 | { |
219 | 219 | $this->xTarget = Target::makeClass(trim($aBody['jxncls']), trim($aBody['jxnmthd'])); |
220 | 220 | return; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $sMethodName = $this->xTarget->getMethodName(); |
234 | 234 | $this->xTarget->setMethodArgs($this->xParameterReader->args()); |
235 | 235 | |
236 | - if(!$this->xValidator->validateClass($sClassName) || !$this->xValidator->validateMethod($sMethodName)) |
|
236 | + if (!$this->xValidator->validateClass($sClassName) || !$this->xValidator->validateMethod($sMethodName)) |
|
237 | 237 | { |
238 | 238 | // Unable to find the requested object or method |
239 | 239 | throw new RequestException($this->xTranslator->trans('errors.objects.invalid', |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | { |
246 | 246 | return $this->getCallable($sClassName)->call($this->xTarget); |
247 | 247 | } |
248 | - catch(ReflectionException|SetupException $e) |
|
248 | + catch (ReflectionException | SetupException $e) |
|
249 | 249 | { |
250 | 250 | // Unable to find the requested class or method |
251 | 251 | $this->di->getLogger()->error($e->getMessage()); |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | if(is_string($xOptions)) |
89 | 89 | { |
90 | 90 | $xOptions = ['include' => $xOptions]; |
91 | - } |
|
92 | - elseif(!is_array($xOptions)) |
|
91 | + } elseif(!is_array($xOptions)) |
|
93 | 92 | { |
94 | 93 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
95 | 94 | } |
@@ -244,8 +243,7 @@ discard block |
||
244 | 243 | try |
245 | 244 | { |
246 | 245 | return $this->getCallable($sClassName)->call($this->xTarget); |
247 | - } |
|
248 | - catch(ReflectionException|SetupException $e) |
|
246 | + } catch(ReflectionException|SetupException $e) |
|
249 | 247 | { |
250 | 248 | // Unable to find the requested class or method |
251 | 249 | $this->di->getLogger()->error($e->getMessage()); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | public function __construct(protected ClassContainer $cls) |
121 | 121 | { |
122 | 122 | // Set the composer autoloader |
123 | - if(file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
123 | + if (file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
124 | 124 | file_exists(($sAutoloadFile = __DIR__ . '/../../../../../vendor/autoload.php')) || |
125 | 125 | file_exists(($sAutoloadFile = __DIR__ . '/../../../../vendor/autoload.php'))) |
126 | 126 | { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | // The methods of the AbstractCallable class must not be exported |
131 | 131 | $xAbstractCallable = new ReflectionClass(AbstractCallable::class); |
132 | - foreach($xAbstractCallable->getMethods(ReflectionMethod::IS_PUBLIC) as $xMethod) |
|
132 | + foreach ($xAbstractCallable->getMethods(ReflectionMethod::IS_PUBLIC) as $xMethod) |
|
133 | 133 | { |
134 | 134 | $this->aProtectedMethods[] = $xMethod->getName(); |
135 | 135 | } |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | */ |
177 | 177 | private function makeClassOptions(string $sClassName, array $aClassOptions, array $aDirectoryOptions): array |
178 | 178 | { |
179 | - foreach($this->aDefaultClassOptions as $sOption => $xValue) |
|
179 | + foreach ($this->aDefaultClassOptions as $sOption => $xValue) |
|
180 | 180 | { |
181 | - if(!isset($aClassOptions[$sOption])) |
|
181 | + if (!isset($aClassOptions[$sOption])) |
|
182 | 182 | { |
183 | 183 | $aClassOptions[$sOption] = $xValue; |
184 | 184 | } |
185 | 185 | } |
186 | - $aClassOptions['excluded'] = (bool)($aClassOptions['excluded'] ?? false); // Convert to bool. |
|
187 | - if(is_string($aClassOptions['protected'])) |
|
186 | + $aClassOptions['excluded'] = (bool) ($aClassOptions['excluded'] ?? false); // Convert to bool. |
|
187 | + if (is_string($aClassOptions['protected'])) |
|
188 | 188 | { |
189 | 189 | $aClassOptions['protected'] = [$aClassOptions['protected']]; // Convert to array. |
190 | 190 | } |
@@ -195,30 +195,30 @@ discard block |
||
195 | 195 | $aDirectoryOptions['classes']['*'] ?? [], // Options for all classes |
196 | 196 | $aDirectoryOptions['classes'][$sClassName] ?? [], // Options for this specific class |
197 | 197 | ]; |
198 | - foreach($aOptionGroups as $aOptionGroup) |
|
198 | + foreach ($aOptionGroups as $aOptionGroup) |
|
199 | 199 | { |
200 | - if(isset($aOptionGroup['separator'])) |
|
200 | + if (isset($aOptionGroup['separator'])) |
|
201 | 201 | { |
202 | - $aClassOptions['separator'] = (string)$aOptionGroup['separator']; |
|
202 | + $aClassOptions['separator'] = (string) $aOptionGroup['separator']; |
|
203 | 203 | } |
204 | - if(isset($aOptionGroup['excluded'])) |
|
204 | + if (isset($aOptionGroup['excluded'])) |
|
205 | 205 | { |
206 | - $aClassOptions['excluded'] = (bool)$aOptionGroup['excluded']; |
|
206 | + $aClassOptions['excluded'] = (bool) $aOptionGroup['excluded']; |
|
207 | 207 | } |
208 | - if(isset($aOptionGroup['protected'])) |
|
208 | + if (isset($aOptionGroup['protected'])) |
|
209 | 209 | { |
210 | - if(is_string($aOptionGroup['protected'])) |
|
210 | + if (is_string($aOptionGroup['protected'])) |
|
211 | 211 | { |
212 | 212 | $aOptionGroup['protected'] = [$aOptionGroup['protected']]; // Convert to array. |
213 | 213 | } |
214 | 214 | $aClassOptions['protected'] = array_merge($aClassOptions['protected'], $aOptionGroup['protected']); |
215 | 215 | } |
216 | - if(isset($aOptionGroup['functions'])) |
|
216 | + if (isset($aOptionGroup['functions'])) |
|
217 | 217 | { |
218 | 218 | $aClassOptions['functions'] = array_merge($aClassOptions['functions'], $aOptionGroup['functions']); |
219 | 219 | } |
220 | 220 | } |
221 | - if(isset($aDirectoryOptions['config']) && !isset($aClassOptions['config'])) |
|
221 | + if (isset($aDirectoryOptions['config']) && !isset($aClassOptions['config'])) |
|
222 | 222 | { |
223 | 223 | $aClassOptions['config'] = $aDirectoryOptions['config']; |
224 | 224 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function addClass(string $sClassName, array $aClassOptions) |
252 | 252 | { |
253 | - if($this->xCurrentConfig !== null) |
|
253 | + if ($this->xCurrentConfig !== null) |
|
254 | 254 | { |
255 | 255 | $aClassOptions['config'] = $this->xCurrentConfig; |
256 | 256 | } |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | public function setNamespaceClassOptions(string $sClassName) |
268 | 268 | { |
269 | 269 | // Find the corresponding namespace |
270 | - foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
270 | + foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
271 | 271 | { |
272 | 272 | // Check if the namespace matches the class. |
273 | - if(strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
273 | + if (strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
274 | 274 | { |
275 | 275 | // Save the class options |
276 | 276 | $aClassOptions = ['namespace' => $sNamespace]; |
@@ -292,8 +292,7 @@ discard block |
||
292 | 292 | { |
293 | 293 | // Don't export the item() and html() public methods for Component objects. |
294 | 294 | return is_subclass_of($sClassName, Component::class) ? |
295 | - [...$this->aProtectedMethods, 'item', 'html'] : |
|
296 | - (is_subclass_of($sClassName, AbstractCallable::class) ? |
|
295 | + [...$this->aProtectedMethods, 'item', 'html'] : (is_subclass_of($sClassName, AbstractCallable::class) ? |
|
297 | 296 | $this->aProtectedMethods : []); |
298 | 297 | } |
299 | 298 | |
@@ -307,11 +306,11 @@ discard block |
||
307 | 306 | public function addDirectory(string $sDirectory, array $aOptions) |
308 | 307 | { |
309 | 308 | // Set the autoload option default value |
310 | - if(!isset($aOptions['autoload'])) |
|
309 | + if (!isset($aOptions['autoload'])) |
|
311 | 310 | { |
312 | 311 | $aOptions['autoload'] = true; |
313 | 312 | } |
314 | - if($this->xCurrentConfig !== null) |
|
313 | + if ($this->xCurrentConfig !== null) |
|
315 | 314 | { |
316 | 315 | $aOptions['config'] = $this->xCurrentConfig; |
317 | 316 | } |
@@ -341,30 +340,30 @@ discard block |
||
341 | 340 | public function addNamespace(string $sNamespace, array $aOptions) |
342 | 341 | { |
343 | 342 | // Separator default value |
344 | - if(!isset($aOptions['separator'])) |
|
343 | + if (!isset($aOptions['separator'])) |
|
345 | 344 | { |
346 | 345 | $aOptions['separator'] = '.'; |
347 | 346 | } |
348 | 347 | $aOptions['separator'] = trim($aOptions['separator']); |
349 | - if(!in_array($aOptions['separator'], ['.', '_'])) |
|
348 | + if (!in_array($aOptions['separator'], ['.', '_'])) |
|
350 | 349 | { |
351 | 350 | $aOptions['separator'] = '.'; |
352 | 351 | } |
353 | - if($aOptions['separator'] === '_') |
|
352 | + if ($aOptions['separator'] === '_') |
|
354 | 353 | { |
355 | 354 | $this->cls->useUnderscore(); |
356 | 355 | } |
357 | 356 | // Set the autoload option default value |
358 | - if(!isset($aOptions['autoload'])) |
|
357 | + if (!isset($aOptions['autoload'])) |
|
359 | 358 | { |
360 | 359 | $aOptions['autoload'] = true; |
361 | 360 | } |
362 | - if($this->xCurrentConfig !== null) |
|
361 | + if ($this->xCurrentConfig !== null) |
|
363 | 362 | { |
364 | 363 | $aOptions['config'] = $this->xCurrentConfig; |
365 | 364 | } |
366 | 365 | // Register the dir with PSR4 autoloading |
367 | - if(($aOptions['autoload']) && $this->xAutoloader != null) |
|
366 | + if (($aOptions['autoload']) && $this->xAutoloader != null) |
|
368 | 367 | { |
369 | 368 | $this->xAutoloader->setPsr4($sNamespace . '\\', $aOptions['directory']); |
370 | 369 | } |
@@ -380,7 +379,7 @@ discard block |
||
380 | 379 | public function parseDirectories() |
381 | 380 | { |
382 | 381 | // This is to be done only once. |
383 | - if($this->bDirectoriesParsed) |
|
382 | + if ($this->bDirectoriesParsed) |
|
384 | 383 | { |
385 | 384 | return; |
386 | 385 | } |
@@ -388,14 +387,14 @@ discard block |
||
388 | 387 | |
389 | 388 | // Browse directories without namespaces and read all the files. |
390 | 389 | $aClassMap = []; |
391 | - foreach($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions) |
|
390 | + foreach ($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions) |
|
392 | 391 | { |
393 | 392 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
394 | 393 | // Iterate on dir content |
395 | - foreach($itFile as $xFile) |
|
394 | + foreach ($itFile as $xFile) |
|
396 | 395 | { |
397 | 396 | // Skip everything except PHP files |
398 | - if(!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
397 | + if (!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
399 | 398 | { |
400 | 399 | continue; |
401 | 400 | } |
@@ -403,7 +402,7 @@ discard block |
||
403 | 402 | $sClassName = $xFile->getBasename('.php'); |
404 | 403 | $aClassOptions = ['timestamp' => $xFile->getMTime()]; |
405 | 404 | // No more custom classmap autoloading. The file will be included when needed. |
406 | - if(($aDirectoryOptions['autoload'])) |
|
405 | + if (($aDirectoryOptions['autoload'])) |
|
407 | 406 | { |
408 | 407 | $aClassMap[$sClassName] = $xFile->getPathname(); |
409 | 408 | } |
@@ -411,7 +410,7 @@ discard block |
||
411 | 410 | } |
412 | 411 | } |
413 | 412 | // Set classmap autoloading |
414 | - if(($aClassMap) && $this->xAutoloader !== null) |
|
413 | + if (($aClassMap) && $this->xAutoloader !== null) |
|
415 | 414 | { |
416 | 415 | $this->xAutoloader->addClassMap($aClassMap); |
417 | 416 | } |
@@ -425,7 +424,7 @@ discard block |
||
425 | 424 | public function parseNamespaces() |
426 | 425 | { |
427 | 426 | // This is to be done only once. |
428 | - if($this->bNamespacesParsed) |
|
427 | + if ($this->bNamespacesParsed) |
|
429 | 428 | { |
430 | 429 | return; |
431 | 430 | } |
@@ -433,17 +432,17 @@ discard block |
||
433 | 432 | |
434 | 433 | // Browse directories with namespaces and read all the files. |
435 | 434 | $sDS = DIRECTORY_SEPARATOR; |
436 | - foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
435 | + foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions) |
|
437 | 436 | { |
438 | 437 | $this->_addNamespace($sNamespace, ['separator' => $aDirectoryOptions['separator']]); |
439 | 438 | |
440 | 439 | // Iterate on dir content |
441 | 440 | $sDirectory = $aDirectoryOptions['directory']; |
442 | 441 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
443 | - foreach($itFile as $xFile) |
|
442 | + foreach ($itFile as $xFile) |
|
444 | 443 | { |
445 | 444 | // skip everything except PHP files |
446 | - if(!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
445 | + if (!$xFile->isFile() || $xFile->getExtension() !== 'php') |
|
447 | 446 | { |
448 | 447 | continue; |
449 | 448 | } |
@@ -452,7 +451,7 @@ discard block |
||
452 | 451 | $sClassPath = $sNamespace; |
453 | 452 | $sRelativePath = substr($xFile->getPath(), strlen($sDirectory)); |
454 | 453 | $sRelativePath = trim(str_replace($sDS, '\\', $sRelativePath), '\\'); |
455 | - if($sRelativePath !== '') |
|
454 | + if ($sRelativePath !== '') |
|
456 | 455 | { |
457 | 456 | $sClassPath .= '\\' . $sRelativePath; |
458 | 457 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | /** @var Config|null */ |
119 | 119 | $xConfig = $aOptions['config'] ?? null; |
120 | - if($xConfig === null) |
|
120 | + if ($xConfig === null) |
|
121 | 121 | { |
122 | 122 | return [false, [], []]; |
123 | 123 | } |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | $sMethod = $this->xTarget->getMethodName(); |
280 | 280 | // The hooks defined at method level are merged with those defined at class level. |
281 | 281 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
282 | - foreach($aMethods as $xKey => $xValue) |
|
282 | + foreach ($aMethods as $xKey => $xValue) |
|
283 | 283 | { |
284 | 284 | $sHookName = $xValue; |
285 | 285 | $aHookArgs = []; |
286 | - if(is_string($xKey)) |
|
286 | + if (is_string($xKey)) |
|
287 | 287 | { |
288 | 288 | $sHookName = $xKey; |
289 | 289 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | // Warning: dynamic properties will be deprecated in PHP8.2. |
306 | 306 | $this->$sName = $xInjectedObject; |
307 | 307 | }; |
308 | - foreach($aDiOptions as $sName => $sClass) |
|
308 | + foreach ($aDiOptions as $sName => $sClass) |
|
309 | 309 | { |
310 | 310 | // The setter has access to protected attributes |
311 | 311 | $_cSetter = $cSetter->bindTo($xRegisteredObject, $xRegisteredObject); |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | public function getRegisteredObject(?Target $xTarget = null) |
347 | 347 | { |
348 | 348 | $xRegisteredObject = $this->cls->get($this->getClassName()); |
349 | - if(!$xRegisteredObject || !$xTarget) |
|
349 | + if (!$xRegisteredObject || !$xTarget) |
|
350 | 350 | { |
351 | 351 | return $xRegisteredObject; |
352 | 352 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | // We now need to set the method level DI options. |
357 | 357 | $this->setDiMethodAttributes($xRegisteredObject, $xTarget->getMethodName()); |
358 | 358 | // Set the Jaxon request target in the helper |
359 | - if($xRegisteredObject instanceof AbstractCallable) |
|
359 | + if ($xRegisteredObject instanceof AbstractCallable) |
|
360 | 360 | { |
361 | 361 | // Set the protected attributes of the object |
362 | 362 | $sAttr = 'xHelper'; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | private function readImportedTypes() |
67 | 67 | { |
68 | 68 | $sClass = $this->xReflectionClass->getName(); |
69 | - if(isset($this->aImportedTypes[$sClass])) |
|
69 | + if (isset($this->aImportedTypes[$sClass])) |
|
70 | 70 | { |
71 | 71 | return; |
72 | 72 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | private function readPropertyTypes() |
83 | 83 | { |
84 | 84 | $sClass = $this->xReflectionClass->getName(); |
85 | - if(isset($this->aPropertyTypes[$sClass])) |
|
85 | + if (isset($this->aPropertyTypes[$sClass])) |
|
86 | 86 | { |
87 | 87 | return; |
88 | 88 | } |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | $this->aPropertyTypes[$sClass] = []; |
91 | 91 | $nFilter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED; |
92 | 92 | $aProperties = $this->xReflectionClass->getProperties($nFilter); |
93 | - foreach($aProperties as $xReflectionProperty) |
|
93 | + foreach ($aProperties as $xReflectionProperty) |
|
94 | 94 | { |
95 | 95 | $xType = $xReflectionProperty->getType(); |
96 | 96 | // Check that the property has a valid type defined |
97 | - if(is_a($xType, ReflectionNamedType::class) && $xType->getName() !== '') |
|
97 | + if (is_a($xType, ReflectionNamedType::class) && $xType->getName() !== '') |
|
98 | 98 | { |
99 | 99 | $this->aPropertyTypes[$sClass][$xReflectionProperty->getName()] = $xType->getName(); |
100 | 100 | } |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | $xInstance->setTarget($xAttribute->getTarget()); |
116 | 116 | $xInstance->setNamespace($this->xReflectionClass->getNamespaceName()); |
117 | 117 | $sName = $xInstance->getName(); |
118 | - if(is_a($xInstance, DiAttribute::class)) |
|
118 | + if (is_a($xInstance, DiAttribute::class)) |
|
119 | 119 | { |
120 | 120 | $sClass = $this->xReflectionClass->getName(); |
121 | 121 | $xInstance->setTypes($this->aImportedTypes[$sClass], $this->aPropertyTypes[$sClass]); |
122 | - if($sProperty !== '') |
|
122 | + if ($sProperty !== '') |
|
123 | 123 | { |
124 | 124 | $xInstance->setProperty($sProperty); |
125 | 125 | } |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | }); |
146 | 146 | |
147 | 147 | $aValues = []; |
148 | - foreach($aAttributes as $xAttribute) |
|
148 | + foreach ($aAttributes as $xAttribute) |
|
149 | 149 | { |
150 | 150 | [$sName, $xValue] = $this->getAttrValue($xAttribute, $aValues); |
151 | - if($sName !== 'protected' || ($xValue)) // Ignore attribute Exclude with value true |
|
151 | + if ($sName !== 'protected' || ($xValue)) // Ignore attribute Exclude with value true |
|
152 | 152 | { |
153 | 153 | $aValues[$sName] = $xValue; |
154 | 154 | } |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | }); |
174 | 174 | |
175 | 175 | $nCount = count($aAttributes); |
176 | - if($nCount === 0) |
|
176 | + if ($nCount === 0) |
|
177 | 177 | { |
178 | 178 | return ['', null]; |
179 | 179 | } |
180 | - if($nCount > 1) |
|
180 | + if ($nCount > 1) |
|
181 | 181 | { |
182 | 182 | throw new SetupException('Only one DI attribute is allowed on a property'); |
183 | 183 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @inheritDoc |
190 | 190 | * @throws SetupException |
191 | 191 | */ |
192 | - public function getAttributes(ReflectionClass|string $xReflectionClass, |
|
192 | + public function getAttributes(ReflectionClass | string $xReflectionClass, |
|
193 | 193 | array $aMethods = [], array $aProperties = []): array |
194 | 194 | { |
195 | 195 | $this->xReflectionClass = is_string($xReflectionClass) ? |
@@ -202,10 +202,10 @@ discard block |
||
202 | 202 | // Processing properties attributes |
203 | 203 | $aPropAttrs = []; |
204 | 204 | // Properties attributes |
205 | - foreach($aProperties as $sProperty) |
|
205 | + foreach ($aProperties as $sProperty) |
|
206 | 206 | { |
207 | 207 | [$sName, $xValue] = $this->getPropertyAttrValues($sProperty); |
208 | - if($xValue !== null) |
|
208 | + if ($xValue !== null) |
|
209 | 209 | { |
210 | 210 | $aPropAttrs[$sName] = array_merge($aPropAttrs[$sName] ?? [], $xValue); |
211 | 211 | } |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | |
214 | 214 | // Processing class attributes |
215 | 215 | $aClassAttrs = $this->getAttrValues($this->xReflectionClass->getAttributes()); |
216 | - if(isset($aClassAttrs['protected'])) |
|
216 | + if (isset($aClassAttrs['protected'])) |
|
217 | 217 | { |
218 | 218 | return [true, [], []]; // The entire class is not to be exported. |
219 | 219 | } |
220 | 220 | |
221 | 221 | // Merge attributes and class attributes |
222 | - foreach($aPropAttrs as $sName => $xValue) |
|
222 | + foreach ($aPropAttrs as $sName => $xValue) |
|
223 | 223 | { |
224 | 224 | $aClassAttrs[$sName] = array_merge($aClassAttrs[$sName] ?? [], $xValue); |
225 | 225 | } |
@@ -227,16 +227,16 @@ discard block |
||
227 | 227 | // Processing methods attributes |
228 | 228 | $aAttrValues = count($aClassAttrs) > 0 ? ['*' => $aClassAttrs] : []; |
229 | 229 | $aProtected = []; |
230 | - foreach($aMethods as $sMethod) |
|
230 | + foreach ($aMethods as $sMethod) |
|
231 | 231 | { |
232 | 232 | $aAttributes = $this->xReflectionClass->getMethod($sMethod)->getAttributes(); |
233 | 233 | $aMethodAttrs = $this->getAttrValues($aAttributes); |
234 | 234 | |
235 | - if(isset($aMethodAttrs['protected'])) |
|
235 | + if (isset($aMethodAttrs['protected'])) |
|
236 | 236 | { |
237 | 237 | $aProtected[] = $sMethod; // The method is not to be exported. |
238 | 238 | } |
239 | - elseif(count($aMethodAttrs) > 0) |
|
239 | + elseif (count($aMethodAttrs) > 0) |
|
240 | 240 | { |
241 | 241 | $aAttrValues[$sMethod] = $aMethodAttrs; |
242 | 242 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | return [false, $aAttrValues, $aProtected]; |
246 | 246 | } |
247 | - catch(Exception|Error $e) |
|
247 | + catch (Exception | Error $e) |
|
248 | 248 | { |
249 | 249 | throw new SetupException($e->getMessage()); |
250 | 250 | } |
@@ -148,10 +148,12 @@ discard block |
||
148 | 148 | foreach($aAttributes as $xAttribute) |
149 | 149 | { |
150 | 150 | [$sName, $xValue] = $this->getAttrValue($xAttribute, $aValues); |
151 | - if($sName !== 'protected' || ($xValue)) // Ignore attribute Exclude with value true |
|
151 | + if($sName !== 'protected' || ($xValue)) { |
|
152 | + // Ignore attribute Exclude with value true |
|
152 | 153 | { |
153 | 154 | $aValues[$sName] = $xValue; |
154 | 155 | } |
156 | + } |
|
155 | 157 | } |
156 | 158 | return $aValues; |
157 | 159 | } |
@@ -235,16 +237,14 @@ discard block |
||
235 | 237 | if(isset($aMethodAttrs['protected'])) |
236 | 238 | { |
237 | 239 | $aProtected[] = $sMethod; // The method is not to be exported. |
238 | - } |
|
239 | - elseif(count($aMethodAttrs) > 0) |
|
240 | + } elseif(count($aMethodAttrs) > 0) |
|
240 | 241 | { |
241 | 242 | $aAttrValues[$sMethod] = $aMethodAttrs; |
242 | 243 | } |
243 | 244 | } |
244 | 245 | |
245 | 246 | return [false, $aAttrValues, $aProtected]; |
246 | - } |
|
247 | - catch(Exception|Error $e) |
|
247 | + } catch(Exception|Error $e) |
|
248 | 248 | { |
249 | 249 | throw new SetupException($e->getMessage()); |
250 | 250 | } |
@@ -67,14 +67,14 @@ |
||
67 | 67 | |
68 | 68 | switch($xToken[0]) |
69 | 69 | { |
70 | - case T_USE: |
|
71 | - $aUseTokens[] = $xToken; |
|
72 | - break; |
|
73 | - case T_CLASS: |
|
74 | - // Stop on the "class" token. |
|
75 | - return [$aUseTokens, $aHeaderTokens]; |
|
76 | - default: |
|
77 | - $aHeaderTokens[] = $xToken; |
|
70 | + case T_USE: |
|
71 | + $aUseTokens[] = $xToken; |
|
72 | + break; |
|
73 | + case T_CLASS: |
|
74 | + // Stop on the "class" token. |
|
75 | + return [$aUseTokens, $aHeaderTokens]; |
|
76 | + default: |
|
77 | + $aHeaderTokens[] = $xToken; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | // No "class" token in the file. Do nothing. |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | |
59 | 59 | $aHeaderTokens = []; |
60 | 60 | $aUseTokens = []; |
61 | - foreach($aTokens as $xToken) |
|
61 | + foreach ($aTokens as $xToken) |
|
62 | 62 | { |
63 | - if(!is_array($xToken)) |
|
63 | + if (!is_array($xToken)) |
|
64 | 64 | { |
65 | 65 | continue; |
66 | 66 | } |
67 | 67 | |
68 | - switch($xToken[0]) |
|
68 | + switch ($xToken[0]) |
|
69 | 69 | { |
70 | 70 | case T_USE: |
71 | 71 | $aUseTokens[] = $xToken; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | // Key the tokens values by type |
105 | 105 | $aUseStatement = []; |
106 | - foreach($aUseTokens as $aToken) |
|
106 | + foreach ($aUseTokens as $aToken) |
|
107 | 107 | { |
108 | 108 | $aUseStatement[$aToken[0]] = $aToken[1]; |
109 | 109 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | private function getStatementKey(array $aUseStatement): string |
121 | 121 | { |
122 | - if(isset($aUseStatement[T_STRING])) |
|
122 | + if (isset($aUseStatement[T_STRING])) |
|
123 | 123 | { |
124 | 124 | // The statement is "use <type> as <name>;". <name> is the key. |
125 | 125 | return $aUseStatement[T_STRING]; |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | { |
141 | 141 | $sFileName = $xReflectionClass->getFileName(); |
142 | 142 | [$aUseTokens, $aHeaderTokens] = $this->getTokens($sFileName); |
143 | - if(!$aUseTokens) |
|
143 | + if (!$aUseTokens) |
|
144 | 144 | { |
145 | 145 | return []; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $aImportedTypes = []; |
149 | - foreach($aUseTokens as $aUseToken) |
|
149 | + foreach ($aUseTokens as $aUseToken) |
|
150 | 150 | { |
151 | 151 | $aUseStatement = $this->getUseStatement($aUseToken, $aHeaderTokens); |
152 | 152 | $aImportedTypes[$this->getStatementKey($aUseStatement)] = $aUseStatement[T_NAME_QUALIFIED]; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | public function shallIncludeAssets(AbstractPlugin $xPlugin): bool |
72 | 72 | { |
73 | 73 | $sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
74 | - if($this->xConfigManager->hasOption($sPluginOptionName)) |
|
74 | + if ($this->xConfigManager->hasOption($sPluginOptionName)) |
|
75 | 75 | { |
76 | 76 | return $this->xConfigManager->getOption($sPluginOptionName); |
77 | 77 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->xConfigManager->getOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"), |
96 | 96 | "$sJsLibUri/jaxon.core$sJsExtension", |
97 | 97 | ]; |
98 | - if($this->xConfigManager->getOption('core.debug.on')) |
|
98 | + if ($this->xConfigManager->getOption('core.debug.on')) |
|
99 | 99 | { |
100 | 100 | $sLanguage = $this->xConfigManager->getOption('core.language'); |
101 | 101 | $aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension"; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getOptionVars(): array |
115 | 115 | { |
116 | - if(!$this->xConfigManager->hasOption('core.request.uri')) |
|
116 | + if (!$this->xConfigManager->hasOption('core.request.uri')) |
|
117 | 117 | { |
118 | 118 | $this->xConfigManager->setOption('core.request.uri', $this->xParameterReader->uri()); |
119 | 119 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | // Check config options |
147 | 147 | // - The js.app.export option must be set to true |
148 | 148 | // - The js.app.uri and js.app.dir options must be set to non null values |
149 | - if(!$this->xConfigManager->getOption('js.app.export', false) || |
|
149 | + if (!$this->xConfigManager->getOption('js.app.export', false) || |
|
150 | 150 | !$this->xConfigManager->getOption('js.app.uri') || |
151 | 151 | !$this->xConfigManager->getOption('js.app.dir')) |
152 | 152 | { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function createJsFiles(CodeGenerator $xCodeGenerator): string |
166 | 166 | { |
167 | - if(!$this->shallCreateJsFiles()) |
|
167 | + if (!$this->shallCreateJsFiles()) |
|
168 | 168 | { |
169 | 169 | return ''; |
170 | 170 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $sJsFileName = $this->xConfigManager->getOption('js.app.file') ?: $xCodeGenerator->getHash(); |
174 | 174 | $sJsDirectory = rtrim($this->xConfigManager->getOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
175 | 175 | // - The js.app.dir must be writable |
176 | - if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
176 | + if (!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
177 | 177 | { |
178 | 178 | return ''; |
179 | 179 | } |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | $sJsFilePath = $sJsDirectory . $sJsFileName . '.js'; |
182 | 182 | $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
183 | 183 | $sJsFileUri = rtrim($this->xConfigManager->getOption('js.app.uri'), '/') . "/$sJsFileName"; |
184 | - if(!is_file($sJsFilePath) && !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
184 | + if (!is_file($sJsFilePath) && !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
185 | 185 | { |
186 | 186 | return ''; |
187 | 187 | } |
188 | - if(!$this->xConfigManager->getOption('js.app.minify', false)) |
|
188 | + if (!$this->xConfigManager->getOption('js.app.minify', false)) |
|
189 | 189 | { |
190 | 190 | return $sJsFileUri . '.js'; |
191 | 191 | } |
192 | - if(!is_file($sJsMinFilePath) && !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
192 | + if (!is_file($sJsMinFilePath) && !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
193 | 193 | { |
194 | 194 | // If the file cannot be minified, return the plain js file. |
195 | 195 | return $sJsFileUri . '.js'; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function addCodeGenerator(string $sClassName, int $nPriority) |
117 | 117 | { |
118 | - while(isset($this->aCodeGenerators[$nPriority])) |
|
118 | + while (isset($this->aCodeGenerators[$nPriority])) |
|
119 | 119 | { |
120 | 120 | $nPriority++; |
121 | 121 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | private function generatePluginCodes(string $sClassName) |
159 | 159 | { |
160 | 160 | $xGenerator = $this->di->g($sClassName); |
161 | - if(!is_subclass_of($xGenerator, AbstractPlugin::class) || $this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
161 | + if (!is_subclass_of($xGenerator, AbstractPlugin::class) || $this->xAssetManager->shallIncludeAssets($xGenerator)) |
|
162 | 162 | { |
163 | 163 | // HTML tags for CSS |
164 | 164 | $this->sCss = trim($this->sCss) . "\n" . trim($xGenerator->getCss(), " \n"); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | } |
168 | 168 | // Javascript code |
169 | 169 | $this->sJsScript = trim($this->sJsScript) . "\n\n" . trim($xGenerator->getScript(), " \n"); |
170 | - if($xGenerator->readyEnabled()) |
|
170 | + if ($xGenerator->readyEnabled()) |
|
171 | 171 | { |
172 | 172 | $sScriptAttr = $xGenerator->readyInlined() ? 'sJsInlineScript' : 'sJsReadyScript'; |
173 | 173 | $this->$sScriptAttr = trim($this->$sScriptAttr) . "\n\n" . trim($xGenerator->getReadyScript(), " \n"); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | 'sScript' => trim($this->sJsReadyScript, " \n") . "\n\tjaxon.processCustomAttrs();\n", |
189 | 189 | ]); |
190 | 190 | $this->sJsInlineScript = trim($this->sJsInlineScript, " \n"); |
191 | - if(($this->sJsInlineScript)) |
|
191 | + if (($this->sJsInlineScript)) |
|
192 | 192 | { |
193 | 193 | $this->sJsInlineScript = $this->render('ready.js', ['sScript' => $this->sJsInlineScript . "\n"]); |
194 | 194 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | private function generateCodes() |
207 | 207 | { |
208 | - if($this->bGenerated) |
|
208 | + if ($this->bGenerated) |
|
209 | 209 | { |
210 | 210 | return; |
211 | 211 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $this->xAssetManager = $this->di->getAssetManager(); |
217 | 217 | $this->sJsOptions = $this->xAssetManager->getJsOptions(); |
218 | - foreach($this->aCodeGenerators as $sClassName) |
|
218 | + foreach ($this->aCodeGenerators as $sClassName) |
|
219 | 219 | { |
220 | 220 | $this->generatePluginCodes($sClassName); |
221 | 221 | } |
@@ -277,16 +277,16 @@ discard block |
||
277 | 277 | { |
278 | 278 | $this->generateCodes(); |
279 | 279 | $sScript = ''; |
280 | - if(($bIncludeCss)) |
|
280 | + if (($bIncludeCss)) |
|
281 | 281 | { |
282 | 282 | $sScript .= $this->getCss() . "\n"; |
283 | 283 | } |
284 | - if(($bIncludeJs)) |
|
284 | + if (($bIncludeJs)) |
|
285 | 285 | { |
286 | 286 | $sScript .= $this->getJs() . "\n"; |
287 | 287 | } |
288 | 288 | |
289 | - if(!($sUrl = $this->xAssetManager->createJsFiles($this))) |
|
289 | + if (!($sUrl = $this->xAssetManager->createJsFiles($this))) |
|
290 | 290 | { |
291 | 291 | return trim($sScript) . "\n\n" . $this->render('wrapper.js', |
292 | 292 | ['sScript' => trim($this->sJsScript) . "\n\n" . trim($this->sJsInlineScript)]); |