@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | try |
| 206 | 206 | { |
| 207 | 207 | // Make sure the registered class exists |
| 208 | - if(isset($aOptions['include'])) |
|
| 208 | + if (isset($aOptions['include'])) |
|
| 209 | 209 | { |
| 210 | 210 | require_once $aOptions['include']; |
| 211 | 211 | } |
| 212 | 212 | $xReflectionClass = new ReflectionClass($sClassName); |
| 213 | 213 | // Check if the class is registrable |
| 214 | - if(!$xReflectionClass->isInstantiable()) |
|
| 214 | + if (!$xReflectionClass->isInstantiable()) |
|
| 215 | 215 | { |
| 216 | 216 | return; |
| 217 | 217 | } |
@@ -219,14 +219,14 @@ discard block |
||
| 219 | 219 | $this->aComponents[$sClassName] = $aOptions; |
| 220 | 220 | $this->val($this->getReflectionClassKey($sClassName), $xReflectionClass); |
| 221 | 221 | // Register the user class, but only if the user didn't already. |
| 222 | - if(!$this->has($sClassName)) |
|
| 222 | + if (!$this->has($sClassName)) |
|
| 223 | 223 | { |
| 224 | 224 | $this->set($sClassName, function() use($sClassName) { |
| 225 | 225 | return $this->make($this->get($this->getReflectionClassKey($sClassName))); |
| 226 | 226 | }); |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | - catch(ReflectionException $e) |
|
| 229 | + catch (ReflectionException $e) |
|
| 230 | 230 | { |
| 231 | 231 | throw new SetupException($this->di->g(Translator::class) |
| 232 | 232 | ->trans('errors.class.invalid', ['name' => $sClassName])); |
@@ -243,12 +243,12 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | private function discoverComponent(string $sClassName) |
| 245 | 245 | { |
| 246 | - if(!isset($this->aComponents[$sClassName])) |
|
| 246 | + if (!isset($this->aComponents[$sClassName])) |
|
| 247 | 247 | { |
| 248 | 248 | $xRegistry = $this->di->g(ComponentRegistry::class); |
| 249 | 249 | $xRegistry->updateHash(false); // Disable hash calculation. |
| 250 | 250 | $aOptions = $xRegistry->getNamespaceComponentOptions($sClassName); |
| 251 | - if($aOptions !== null) |
|
| 251 | + if ($aOptions !== null) |
|
| 252 | 252 | { |
| 253 | 253 | $this->registerComponent($sClassName, $aOptions); |
| 254 | 254 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | $xRegistry->registerComponentsInDirectories(); |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - if(!isset($this->aComponents[$sClassName])) |
|
| 262 | + if (!isset($this->aComponents[$sClassName])) |
|
| 263 | 263 | { |
| 264 | 264 | throw new SetupException($this->di->g(Translator::class) |
| 265 | 265 | ->trans('errors.class.invalid', ['name' => $sClassName])); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | public function getCallableObjects(): array |
| 276 | 276 | { |
| 277 | 277 | $aCallableObjects = []; |
| 278 | - foreach($this->aComponents as $sClassName => $_) |
|
| 278 | + foreach ($this->aComponents as $sClassName => $_) |
|
| 279 | 279 | { |
| 280 | 280 | $aCallableObjects[$sClassName] = $this->makeCallableObject($sClassName); |
| 281 | 281 | } |
@@ -326,12 +326,12 @@ discard block |
||
| 326 | 326 | { |
| 327 | 327 | /** @var Config|null */ |
| 328 | 328 | $xConfig = $aOptions['config'] ?? null; |
| 329 | - if($xConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 329 | + if ($xConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 330 | 330 | { |
| 331 | 331 | return null; |
| 332 | 332 | } |
| 333 | 333 | $sReaderId = $xConfig->getOption('metadata.reader'); |
| 334 | - if(!in_array($sReaderId, ['attributes', 'annotations'])) |
|
| 334 | + if (!in_array($sReaderId, ['attributes', 'annotations'])) |
|
| 335 | 335 | { |
| 336 | 336 | return null; |
| 337 | 337 | } |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | null : $this->di->getMetadataCache(); |
| 343 | 343 | $xMetadata = $xMetadataCache?->read($sClassName) ?? null; |
| 344 | 344 | |
| 345 | - if($xMetadata !== null) |
|
| 345 | + if ($xMetadata !== null) |
|
| 346 | 346 | { |
| 347 | 347 | return $xMetadata; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
| 351 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 351 | + $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC| |
|
| 352 | 352 | ReflectionProperty::IS_PROTECTED)); |
| 353 | 353 | $aMethods = $this->getPublicMethods($xReflectionClass); |
| 354 | 354 | |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | $xMetadata = $xMetadataReader->getAttributes($xInput); |
| 358 | 358 | |
| 359 | 359 | // Try to save the metadata in the cache |
| 360 | - if($xMetadataCache !== null && $xMetadata !== null) |
|
| 360 | + if ($xMetadataCache !== null && $xMetadata !== null) |
|
| 361 | 361 | { |
| 362 | 362 | $xMetadataCache->save($sClassName, $xMetadata); |
| 363 | 363 | } |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | { |
| 393 | 393 | $sComponentObject = $this->getCallableObjectKey($sClassName); |
| 394 | 394 | // Prevent duplication. It's important not to use the class name here. |
| 395 | - if($this->has($sComponentObject)) |
|
| 395 | + if ($this->has($sComponentObject)) |
|
| 396 | 396 | { |
| 397 | 397 | return; |
| 398 | 398 | } |
@@ -418,14 +418,14 @@ discard block |
||
| 418 | 418 | |
| 419 | 419 | // Initialize the user class instance |
| 420 | 420 | $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
| 421 | - if($xClassInstance instanceof AbstractComponent) |
|
| 421 | + if ($xClassInstance instanceof AbstractComponent) |
|
| 422 | 422 | { |
| 423 | 423 | $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
| 424 | 424 | $xHelper->xTarget = $this->xTarget; |
| 425 | 425 | |
| 426 | 426 | // Call the protected "initComponent()" method of the Component class. |
| 427 | 427 | $cSetter = function($di, $xHelper) { |
| 428 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 428 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 429 | 429 | }; |
| 430 | 430 | $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
| 431 | 431 | call_user_func($cSetter, $this->di, $xHelper); |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | /** @var CallableObject */ |
| 441 | 441 | $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
| 442 | 442 | $xCallableObject->setDiClassAttributes($xClassInstance); |
| 443 | - if($this->xTarget !== null) |
|
| 443 | + if ($this->xTarget !== null) |
|
| 444 | 444 | { |
| 445 | 445 | $sMethodName = $this->xTarget->getMethodName(); |
| 446 | 446 | $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | private function registerRequestFactory(string $sClassName, string $sFactoryKey) |
| 517 | 517 | { |
| 518 | 518 | $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
| 519 | - if(!($xCallable = $this->makeCallableObject($sClassName))) |
|
| 519 | + if (!($xCallable = $this->makeCallableObject($sClassName))) |
|
| 520 | 520 | { |
| 521 | 521 | return null; |
| 522 | 522 | } |
@@ -546,13 +546,13 @@ discard block |
||
| 546 | 546 | private function getComponentRequestFactory(string $sClassName): ?JxnCall |
| 547 | 547 | { |
| 548 | 548 | $sClassName = trim($sClassName, " \t"); |
| 549 | - if($sClassName === '') |
|
| 549 | + if ($sClassName === '') |
|
| 550 | 550 | { |
| 551 | 551 | return null; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
| 555 | - if(!$this->has($sFactoryKey)) |
|
| 555 | + if (!$this->has($sFactoryKey)) |
|
| 556 | 556 | { |
| 557 | 557 | $this->registerRequestFactory($sClassName, $sFactoryKey); |
| 558 | 558 | } |
@@ -568,7 +568,6 @@ discard block |
||
| 568 | 568 | */ |
| 569 | 569 | public function getRequestFactory(string $sClassName = ''): JxnCall |
| 570 | 570 | { |
| 571 | - return $sClassName === '' ? $this->getFunctionRequestFactory() : |
|
| 572 | - $this->getComponentRequestFactory($sClassName); |
|
| 571 | + return $sClassName === '' ? $this->getFunctionRequestFactory() : $this->getComponentRequestFactory($sClassName); |
|
| 573 | 572 | } |
| 574 | 573 | } |
@@ -23,61 +23,61 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | class MetadataCache |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @param string $sCacheDir |
| 28 | 28 | */ |
| 29 | - public function __construct(private string $sCacheDir) |
|
| 30 | - {} |
|
| 29 | +public function __construct(private string $sCacheDir) |
|
| 30 | +{} |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @param string $sClass |
| 34 | 34 | * |
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | - private function filepath(string $sClass): string |
|
| 38 | - { |
|
| 39 | - $sFilename = str_replace(['\\', '.'], '_', strtolower($sClass)); |
|
| 40 | - return "{$this->sCacheDir}/jaxon_metadata_{$sFilename}.php"; |
|
| 41 | - } |
|
| 37 | +private function filepath(string $sClass): string |
|
| 38 | +{ |
|
| 39 | +$sFilename = str_replace(['\\', '.'], '_', strtolower($sClass)); |
|
| 40 | +return "{$this->sCacheDir}/jaxon_metadata_{$sFilename}.php"; |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * Generate the PHP code to create a metadata object. |
| 45 | 45 | * |
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | - private function encode(Metadata $xMetadata): array |
|
| 48 | +private function encode(Metadata $xMetadata): array |
|
| 49 | +{ |
|
| 50 | +$sVar = '$'; // The dollar char. |
|
| 51 | +$aCalls = ["{$sVar}xMetadata = new " . Metadata::class . '();']; |
|
| 52 | +foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 53 | +{ |
|
| 54 | +if(count($aValues) === 0) |
|
| 55 | +{ |
|
| 56 | + continue; |
|
| 57 | +} |
|
| 58 | +foreach($aValues as $sMethod => $xData) |
|
| 59 | +{ |
|
| 60 | + $aCalls[] = "{$sVar}xData = {$sVar}xMetadata->{$sType}('$sMethod');"; |
|
| 61 | + foreach($xData->encode("{$sVar}xData") as $sCall) |
|
| 49 | 62 | { |
| 50 | - $sVar = '$'; // The dollar char. |
|
| 51 | - $aCalls = ["{$sVar}xMetadata = new " . Metadata::class . '();']; |
|
| 52 | - foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 53 | - { |
|
| 54 | - if(count($aValues) === 0) |
|
| 55 | - { |
|
| 56 | - continue; |
|
| 57 | - } |
|
| 58 | - foreach($aValues as $sMethod => $xData) |
|
| 59 | - { |
|
| 60 | - $aCalls[] = "{$sVar}xData = {$sVar}xMetadata->{$sType}('$sMethod');"; |
|
| 61 | - foreach($xData->encode("{$sVar}xData") as $sCall) |
|
| 62 | - { |
|
| 63 | - $aCalls[] = $sCall; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $aCalls[] = "return {$sVar}xMetadata;"; |
|
| 68 | - return $aCalls; |
|
| 63 | + $aCalls[] = $sCall; |
|
| 69 | 64 | } |
| 65 | +} |
|
| 66 | +} |
|
| 67 | +$aCalls[] = "return {$sVar}xMetadata;"; |
|
| 68 | +return $aCalls; |
|
| 69 | +} |
|
| 70 | 70 | |
| 71 | - /** |
|
| 71 | +/** |
|
| 72 | 72 | * @param string $sClass |
| 73 | 73 | * @param Metadata $xMetadata |
| 74 | 74 | * |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function save(string $sClass, Metadata $xMetadata): void |
|
| 78 | - { |
|
| 79 | - $sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 80 | - $sPhpCode = <<<CODE |
|
| 77 | +public function save(string $sClass, Metadata $xMetadata): void |
|
| 78 | +{ |
|
| 79 | +$sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 80 | +$sPhpCode = <<<CODE |
|
| 81 | 81 | <?php |
| 82 | 82 | |
| 83 | 83 | return function() { |
@@ -85,17 +85,17 @@ discard block |
||
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | CODE; |
| 88 | - file_put_contents($this->filepath($sClass), $sPhpCode); |
|
| 89 | - } |
|
| 88 | +file_put_contents($this->filepath($sClass), $sPhpCode); |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * @param string $sClass |
| 93 | 93 | * |
| 94 | 94 | * @return Metadata|null |
| 95 | 95 | */ |
| 96 | - public function read(string $sClass): ?Metadata |
|
| 97 | - { |
|
| 98 | - $fCreator = require $this->filepath($sClass); |
|
| 99 | - return !is_callable($fCreator) ? null : $fCreator(); |
|
| 100 | - } |
|
| 96 | +public function read(string $sClass): ?Metadata |
|
| 97 | +{ |
|
| 98 | +$fCreator = require $this->filepath($sClass); |
|
| 99 | +return !is_callable($fCreator) ? null : $fCreator(); |
|
| 100 | +} |
|
| 101 | 101 | } |
@@ -49,16 +49,16 @@ |
||
| 49 | 49 | { |
| 50 | 50 | $sVar = '$'; // The dollar char. |
| 51 | 51 | $aCalls = ["{$sVar}xMetadata = new " . Metadata::class . '();']; |
| 52 | - foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 52 | + foreach ($xMetadata->getAttributes() as $sType => $aValues) |
|
| 53 | 53 | { |
| 54 | - if(count($aValues) === 0) |
|
| 54 | + if (count($aValues) === 0) |
|
| 55 | 55 | { |
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | - foreach($aValues as $sMethod => $xData) |
|
| 58 | + foreach ($aValues as $sMethod => $xData) |
|
| 59 | 59 | { |
| 60 | 60 | $aCalls[] = "{$sVar}xData = {$sVar}xMetadata->{$sType}('$sMethod');"; |
| 61 | - foreach($xData->encode("{$sVar}xData") as $sCall) |
|
| 61 | + foreach ($xData->encode("{$sVar}xData") as $sCall) |
|
| 62 | 62 | { |
| 63 | 63 | $aCalls[] = $sCall; |
| 64 | 64 | } |
@@ -21,161 +21,161 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Metadata |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var array<string, array<string, Data\AbstractData>> |
| 26 | 26 | */ |
| 27 | - private array $aAttributes = [ |
|
| 28 | - 'exclude' => [], |
|
| 29 | - 'container' => [], |
|
| 30 | - 'databag' => [], |
|
| 31 | - 'callback' => [], |
|
| 32 | - 'before' => [], |
|
| 33 | - 'after' => [], |
|
| 34 | - 'upload' => [], |
|
| 35 | - ]; |
|
| 36 | - |
|
| 37 | - /** |
|
| 27 | +private array $aAttributes = [ |
|
| 28 | +'exclude' => [], |
|
| 29 | +'container' => [], |
|
| 30 | +'databag' => [], |
|
| 31 | +'callback' => [], |
|
| 32 | +'before' => [], |
|
| 33 | +'after' => [], |
|
| 34 | +'upload' => [], |
|
| 35 | +]; |
|
| 36 | + |
|
| 37 | +/** |
|
| 38 | 38 | * @return array<string, array<string, Data\AbstractData>> |
| 39 | 39 | */ |
| 40 | - public function getAttributes(): array |
|
| 41 | - { |
|
| 42 | - return $this->aAttributes; |
|
| 43 | - } |
|
| 40 | +public function getAttributes(): array |
|
| 41 | +{ |
|
| 42 | +return $this->aAttributes; |
|
| 43 | +} |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @param string $sMethod |
| 47 | 47 | * |
| 48 | 48 | * @return Data\ExcludeData |
| 49 | 49 | */ |
| 50 | - public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 51 | - { |
|
| 52 | - return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 53 | - $this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 54 | - } |
|
| 50 | +public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 51 | +{ |
|
| 52 | +return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 53 | +$this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 54 | +} |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * @param string $sMethod |
| 58 | 58 | * |
| 59 | 59 | * @return Data\ContainerData |
| 60 | 60 | */ |
| 61 | - public function container(string $sMethod = '*'): Data\ContainerData |
|
| 62 | - { |
|
| 63 | - return $this->aAttributes['container'][$sMethod] ?? |
|
| 64 | - $this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 65 | - } |
|
| 61 | +public function container(string $sMethod = '*'): Data\ContainerData |
|
| 62 | +{ |
|
| 63 | +return $this->aAttributes['container'][$sMethod] ?? |
|
| 64 | +$this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * @param string $sMethod |
| 69 | 69 | * |
| 70 | 70 | * @return Data\DatabagData |
| 71 | 71 | */ |
| 72 | - public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 73 | - { |
|
| 74 | - return $this->aAttributes['databag'][$sMethod] ?? |
|
| 75 | - $this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 76 | - } |
|
| 72 | +public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 73 | +{ |
|
| 74 | +return $this->aAttributes['databag'][$sMethod] ?? |
|
| 75 | +$this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 76 | +} |
|
| 77 | 77 | |
| 78 | - /** |
|
| 78 | +/** |
|
| 79 | 79 | * @param string $sMethod |
| 80 | 80 | * |
| 81 | 81 | * @return Data\CallbackData |
| 82 | 82 | */ |
| 83 | - public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 84 | - { |
|
| 85 | - return $this->aAttributes['callback'][$sMethod] ?? |
|
| 86 | - $this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 87 | - } |
|
| 83 | +public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 84 | +{ |
|
| 85 | +return $this->aAttributes['callback'][$sMethod] ?? |
|
| 86 | +$this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * @param string $sMethod |
| 91 | 91 | * |
| 92 | 92 | * @return Data\BeforeData |
| 93 | 93 | */ |
| 94 | - public function before(string $sMethod = '*'): Data\BeforeData |
|
| 95 | - { |
|
| 96 | - return $this->aAttributes['before'][$sMethod] ?? |
|
| 97 | - $this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 98 | - } |
|
| 94 | +public function before(string $sMethod = '*'): Data\BeforeData |
|
| 95 | +{ |
|
| 96 | +return $this->aAttributes['before'][$sMethod] ?? |
|
| 97 | +$this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 98 | +} |
|
| 99 | 99 | |
| 100 | - /** |
|
| 100 | +/** |
|
| 101 | 101 | * @param string $sMethod |
| 102 | 102 | * |
| 103 | 103 | * @return Data\AfterData |
| 104 | 104 | */ |
| 105 | - public function after(string $sMethod = '*'): Data\AfterData |
|
| 106 | - { |
|
| 107 | - return $this->aAttributes['after'][$sMethod] ?? |
|
| 108 | - $this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 109 | - } |
|
| 105 | +public function after(string $sMethod = '*'): Data\AfterData |
|
| 106 | +{ |
|
| 107 | +return $this->aAttributes['after'][$sMethod] ?? |
|
| 108 | +$this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 109 | +} |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | +/** |
|
| 112 | 112 | * @param string $sMethod |
| 113 | 113 | * |
| 114 | 114 | * @return Data\UploadData |
| 115 | 115 | */ |
| 116 | - public function upload(string $sMethod = '*'): Data\UploadData |
|
| 117 | - { |
|
| 118 | - return $this->aAttributes['upload'][$sMethod] ?? |
|
| 119 | - $this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 120 | - } |
|
| 116 | +public function upload(string $sMethod = '*'): Data\UploadData |
|
| 117 | +{ |
|
| 118 | +return $this->aAttributes['upload'][$sMethod] ?? |
|
| 119 | +$this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 120 | +} |
|
| 121 | 121 | |
| 122 | - /** |
|
| 122 | +/** |
|
| 123 | 123 | * True if the class is excluded |
| 124 | 124 | * |
| 125 | 125 | * @return bool |
| 126 | 126 | */ |
| 127 | - public function isExcluded(): bool |
|
| 128 | - { |
|
| 129 | - $xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 130 | - return $xData !== null && $xData->getValue() === true; |
|
| 131 | - } |
|
| 127 | +public function isExcluded(): bool |
|
| 128 | +{ |
|
| 129 | +$xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 130 | +return $xData !== null && $xData->getValue() === true; |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get the properties of the class methods |
| 135 | 135 | * |
| 136 | 136 | * @return array |
| 137 | 137 | */ |
| 138 | - public function getProperties(): array |
|
| 138 | +public function getProperties(): array |
|
| 139 | +{ |
|
| 140 | +$aProperties = []; |
|
| 141 | +$aClassProperties = []; |
|
| 142 | +foreach($this->aAttributes as $sType => $aValues) |
|
| 143 | +{ |
|
| 144 | +if($sType === 'exclude') |
|
| 145 | +{ |
|
| 146 | + continue; |
|
| 147 | +} |
|
| 148 | + |
|
| 149 | +foreach($aValues as $sMethod => $xData) |
|
| 150 | +{ |
|
| 151 | + if($sMethod === '*') |
|
| 139 | 152 | { |
| 140 | - $aProperties = []; |
|
| 141 | - $aClassProperties = []; |
|
| 142 | - foreach($this->aAttributes as $sType => $aValues) |
|
| 143 | - { |
|
| 144 | - if($sType === 'exclude') |
|
| 145 | - { |
|
| 146 | - continue; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - foreach($aValues as $sMethod => $xData) |
|
| 150 | - { |
|
| 151 | - if($sMethod === '*') |
|
| 152 | - { |
|
| 153 | - $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if(count($aClassProperties) > 0) |
|
| 161 | - { |
|
| 162 | - $aProperties['*'] = $aClassProperties; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $aProperties; |
|
| 153 | + $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 154 | + continue; |
|
| 166 | 155 | } |
| 156 | + $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 157 | +} |
|
| 158 | +} |
|
| 159 | + |
|
| 160 | +if(count($aClassProperties) > 0) |
|
| 161 | +{ |
|
| 162 | +$aProperties['*'] = $aClassProperties; |
|
| 163 | +} |
|
| 164 | + |
|
| 165 | +return $aProperties; |
|
| 166 | +} |
|
| 167 | 167 | |
| 168 | - /** |
|
| 168 | +/** |
|
| 169 | 169 | * Get the protected methods |
| 170 | 170 | * |
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | - public function getProtectedMethods(): array |
|
| 174 | - { |
|
| 175 | - /** @var array<Data\ExcludeData> */ |
|
| 176 | - $aAttributes = $this->aAttributes['exclude']; |
|
| 177 | - $aMethods = array_keys($aAttributes); |
|
| 178 | - return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 179 | - $sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 180 | - } |
|
| 173 | +public function getProtectedMethods(): array |
|
| 174 | +{ |
|
| 175 | +/** @var array<Data\ExcludeData> */ |
|
| 176 | +$aAttributes = $this->aAttributes['exclude']; |
|
| 177 | +$aMethods = array_keys($aAttributes); |
|
| 178 | +return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 179 | +$sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 180 | +} |
|
| 181 | 181 | } |
@@ -139,16 +139,16 @@ discard block |
||
| 139 | 139 | { |
| 140 | 140 | $aProperties = []; |
| 141 | 141 | $aClassProperties = []; |
| 142 | - foreach($this->aAttributes as $sType => $aValues) |
|
| 142 | + foreach ($this->aAttributes as $sType => $aValues) |
|
| 143 | 143 | { |
| 144 | - if($sType === 'exclude') |
|
| 144 | + if ($sType === 'exclude') |
|
| 145 | 145 | { |
| 146 | 146 | continue; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - foreach($aValues as $sMethod => $xData) |
|
| 149 | + foreach ($aValues as $sMethod => $xData) |
|
| 150 | 150 | { |
| 151 | - if($sMethod === '*') |
|
| 151 | + if ($sMethod === '*') |
|
| 152 | 152 | { |
| 153 | 153 | $aClassProperties[$xData->getName()] = $xData->getValue(); |
| 154 | 154 | continue; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if(count($aClassProperties) > 0) |
|
| 160 | + if (count($aClassProperties) > 0) |
|
| 161 | 161 | { |
| 162 | 162 | $aProperties['*'] = $aClassProperties; |
| 163 | 163 | } |
@@ -27,56 +27,56 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class ComponentOptions |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * Check if the js code for this object must be generated |
| 32 | 32 | * |
| 33 | 33 | * @var bool |
| 34 | 34 | */ |
| 35 | - private $bExcluded = false; |
|
| 35 | +private $bExcluded = false; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The character to use as separator in javascript class names |
| 39 | 39 | * |
| 40 | 40 | * @var string |
| 41 | 41 | */ |
| 42 | - private $sSeparator = '.'; |
|
| 42 | +private $sSeparator = '.'; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * A list of methods of the user registered callable object the library must not export to javascript |
| 46 | 46 | * |
| 47 | 47 | * @var array |
| 48 | 48 | */ |
| 49 | - private $aProtectedMethods = []; |
|
| 49 | +private $aProtectedMethods = []; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * A list of methods to call before processing the request |
| 53 | 53 | * |
| 54 | 54 | * @var array |
| 55 | 55 | */ |
| 56 | - private $aBeforeMethods = []; |
|
| 56 | +private $aBeforeMethods = []; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * A list of methods to call after processing the request |
| 60 | 60 | * |
| 61 | 61 | * @var array |
| 62 | 62 | */ |
| 63 | - private $aAfterMethods = []; |
|
| 63 | +private $aAfterMethods = []; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * The javascript class options |
| 67 | 67 | * |
| 68 | 68 | * @var array |
| 69 | 69 | */ |
| 70 | - private $aJsOptions = []; |
|
| 70 | +private $aJsOptions = []; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * The DI options |
| 74 | 74 | * |
| 75 | 75 | * @var array |
| 76 | 76 | */ |
| 77 | - private $aDiOptions = []; |
|
| 77 | +private $aDiOptions = []; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * The constructor |
| 81 | 81 | * |
| 82 | 82 | * @param array $aOptions |
@@ -84,119 +84,119 @@ discard block |
||
| 84 | 84 | * @param array $aProtectedMethods |
| 85 | 85 | * @param array $aProperties |
| 86 | 86 | */ |
| 87 | - public function __construct(array $aOptions, bool $bExcluded, |
|
| 88 | - array $aProtectedMethods, array $aProperties) |
|
| 89 | - { |
|
| 90 | - $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
| 91 | - if($this->bExcluded) |
|
| 92 | - { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 87 | +public function __construct(array $aOptions, bool $bExcluded, |
|
| 88 | +array $aProtectedMethods, array $aProperties) |
|
| 89 | +{ |
|
| 90 | +$this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
| 91 | +if($this->bExcluded) |
|
| 92 | +{ |
|
| 93 | +return; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - $sSeparator = $aOptions['separator']; |
|
| 97 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 98 | - { |
|
| 99 | - $this->sSeparator = $sSeparator; |
|
| 100 | - } |
|
| 101 | - $this->addProtectedMethods($aOptions['protected']); |
|
| 102 | - $this->addProtectedMethods($aProtectedMethods); |
|
| 96 | +$sSeparator = $aOptions['separator']; |
|
| 97 | +if($sSeparator === '_' || $sSeparator === '.') |
|
| 98 | +{ |
|
| 99 | +$this->sSeparator = $sSeparator; |
|
| 100 | +} |
|
| 101 | +$this->addProtectedMethods($aOptions['protected']); |
|
| 102 | +$this->addProtectedMethods($aProtectedMethods); |
|
| 103 | 103 | |
| 104 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 105 | - { |
|
| 106 | - // Names are in a comma-separated list. |
|
| 107 | - $aFunctionNames = explode(',', $sNames); |
|
| 108 | - foreach($aFunctionNames as $sFunctionName) |
|
| 109 | - { |
|
| 110 | - $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - foreach($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 114 | - { |
|
| 115 | - $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 116 | - } |
|
| 117 | - } |
|
| 104 | +foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 105 | +{ |
|
| 106 | +// Names are in a comma-separated list. |
|
| 107 | +$aFunctionNames = explode(',', $sNames); |
|
| 108 | +foreach($aFunctionNames as $sFunctionName) |
|
| 109 | +{ |
|
| 110 | + $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 111 | +} |
|
| 112 | +} |
|
| 113 | +foreach($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 114 | +{ |
|
| 115 | +$this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 116 | +} |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - /** |
|
| 119 | +/** |
|
| 120 | 120 | * @param array|string $xMethods |
| 121 | 121 | * |
| 122 | 122 | * @return void |
| 123 | 123 | */ |
| 124 | - private function addProtectedMethods(array|string $xMethods): void |
|
| 125 | - { |
|
| 126 | - if(!is_array($xMethods)) |
|
| 127 | - { |
|
| 128 | - $this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
| 129 | - return; |
|
| 130 | - } |
|
| 124 | +private function addProtectedMethods(array|string $xMethods): void |
|
| 125 | +{ |
|
| 126 | +if(!is_array($xMethods)) |
|
| 127 | +{ |
|
| 128 | +$this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
| 129 | +return; |
|
| 130 | +} |
|
| 131 | 131 | |
| 132 | - foreach($xMethods as $sMethod) |
|
| 133 | - { |
|
| 134 | - $this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
| 135 | - } |
|
| 136 | - } |
|
| 132 | +foreach($xMethods as $sMethod) |
|
| 133 | +{ |
|
| 134 | +$this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
| 135 | +} |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * @param string $sMethodName |
| 140 | 140 | * |
| 141 | 141 | * @return bool |
| 142 | 142 | */ |
| 143 | - public function isProtectedMethod(string $sMethodName): bool |
|
| 144 | - { |
|
| 145 | - return isset($this->aProtectedMethods['*']) || |
|
| 146 | - isset($this->aProtectedMethods[$sMethodName]); |
|
| 147 | - } |
|
| 143 | +public function isProtectedMethod(string $sMethodName): bool |
|
| 144 | +{ |
|
| 145 | +return isset($this->aProtectedMethods['*']) || |
|
| 146 | +isset($this->aProtectedMethods[$sMethodName]); |
|
| 147 | +} |
|
| 148 | 148 | |
| 149 | - /** |
|
| 149 | +/** |
|
| 150 | 150 | * Check if the js code for this object must be generated |
| 151 | 151 | * |
| 152 | 152 | * @return bool |
| 153 | 153 | */ |
| 154 | - public function excluded(): bool |
|
| 155 | - { |
|
| 156 | - return $this->bExcluded; |
|
| 157 | - } |
|
| 154 | +public function excluded(): bool |
|
| 155 | +{ |
|
| 156 | +return $this->bExcluded; |
|
| 157 | +} |
|
| 158 | 158 | |
| 159 | - /** |
|
| 159 | +/** |
|
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public function separator(): string |
|
| 163 | - { |
|
| 164 | - return $this->sSeparator; |
|
| 165 | - } |
|
| 162 | +public function separator(): string |
|
| 163 | +{ |
|
| 164 | +return $this->sSeparator; |
|
| 165 | +} |
|
| 166 | 166 | |
| 167 | - /** |
|
| 167 | +/** |
|
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - public function beforeMethods(): array |
|
| 171 | - { |
|
| 172 | - return $this->aBeforeMethods; |
|
| 173 | - } |
|
| 170 | +public function beforeMethods(): array |
|
| 171 | +{ |
|
| 172 | +return $this->aBeforeMethods; |
|
| 173 | +} |
|
| 174 | 174 | |
| 175 | - /** |
|
| 175 | +/** |
|
| 176 | 176 | * @return array |
| 177 | 177 | */ |
| 178 | - public function afterMethods(): array |
|
| 179 | - { |
|
| 180 | - return $this->aAfterMethods; |
|
| 181 | - } |
|
| 178 | +public function afterMethods(): array |
|
| 179 | +{ |
|
| 180 | +return $this->aAfterMethods; |
|
| 181 | +} |
|
| 182 | 182 | |
| 183 | - /** |
|
| 183 | +/** |
|
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - public function diOptions(): array |
|
| 187 | - { |
|
| 188 | - return $this->aDiOptions; |
|
| 189 | - } |
|
| 186 | +public function diOptions(): array |
|
| 187 | +{ |
|
| 188 | +return $this->aDiOptions; |
|
| 189 | +} |
|
| 190 | 190 | |
| 191 | - /** |
|
| 191 | +/** |
|
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | - public function jsOptions(): array |
|
| 195 | - { |
|
| 196 | - return $this->aJsOptions; |
|
| 197 | - } |
|
| 194 | +public function jsOptions(): array |
|
| 195 | +{ |
|
| 196 | +return $this->aJsOptions; |
|
| 197 | +} |
|
| 198 | 198 | |
| 199 | - /** |
|
| 199 | +/** |
|
| 200 | 200 | * Set hook methods |
| 201 | 201 | * |
| 202 | 202 | * @param array $aHookMethods The array of hook methods |
@@ -204,34 +204,34 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | - private function setHookMethods(array &$aHookMethods, $xValue): void |
|
| 208 | - { |
|
| 209 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 210 | - { |
|
| 211 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 212 | - { |
|
| 213 | - $aHookMethods[$sCalledMethod] = []; |
|
| 214 | - } |
|
| 215 | - if(is_array($xMethodToCall)) |
|
| 216 | - { |
|
| 217 | - $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
|
| 218 | - } |
|
| 219 | - elseif(is_string($xMethodToCall)) |
|
| 220 | - { |
|
| 221 | - $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 207 | +private function setHookMethods(array &$aHookMethods, $xValue): void |
|
| 208 | +{ |
|
| 209 | +foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 210 | +{ |
|
| 211 | +if(!isset($aHookMethods[$sCalledMethod])) |
|
| 212 | +{ |
|
| 213 | + $aHookMethods[$sCalledMethod] = []; |
|
| 214 | +} |
|
| 215 | +if(is_array($xMethodToCall)) |
|
| 216 | +{ |
|
| 217 | + $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
|
| 218 | +} |
|
| 219 | +elseif(is_string($xMethodToCall)) |
|
| 220 | +{ |
|
| 221 | + $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
|
| 222 | +} |
|
| 223 | +} |
|
| 224 | +} |
|
| 225 | 225 | |
| 226 | - /** |
|
| 226 | +/** |
|
| 227 | 227 | * @param array $aDiOptions |
| 228 | 228 | */ |
| 229 | - private function addDiOption(array $aDiOptions): void |
|
| 230 | - { |
|
| 231 | - $this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions); |
|
| 232 | - } |
|
| 229 | +private function addDiOption(array $aDiOptions): void |
|
| 230 | +{ |
|
| 231 | +$this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 234 | +/** |
|
| 235 | 235 | * Set configuration options / call options for each method |
| 236 | 236 | * |
| 237 | 237 | * @param string $sName The name of the configuration option |
@@ -239,25 +239,25 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return void |
| 241 | 241 | */ |
| 242 | - private function addOption(string $sName, $xValue): void |
|
| 243 | - { |
|
| 244 | - switch($sName) |
|
| 245 | - { |
|
| 246 | - // Set the methods to call before processing the request |
|
| 247 | - case '__before': |
|
| 248 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 249 | - break; |
|
| 250 | - // Set the methods to call after processing the request |
|
| 251 | - case '__after': |
|
| 252 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 253 | - break; |
|
| 254 | - // Set the attributes to inject in the callable object |
|
| 255 | - case '__di': |
|
| 256 | - $this->addDiOption($xValue); |
|
| 257 | - break; |
|
| 258 | - default: |
|
| 259 | - break; |
|
| 260 | - } |
|
| 242 | +private function addOption(string $sName, $xValue): void |
|
| 243 | +{ |
|
| 244 | +switch($sName) |
|
| 245 | +{ |
|
| 246 | +// Set the methods to call before processing the request |
|
| 247 | +case '__before': |
|
| 248 | +$this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 249 | +break; |
|
| 250 | +// Set the methods to call after processing the request |
|
| 251 | +case '__after': |
|
| 252 | +$this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 253 | +break; |
|
| 254 | +// Set the attributes to inject in the callable object |
|
| 255 | +case '__di': |
|
| 256 | +$this->addDiOption($xValue); |
|
| 257 | +break; |
|
| 258 | +default: |
|
| 259 | +break; |
|
| 260 | +} |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -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 | } |
@@ -75,8 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function excluded(?string $sMethodName = null): bool |
| 77 | 77 | { |
| 78 | - return $sMethodName === null ? $this->xOptions->excluded() : |
|
| 79 | - $this->xOptions->isProtectedMethod($sMethodName); |
|
| 78 | + return $sMethodName === null ? $this->xOptions->excluded() : $this->xOptions->isProtectedMethod($sMethodName); |
|
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | /** |
@@ -176,11 +175,11 @@ discard block |
||
| 176 | 175 | $sMethod = $this->xTarget->getMethodName(); |
| 177 | 176 | // The hooks defined at method level are merged with those defined at class level. |
| 178 | 177 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
| 179 | - foreach($aMethods as $xKey => $xValue) |
|
| 178 | + foreach ($aMethods as $xKey => $xValue) |
|
| 180 | 179 | { |
| 181 | 180 | $sHookName = $xValue; |
| 182 | 181 | $aHookArgs = []; |
| 183 | - if(is_string($xKey)) |
|
| 182 | + if (is_string($xKey)) |
|
| 184 | 183 | { |
| 185 | 184 | $sHookName = $xKey; |
| 186 | 185 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -218,7 +217,7 @@ discard block |
||
| 218 | 217 | // Warning: dynamic properties will be deprecated in PHP8.2. |
| 219 | 218 | $this->$sAttr = $xDiValue; |
| 220 | 219 | }; |
| 221 | - foreach($aDiOptions as $sAttr => $sClass) |
|
| 220 | + foreach ($aDiOptions as $sAttr => $sClass) |
|
| 222 | 221 | { |
| 223 | 222 | $this->setDiAttribute($xComponent, $sAttr, $this->di->get($sClass), $cSetter); |
| 224 | 223 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function _register(): void |
| 18 | 18 | { |
| 19 | - $di = jaxon()->di(); |
|
| 19 | +$di = jaxon()->di(); |
|
| 20 | 20 | |
| 21 | - $di->set(AnnotationReader::class, function($c) { |
|
| 22 | - $sKey = 'jaxon_annotations_cache_dir'; |
|
| 23 | - $sCacheDir = $c->h($sKey) ? $c->g($sKey) : sys_get_temp_dir(); |
|
| 24 | - $xAnnotationManager = new AnnotationManager(); |
|
| 25 | - $xAnnotationManager->cache = new AnnotationCache($sCacheDir); |
|
| 21 | +$di->set(AnnotationReader::class, function($c) { |
|
| 22 | +$sKey = 'jaxon_annotations_cache_dir'; |
|
| 23 | +$sCacheDir = $c->h($sKey) ? $c->g($sKey) : sys_get_temp_dir(); |
|
| 24 | +$xAnnotationManager = new AnnotationManager(); |
|
| 25 | +$xAnnotationManager->cache = new AnnotationCache($sCacheDir); |
|
| 26 | 26 | |
| 27 | - return new AnnotationReader($xAnnotationManager); |
|
| 28 | - }); |
|
| 27 | +return new AnnotationReader($xAnnotationManager); |
|
| 28 | +}); |
|
| 29 | 29 | |
| 30 | - $di->alias('metadata_reader_annotations', AnnotationReader::class); |
|
| 30 | +$di->alias('metadata_reader_annotations', AnnotationReader::class); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function register(): void |
| 34 | 34 | { |
| 35 | - // Do nothing if running in cli. |
|
| 36 | - if(php_sapi_name() !== 'cli') |
|
| 37 | - { |
|
| 38 | - _register(); |
|
| 39 | - }; |
|
| 35 | +// Do nothing if running in cli. |
|
| 36 | +if(php_sapi_name() !== 'cli') |
|
| 37 | +{ |
|
| 38 | +_register(); |
|
| 39 | +}; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | register(); |