@@ -236,82 +236,82 @@ |
||
| 236 | 236 | $this->aComponentPublicMethods['node'], |
| 237 | 237 | $xReflectionClass->isSubclassOf(FuncComponent::class) => |
| 238 | 238 | $this->aComponentPublicMethods['func'], |
| 239 | - default => [], |
|
| 240 | - }; |
|
| 241 | - return [$aMethods, $aBaseMethods]; |
|
| 242 | - } |
|
| 239 | +default => [], |
|
| 240 | +}; |
|
| 241 | +return [$aMethods, $aBaseMethods]; |
|
| 242 | +} |
|
| 243 | 243 | |
| 244 | - /** |
|
| 244 | +/** |
|
| 245 | 245 | * @param ReflectionClass $xReflectionClass |
| 246 | 246 | * @param array $aMethods |
| 247 | 247 | * @param array $aOptions |
| 248 | 248 | * |
| 249 | 249 | * @return Metadata|null |
| 250 | 250 | */ |
| 251 | - private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 252 | - array $aMethods, array $aOptions): Metadata|null |
|
| 253 | - { |
|
| 254 | - /** @var Config|null */ |
|
| 255 | - $xPackageConfig = $aOptions['config'] ?? null; |
|
| 256 | - if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 257 | - { |
|
| 258 | - return null; |
|
| 259 | - } |
|
| 260 | - $sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 261 | - if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 262 | - { |
|
| 263 | - return null; |
|
| 264 | - } |
|
| 251 | +private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 252 | +array $aMethods, array $aOptions): Metadata|null |
|
| 253 | +{ |
|
| 254 | +/** @var Config|null */ |
|
| 255 | +$xPackageConfig = $aOptions['config'] ?? null; |
|
| 256 | +if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 257 | +{ |
|
| 258 | +return null; |
|
| 259 | +} |
|
| 260 | +$sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 261 | +if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 262 | +{ |
|
| 263 | +return null; |
|
| 264 | +} |
|
| 265 | 265 | |
| 266 | - // Try to get the class metadata from the cache. |
|
| 267 | - $di = $this->cn(); |
|
| 268 | - $xMetadata = null; |
|
| 269 | - $xMetadataCache = null; |
|
| 270 | - $xConfig = $di->config(); |
|
| 271 | - if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 272 | - { |
|
| 273 | - if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 274 | - { |
|
| 275 | - $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 276 | - $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 277 | - } |
|
| 278 | - $xMetadataCache = $di->getMetadataCache(); |
|
| 279 | - $xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 280 | - if($xMetadata !== null) |
|
| 281 | - { |
|
| 282 | - return $xMetadata; |
|
| 283 | - } |
|
| 284 | - } |
|
| 266 | +// Try to get the class metadata from the cache. |
|
| 267 | +$di = $this->cn(); |
|
| 268 | +$xMetadata = null; |
|
| 269 | +$xMetadataCache = null; |
|
| 270 | +$xConfig = $di->config(); |
|
| 271 | +if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 272 | +{ |
|
| 273 | +if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 274 | +{ |
|
| 275 | + $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 276 | + $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 277 | +} |
|
| 278 | +$xMetadataCache = $di->getMetadataCache(); |
|
| 279 | +$xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 280 | +if($xMetadata !== null) |
|
| 281 | +{ |
|
| 282 | + return $xMetadata; |
|
| 283 | +} |
|
| 284 | +} |
|
| 285 | 285 | |
| 286 | - $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 287 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 288 | - ReflectionProperty::IS_PROTECTED)); |
|
| 286 | +$aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 287 | +$xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 288 | + ReflectionProperty::IS_PROTECTED)); |
|
| 289 | 289 | |
| 290 | - $xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 291 | - $xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 292 | - $xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 290 | +$xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 291 | +$xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 292 | +$xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 293 | 293 | |
| 294 | - // Try to save the metadata in the cache |
|
| 295 | - if($xMetadataCache !== null && $xMetadata !== null) |
|
| 296 | - { |
|
| 297 | - $xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 298 | - } |
|
| 294 | +// Try to save the metadata in the cache |
|
| 295 | +if($xMetadataCache !== null && $xMetadata !== null) |
|
| 296 | +{ |
|
| 297 | +$xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 298 | +} |
|
| 299 | 299 | |
| 300 | - return $xMetadata; |
|
| 301 | - } |
|
| 300 | +return $xMetadata; |
|
| 301 | +} |
|
| 302 | 302 | |
| 303 | - /** |
|
| 303 | +/** |
|
| 304 | 304 | * @param ReflectionClass $xReflectionClass |
| 305 | 305 | * @param array $aOptions |
| 306 | 306 | * |
| 307 | 307 | * @return ComponentOptions |
| 308 | 308 | */ |
| 309 | - private function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 310 | - array $aOptions): ComponentOptions |
|
| 311 | - { |
|
| 312 | - $aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 313 | - $xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 309 | +private function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 310 | +array $aOptions): ComponentOptions |
|
| 311 | +{ |
|
| 312 | +$aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 313 | +$xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 314 | 314 | |
| 315 | - return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 316 | - } |
|
| 315 | +return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 316 | +} |
|
| 317 | 317 | } |
@@ -151,15 +151,15 @@ discard block |
||
| 151 | 151 | $xRegistry->updateHash(false); // Disable hash calculation. |
| 152 | 152 | |
| 153 | 153 | $sComponentId = str_replace('\\', '.', $sClassName); |
| 154 | - if(!isset($this->aComponents[$sComponentId])) |
|
| 154 | + if (!isset($this->aComponents[$sComponentId])) |
|
| 155 | 155 | { |
| 156 | 156 | $aOptions = $xRegistry->getNamespaceComponentOptions($sClassName); |
| 157 | - if($aOptions !== null) |
|
| 157 | + if ($aOptions !== null) |
|
| 158 | 158 | { |
| 159 | 159 | $this->saveComponent($sClassName, $aOptions); |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | - if(isset($this->aComponents[$sComponentId])) |
|
| 162 | + if (isset($this->aComponents[$sComponentId])) |
|
| 163 | 163 | { |
| 164 | 164 | return; // The component is found. |
| 165 | 165 | } |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | // The component was not found in a registered namespace. We need to parse all |
| 168 | 168 | // the directories to be able to find a component registered without a namespace. |
| 169 | 169 | $sComponentId = str_replace('\\', '_', $sClassName); |
| 170 | - if(!isset($this->aComponents[$sComponentId])) |
|
| 170 | + if (!isset($this->aComponents[$sComponentId])) |
|
| 171 | 171 | { |
| 172 | 172 | $xRegistry->registerComponentsInDirectories(); |
| 173 | 173 | } |
| 174 | - if(isset($this->aComponents[$sComponentId])) |
|
| 174 | + if (isset($this->aComponents[$sComponentId])) |
|
| 175 | 175 | { |
| 176 | 176 | return; // The component is found. |
| 177 | 177 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | public function getCallableObjects(): array |
| 190 | 190 | { |
| 191 | 191 | $aCallableObjects = []; |
| 192 | - foreach($this->aComponents as $sComponentId => $_) |
|
| 192 | + foreach ($this->aComponents as $sComponentId => $_) |
|
| 193 | 193 | { |
| 194 | 194 | $aCallableObjects[$sComponentId] = $this->makeCallableObject($sComponentId); |
| 195 | 195 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | private function setComponentPublicMethods(string $sKey, string $sClass): void |
| 206 | 206 | { |
| 207 | - if(isset($this->aComponentPublicMethods[$sKey])) |
|
| 207 | + if (isset($this->aComponentPublicMethods[$sKey])) |
|
| 208 | 208 | { |
| 209 | 209 | return; |
| 210 | 210 | } |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | /** @var Config|null */ |
| 255 | 255 | $xPackageConfig = $aOptions['config'] ?? null; |
| 256 | - if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 256 | + if ($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 257 | 257 | { |
| 258 | 258 | return null; |
| 259 | 259 | } |
| 260 | 260 | $sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
| 261 | - if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 261 | + if (!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 262 | 262 | { |
| 263 | 263 | return null; |
| 264 | 264 | } |
@@ -268,23 +268,23 @@ discard block |
||
| 268 | 268 | $xMetadata = null; |
| 269 | 269 | $xMetadataCache = null; |
| 270 | 270 | $xConfig = $di->config(); |
| 271 | - if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 271 | + if ($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 272 | 272 | { |
| 273 | - if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 273 | + if (!$di->h('jaxon_metadata_cache_dir')) |
|
| 274 | 274 | { |
| 275 | 275 | $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
| 276 | 276 | $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
| 277 | 277 | } |
| 278 | 278 | $xMetadataCache = $di->getMetadataCache(); |
| 279 | 279 | $xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
| 280 | - if($xMetadata !== null) |
|
| 280 | + if ($xMetadata !== null) |
|
| 281 | 281 | { |
| 282 | 282 | return $xMetadata; |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
| 287 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 287 | + $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC| |
|
| 288 | 288 | ReflectionProperty::IS_PROTECTED)); |
| 289 | 289 | |
| 290 | 290 | $xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | $xMetadata = $xMetadataReader->getAttributes($xInput); |
| 293 | 293 | |
| 294 | 294 | // Try to save the metadata in the cache |
| 295 | - if($xMetadataCache !== null && $xMetadata !== null) |
|
| 295 | + if ($xMetadataCache !== null && $xMetadata !== null) |
|
| 296 | 296 | { |
| 297 | 297 | $xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
| 298 | 298 | } |
@@ -39,73 +39,73 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | class ComponentContainer |
| 41 | 41 | { |
| 42 | - use Traits\DiAutoTrait; |
|
| 43 | - use Traits\ComponentTrait; |
|
| 42 | +use Traits\DiAutoTrait; |
|
| 43 | +use Traits\ComponentTrait; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * The Dependency Injection Container for registered classes |
| 47 | 47 | * |
| 48 | 48 | * @var PimpleContainer |
| 49 | 49 | */ |
| 50 | - private $xContainer; |
|
| 50 | +private $xContainer; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * This will be set only when getting the object targetted by the ajax request. |
| 54 | 54 | * |
| 55 | 55 | * @var Target |
| 56 | 56 | */ |
| 57 | - private $xTarget = null; |
|
| 57 | +private $xTarget = null; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * The class constructor |
| 61 | 61 | * |
| 62 | 62 | * @param Container $di |
| 63 | 63 | */ |
| 64 | - public function __construct(private Container $di) |
|
| 65 | - { |
|
| 66 | - $this->xContainer = new PimpleContainer(); |
|
| 67 | - $this->val(ComponentContainer::class, $this); |
|
| 68 | - |
|
| 69 | - // Register the call factory for registered functions |
|
| 70 | - $this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | - new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | - ->getOption('core.prefix.function', ''))); |
|
| 73 | - |
|
| 74 | - // Register the pagination component, but do not export to js. |
|
| 75 | - $this->saveComponent(Pagination::class, [ |
|
| 76 | - 'excluded' => true, |
|
| 77 | - 'separator' => '.', |
|
| 78 | - // The namespace has the same name as the Component class. |
|
| 79 | - 'namespace' => Component::class, |
|
| 80 | - ]); |
|
| 81 | - |
|
| 82 | - $this->setComponentPublicMethods('node', NodeComponent::class); |
|
| 83 | - $this->setComponentPublicMethods('func', FuncComponent::class); |
|
| 84 | - } |
|
| 64 | +public function __construct(private Container $di) |
|
| 65 | +{ |
|
| 66 | +$this->xContainer = new PimpleContainer(); |
|
| 67 | +$this->val(ComponentContainer::class, $this); |
|
| 68 | + |
|
| 69 | +// Register the call factory for registered functions |
|
| 70 | +$this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | +new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | + ->getOption('core.prefix.function', ''))); |
|
| 73 | + |
|
| 74 | +// Register the pagination component, but do not export to js. |
|
| 75 | +$this->saveComponent(Pagination::class, [ |
|
| 76 | +'excluded' => true, |
|
| 77 | +'separator' => '.', |
|
| 78 | +// The namespace has the same name as the Component class. |
|
| 79 | +'namespace' => Component::class, |
|
| 80 | +]); |
|
| 81 | + |
|
| 82 | +$this->setComponentPublicMethods('node', NodeComponent::class); |
|
| 83 | +$this->setComponentPublicMethods('func', FuncComponent::class); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * The container for parameters |
| 88 | 88 | * |
| 89 | 89 | * @return Container |
| 90 | 90 | */ |
| 91 | - protected function cn(): Container |
|
| 92 | - { |
|
| 93 | - return $this->di; |
|
| 94 | - } |
|
| 91 | +protected function cn(): Container |
|
| 92 | +{ |
|
| 93 | +return $this->di; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Check if a class is defined in the container |
| 98 | 98 | * |
| 99 | 99 | * @param class-string $sClass The full class name |
| 100 | 100 | * |
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | - public function has(string $sClass): bool |
|
| 104 | - { |
|
| 105 | - return $this->xContainer->offsetExists($sClass); |
|
| 106 | - } |
|
| 103 | +public function has(string $sClass): bool |
|
| 104 | +{ |
|
| 105 | +return $this->xContainer->offsetExists($sClass); |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Save a closure in the container |
| 110 | 110 | * |
| 111 | 111 | * @param class-string $sClass The full class name |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function set(string $sClass, Closure $xClosure) |
|
| 117 | - { |
|
| 118 | - $this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | - } |
|
| 116 | +public function set(string $sClass, Closure $xClosure) |
|
| 117 | +{ |
|
| 118 | +$this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Save a value in the container |
| 123 | 123 | * |
| 124 | 124 | * @param string|class-string $sKey The key |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function val(string $sKey, $xValue) |
|
| 130 | - { |
|
| 131 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | - } |
|
| 129 | +public function val(string $sKey, $xValue) |
|
| 130 | +{ |
|
| 131 | +$this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * Get a class instance |
| 136 | 136 | * |
| 137 | 137 | * @template T |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return T |
| 141 | 141 | */ |
| 142 | - public function get(string $sClass) |
|
| 143 | - { |
|
| 144 | - return $this->xContainer->offsetGet($sClass); |
|
| 145 | - } |
|
| 142 | +public function get(string $sClass) |
|
| 143 | +{ |
|
| 144 | +return $this->xContainer->offsetGet($sClass); |
|
| 145 | +} |
|
| 146 | 146 | |
| 147 | - /** |
|
| 147 | +/** |
|
| 148 | 148 | * Get a component when one of its method needs to be called |
| 149 | 149 | * |
| 150 | 150 | * @template T |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return T|null |
| 155 | 155 | */ |
| 156 | - public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | - { |
|
| 158 | - // Set the target only when getting the object targetted by the ajax request. |
|
| 159 | - $this->xTarget = $xTarget; |
|
| 160 | - $xComponent = $this->get($sClassName); |
|
| 161 | - $this->xTarget = null; |
|
| 156 | +public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | +{ |
|
| 158 | +// Set the target only when getting the object targetted by the ajax request. |
|
| 159 | +$this->xTarget = $xTarget; |
|
| 160 | +$xComponent = $this->get($sClassName); |
|
| 161 | +$this->xTarget = null; |
|
| 162 | 162 | |
| 163 | - return $xComponent; |
|
| 164 | - } |
|
| 163 | +return $xComponent; |
|
| 164 | +} |
|
| 165 | 165 | |
| 166 | - /** |
|
| 166 | +/** |
|
| 167 | 167 | * Register a component and its options |
| 168 | 168 | * |
| 169 | 169 | * @param class-string $sClassName The class name |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | - { |
|
| 176 | - try |
|
| 177 | - { |
|
| 178 | - // Make sure the registered class exists |
|
| 179 | - if(isset($aOptions['include'])) |
|
| 180 | - { |
|
| 181 | - require_once $aOptions['include']; |
|
| 182 | - } |
|
| 183 | - $xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | - // Check if the class is registrable |
|
| 185 | - if(!$xReflectionClass->isInstantiable()) |
|
| 186 | - { |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $this->_saveClassOptions($sClassName, $aOptions); |
|
| 191 | - |
|
| 192 | - $sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | - $this->val($sClassKey, $xReflectionClass); |
|
| 194 | - // Register the user class, but only if the user didn't already. |
|
| 195 | - if(!$this->has($sClassName)) |
|
| 196 | - { |
|
| 197 | - $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - catch(ReflectionException $e) |
|
| 201 | - { |
|
| 202 | - throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | - ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | - } |
|
| 205 | - } |
|
| 174 | +public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | +{ |
|
| 176 | +try |
|
| 177 | +{ |
|
| 178 | +// Make sure the registered class exists |
|
| 179 | +if(isset($aOptions['include'])) |
|
| 180 | +{ |
|
| 181 | + require_once $aOptions['include']; |
|
| 182 | +} |
|
| 183 | +$xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | +// Check if the class is registrable |
|
| 185 | +if(!$xReflectionClass->isInstantiable()) |
|
| 186 | +{ |
|
| 187 | + return; |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +$this->_saveClassOptions($sClassName, $aOptions); |
|
| 206 | 191 | |
| 207 | - /** |
|
| 192 | +$sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | +$this->val($sClassKey, $xReflectionClass); |
|
| 194 | +// Register the user class, but only if the user didn't already. |
|
| 195 | +if(!$this->has($sClassName)) |
|
| 196 | +{ |
|
| 197 | + $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | +} |
|
| 199 | +} |
|
| 200 | +catch(ReflectionException $e) |
|
| 201 | +{ |
|
| 202 | +throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | + ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | +} |
|
| 205 | +} |
|
| 206 | + |
|
| 207 | +/** |
|
| 208 | 208 | * Register a component |
| 209 | 209 | * |
| 210 | 210 | * @param string $sComponentId The component name |
@@ -212,74 +212,74 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | * @throws SetupException |
| 214 | 214 | */ |
| 215 | - private function _registerComponent(string $sComponentId): string |
|
| 216 | - { |
|
| 217 | - // Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | - $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | - |
|
| 220 | - $sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | - // Prevent duplication. It's important not to use the class name here. |
|
| 222 | - if($this->has($sComponentObject)) |
|
| 223 | - { |
|
| 224 | - return $sClassName; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Register the helper class |
|
| 228 | - $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | - $xFactory = $this->di->getCallFactory(); |
|
| 230 | - return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | - $xFactory, $this->di->getViewRenderer(), |
|
| 232 | - $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | - $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | - }); |
|
| 235 | - |
|
| 236 | - $this->discoverComponent($sClassName); |
|
| 237 | - |
|
| 238 | - // Register the callable object |
|
| 239 | - $this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | - $aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | - $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | - $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | - return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | - }); |
|
| 245 | - |
|
| 246 | - // Initialize the user class instance |
|
| 247 | - $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | - if($xClassInstance instanceof AbstractComponent) |
|
| 249 | - { |
|
| 250 | - $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | - $xHelper->xTarget = $this->xTarget; |
|
| 252 | - |
|
| 253 | - // Call the protected "initComponent()" method of the Component class. |
|
| 254 | - $cSetter = function($di, $xHelper) { |
|
| 255 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | - }; |
|
| 257 | - $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | - call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Run the callbacks for class initialisation |
|
| 262 | - $this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | - |
|
| 264 | - // Set attributes from the DI container. |
|
| 265 | - // The class level DI options are set on any component. |
|
| 266 | - // The method level DI options are set only on the targetted component. |
|
| 267 | - /** @var CallableObject */ |
|
| 268 | - $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | - $xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | - if($this->xTarget !== null) |
|
| 271 | - { |
|
| 272 | - $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | - $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $xClassInstance; |
|
| 277 | - }); |
|
| 278 | - |
|
| 279 | - return $sClassName; |
|
| 280 | - } |
|
| 215 | +private function _registerComponent(string $sComponentId): string |
|
| 216 | +{ |
|
| 217 | +// Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | +$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | + |
|
| 220 | +$sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | +// Prevent duplication. It's important not to use the class name here. |
|
| 222 | +if($this->has($sComponentObject)) |
|
| 223 | +{ |
|
| 224 | +return $sClassName; |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +// Register the helper class |
|
| 228 | +$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | +$xFactory = $this->di->getCallFactory(); |
|
| 230 | +return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | + $xFactory, $this->di->getViewRenderer(), |
|
| 232 | + $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | + $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | +}); |
|
| 235 | + |
|
| 236 | +$this->discoverComponent($sClassName); |
|
| 237 | + |
|
| 238 | +// Register the callable object |
|
| 239 | +$this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | +$aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | +$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | +$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | +return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | +}); |
|
| 245 | + |
|
| 246 | +// Initialize the user class instance |
|
| 247 | +$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | +if($xClassInstance instanceof AbstractComponent) |
|
| 249 | +{ |
|
| 250 | + $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | + $xHelper->xTarget = $this->xTarget; |
|
| 252 | + |
|
| 253 | + // Call the protected "initComponent()" method of the Component class. |
|
| 254 | + $cSetter = function($di, $xHelper) { |
|
| 255 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | + }; |
|
| 257 | + $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | + call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +// Run the callbacks for class initialisation |
|
| 262 | +$this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | + |
|
| 264 | +// Set attributes from the DI container. |
|
| 265 | +// The class level DI options are set on any component. |
|
| 266 | +// The method level DI options are set only on the targetted component. |
|
| 267 | +/** @var CallableObject */ |
|
| 268 | +$xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | +$xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | +if($this->xTarget !== null) |
|
| 271 | +{ |
|
| 272 | + $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | + $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +return $xClassInstance; |
|
| 277 | +}); |
|
| 281 | 278 | |
| 282 | - /** |
|
| 279 | +return $sClassName; |
|
| 280 | +} |
|
| 281 | + |
|
| 282 | +/** |
|
| 283 | 283 | * Get the callable object for a given class |
| 284 | 284 | * The callable object is registered if it is not already in the DI. |
| 285 | 285 | * |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | * @return CallableObject|null |
| 289 | 289 | * @throws SetupException |
| 290 | 290 | */ |
| 291 | - public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | - { |
|
| 293 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | - return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | - } |
|
| 291 | +public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | +{ |
|
| 293 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | +return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | +} |
|
| 296 | 296 | |
| 297 | - /** |
|
| 297 | +/** |
|
| 298 | 298 | * Get an instance of a component by name |
| 299 | 299 | * |
| 300 | 300 | * @template T |
@@ -303,53 +303,53 @@ discard block |
||
| 303 | 303 | * @return T|null |
| 304 | 304 | * @throws SetupException |
| 305 | 305 | */ |
| 306 | - public function makeComponent(string $sClassName): mixed |
|
| 307 | - { |
|
| 308 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | - return $this->get($sClassName); |
|
| 311 | - } |
|
| 306 | +public function makeComponent(string $sClassName): mixed |
|
| 307 | +{ |
|
| 308 | +$sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | +return $this->get($sClassName); |
|
| 311 | +} |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | +/** |
|
| 314 | 314 | * Get a factory for a call to a registered function. |
| 315 | 315 | * |
| 316 | 316 | * @return JxnCall |
| 317 | 317 | */ |
| 318 | - public function getFunctionRequestFactory(): JxnCall |
|
| 319 | - { |
|
| 320 | - return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | - } |
|
| 318 | +public function getFunctionRequestFactory(): JxnCall |
|
| 319 | +{ |
|
| 320 | +return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | +} |
|
| 322 | 322 | |
| 323 | - /** |
|
| 323 | +/** |
|
| 324 | 324 | * Get a factory for a call to a registered component. |
| 325 | 325 | * |
| 326 | 326 | * @param class-string $sClassName |
| 327 | 327 | * |
| 328 | 328 | * @return JxnCall|null |
| 329 | 329 | */ |
| 330 | - public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 330 | +public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 331 | +{ |
|
| 332 | +$sClassName = trim($sClassName, " \t"); |
|
| 333 | +if($sClassName === '') |
|
| 334 | +{ |
|
| 335 | +return null; |
|
| 336 | +} |
|
| 337 | + |
|
| 338 | +$sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | +if(!$this->has($sFactoryKey)) |
|
| 340 | +{ |
|
| 341 | +$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | + $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | + if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 331 | 344 | { |
| 332 | - $sClassName = trim($sClassName, " \t"); |
|
| 333 | - if($sClassName === '') |
|
| 334 | - { |
|
| 335 | - return null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | - if(!$this->has($sFactoryKey)) |
|
| 340 | - { |
|
| 341 | - $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 344 | - { |
|
| 345 | - return null; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | - $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | - return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | - }); |
|
| 352 | - } |
|
| 353 | - return $this->get($sFactoryKey); |
|
| 345 | + return null; |
|
| 354 | 346 | } |
| 347 | + |
|
| 348 | + $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | + $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | + return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | +}); |
|
| 352 | +} |
|
| 353 | +return $this->get($sFactoryKey); |
|
| 354 | +} |
|
| 355 | 355 | } |
@@ -21,186 +21,186 @@ |
||
| 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 | - 'export' => [], |
|
| 30 | - 'container' => [], |
|
| 31 | - 'databag' => [], |
|
| 32 | - 'callback' => [], |
|
| 33 | - 'before' => [], |
|
| 34 | - 'after' => [], |
|
| 35 | - 'upload' => [], |
|
| 36 | - ]; |
|
| 37 | - |
|
| 38 | - /** |
|
| 27 | +private array $aAttributes = [ |
|
| 28 | +'exclude' => [], |
|
| 29 | +'export' => [], |
|
| 30 | +'container' => [], |
|
| 31 | +'databag' => [], |
|
| 32 | +'callback' => [], |
|
| 33 | +'before' => [], |
|
| 34 | +'after' => [], |
|
| 35 | +'upload' => [], |
|
| 36 | +]; |
|
| 37 | + |
|
| 38 | +/** |
|
| 39 | 39 | * @return array<string, array<string, Data\AbstractData>> |
| 40 | 40 | */ |
| 41 | - public function getAttributes(): array |
|
| 42 | - { |
|
| 43 | - return $this->aAttributes; |
|
| 44 | - } |
|
| 41 | +public function getAttributes(): array |
|
| 42 | +{ |
|
| 43 | +return $this->aAttributes; |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @param string $sMethod |
| 48 | 48 | * |
| 49 | 49 | * @return Data\ExcludeData |
| 50 | 50 | */ |
| 51 | - public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 52 | - { |
|
| 53 | - return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 54 | - $this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 55 | - } |
|
| 51 | +public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 52 | +{ |
|
| 53 | +return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 54 | +$this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @param string $sMethod |
| 59 | 59 | * |
| 60 | 60 | * @return Data\ExportData |
| 61 | 61 | */ |
| 62 | - public function export(string $sMethod = '*'): Data\ExportData |
|
| 63 | - { |
|
| 64 | - $sMethod = '*'; // On classes only |
|
| 65 | - return $this->aAttributes['export'][$sMethod] ?? |
|
| 66 | - $this->aAttributes['export'][$sMethod] = new Data\ExportData(); |
|
| 67 | - } |
|
| 62 | +public function export(string $sMethod = '*'): Data\ExportData |
|
| 63 | +{ |
|
| 64 | +$sMethod = '*'; // On classes only |
|
| 65 | +return $this->aAttributes['export'][$sMethod] ?? |
|
| 66 | +$this->aAttributes['export'][$sMethod] = new Data\ExportData(); |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * @param string $sMethod |
| 71 | 71 | * |
| 72 | 72 | * @return Data\ContainerData |
| 73 | 73 | */ |
| 74 | - public function container(string $sMethod = '*'): Data\ContainerData |
|
| 75 | - { |
|
| 76 | - return $this->aAttributes['container'][$sMethod] ?? |
|
| 77 | - $this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 78 | - } |
|
| 74 | +public function container(string $sMethod = '*'): Data\ContainerData |
|
| 75 | +{ |
|
| 76 | +return $this->aAttributes['container'][$sMethod] ?? |
|
| 77 | +$this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 78 | +} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * @param string $sMethod |
| 82 | 82 | * |
| 83 | 83 | * @return Data\DatabagData |
| 84 | 84 | */ |
| 85 | - public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 86 | - { |
|
| 87 | - return $this->aAttributes['databag'][$sMethod] ?? |
|
| 88 | - $this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 89 | - } |
|
| 85 | +public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 86 | +{ |
|
| 87 | +return $this->aAttributes['databag'][$sMethod] ?? |
|
| 88 | +$this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * @param string $sMethod |
| 93 | 93 | * |
| 94 | 94 | * @return Data\CallbackData |
| 95 | 95 | */ |
| 96 | - public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 97 | - { |
|
| 98 | - return $this->aAttributes['callback'][$sMethod] ?? |
|
| 99 | - $this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 100 | - } |
|
| 96 | +public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 97 | +{ |
|
| 98 | +return $this->aAttributes['callback'][$sMethod] ?? |
|
| 99 | +$this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - /** |
|
| 102 | +/** |
|
| 103 | 103 | * @param string $sMethod |
| 104 | 104 | * |
| 105 | 105 | * @return Data\BeforeData |
| 106 | 106 | */ |
| 107 | - public function before(string $sMethod = '*'): Data\BeforeData |
|
| 108 | - { |
|
| 109 | - return $this->aAttributes['before'][$sMethod] ?? |
|
| 110 | - $this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 111 | - } |
|
| 107 | +public function before(string $sMethod = '*'): Data\BeforeData |
|
| 108 | +{ |
|
| 109 | +return $this->aAttributes['before'][$sMethod] ?? |
|
| 110 | +$this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 111 | +} |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | +/** |
|
| 114 | 114 | * @param string $sMethod |
| 115 | 115 | * |
| 116 | 116 | * @return Data\AfterData |
| 117 | 117 | */ |
| 118 | - public function after(string $sMethod = '*'): Data\AfterData |
|
| 119 | - { |
|
| 120 | - return $this->aAttributes['after'][$sMethod] ?? |
|
| 121 | - $this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 122 | - } |
|
| 118 | +public function after(string $sMethod = '*'): Data\AfterData |
|
| 119 | +{ |
|
| 120 | +return $this->aAttributes['after'][$sMethod] ?? |
|
| 121 | +$this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * @param string $sMethod |
| 126 | 126 | * |
| 127 | 127 | * @return Data\UploadData |
| 128 | 128 | */ |
| 129 | - public function upload(string $sMethod = '*'): Data\UploadData |
|
| 130 | - { |
|
| 131 | - return $this->aAttributes['upload'][$sMethod] ?? |
|
| 132 | - $this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 133 | - } |
|
| 129 | +public function upload(string $sMethod = '*'): Data\UploadData |
|
| 130 | +{ |
|
| 131 | +return $this->aAttributes['upload'][$sMethod] ?? |
|
| 132 | +$this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 133 | +} |
|
| 134 | 134 | |
| 135 | - /** |
|
| 135 | +/** |
|
| 136 | 136 | * True if the class is excluded |
| 137 | 137 | * |
| 138 | 138 | * @return bool |
| 139 | 139 | */ |
| 140 | - public function isExcluded(): bool |
|
| 141 | - { |
|
| 142 | - $xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 143 | - return $xData !== null && $xData->getValue() === true; |
|
| 144 | - } |
|
| 140 | +public function isExcluded(): bool |
|
| 141 | +{ |
|
| 142 | +$xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 143 | +return $xData !== null && $xData->getValue() === true; |
|
| 144 | +} |
|
| 145 | 145 | |
| 146 | - /** |
|
| 146 | +/** |
|
| 147 | 147 | * Get the properties of the class methods |
| 148 | 148 | * |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - public function getProperties(): array |
|
| 151 | +public function getProperties(): array |
|
| 152 | +{ |
|
| 153 | +$aProperties = []; |
|
| 154 | +$aClassProperties = []; |
|
| 155 | +foreach($this->aAttributes as $sType => $aValues) |
|
| 156 | +{ |
|
| 157 | +if($sType === 'exclude') |
|
| 158 | +{ |
|
| 159 | + continue; |
|
| 160 | +} |
|
| 161 | + |
|
| 162 | +foreach($aValues as $sMethod => $xData) |
|
| 163 | +{ |
|
| 164 | + if($sMethod === '*') |
|
| 152 | 165 | { |
| 153 | - $aProperties = []; |
|
| 154 | - $aClassProperties = []; |
|
| 155 | - foreach($this->aAttributes as $sType => $aValues) |
|
| 156 | - { |
|
| 157 | - if($sType === 'exclude') |
|
| 158 | - { |
|
| 159 | - continue; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - foreach($aValues as $sMethod => $xData) |
|
| 163 | - { |
|
| 164 | - if($sMethod === '*') |
|
| 165 | - { |
|
| 166 | - $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 167 | - continue; |
|
| 168 | - } |
|
| 169 | - $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if(count($aClassProperties) > 0) |
|
| 174 | - { |
|
| 175 | - $aProperties['*'] = $aClassProperties; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $aProperties; |
|
| 166 | + $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 167 | + continue; |
|
| 179 | 168 | } |
| 169 | + $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 170 | +} |
|
| 171 | +} |
|
| 172 | + |
|
| 173 | +if(count($aClassProperties) > 0) |
|
| 174 | +{ |
|
| 175 | +$aProperties['*'] = $aClassProperties; |
|
| 176 | +} |
|
| 180 | 177 | |
| 181 | - /** |
|
| 178 | +return $aProperties; |
|
| 179 | +} |
|
| 180 | + |
|
| 181 | +/** |
|
| 182 | 182 | * Get the methods in the export attributes |
| 183 | 183 | * |
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - public function getExportMethods(): array |
|
| 187 | - { |
|
| 188 | - /** @var Data\ExportData */ |
|
| 189 | - $xExportData = $this->aAttributes['export']['*'] ?? null; |
|
| 190 | - return $xExportData?->getMethods() ?? []; |
|
| 191 | - } |
|
| 186 | +public function getExportMethods(): array |
|
| 187 | +{ |
|
| 188 | +/** @var Data\ExportData */ |
|
| 189 | +$xExportData = $this->aAttributes['export']['*'] ?? null; |
|
| 190 | +return $xExportData?->getMethods() ?? []; |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - /** |
|
| 193 | +/** |
|
| 194 | 194 | * Get the protected methods |
| 195 | 195 | * |
| 196 | 196 | * @return array |
| 197 | 197 | */ |
| 198 | - public function getProtectedMethods(): array |
|
| 199 | - { |
|
| 200 | - /** @var array<Data\ExcludeData> */ |
|
| 201 | - $aAttributes = $this->aAttributes['exclude']; |
|
| 202 | - $aMethods = array_keys($aAttributes); |
|
| 203 | - return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 204 | - $sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 205 | - } |
|
| 198 | +public function getProtectedMethods(): array |
|
| 199 | +{ |
|
| 200 | +/** @var array<Data\ExcludeData> */ |
|
| 201 | +$aAttributes = $this->aAttributes['exclude']; |
|
| 202 | +$aMethods = array_keys($aAttributes); |
|
| 203 | +return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 204 | +$sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 205 | +} |
|
| 206 | 206 | } |
@@ -21,59 +21,59 @@ |
||
| 21 | 21 | |
| 22 | 22 | abstract class HookData extends AbstractData |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $aCalls = []; |
|
| 27 | +protected $aCalls = []; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | - abstract protected function getType(): string; |
|
| 32 | +abstract protected function getType(): string; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | - public function getName(): string |
|
| 38 | - { |
|
| 39 | - return '__' . $this->getType(); |
|
| 40 | - } |
|
| 37 | +public function getName(): string |
|
| 38 | +{ |
|
| 39 | +return '__' . $this->getType(); |
|
| 40 | +} |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - public function getValue(): mixed |
|
| 46 | - { |
|
| 47 | - return $this->aCalls; |
|
| 48 | - } |
|
| 45 | +public function getValue(): mixed |
|
| 46 | +{ |
|
| 47 | +return $this->aCalls; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * @param string $sMethod |
| 52 | 52 | * @param array $aParams |
| 53 | 53 | * |
| 54 | 54 | * @return void |
| 55 | 55 | */ |
| 56 | - public function addCall(string $sMethod, array $aParams): void |
|
| 57 | - { |
|
| 58 | - if(!$this->validateMethod($sMethod)) |
|
| 59 | - { |
|
| 60 | - $sType = $this->getType(); |
|
| 61 | - throw new SetupException("'$sMethod' is not a valid \"call\" value for $sType."); |
|
| 62 | - } |
|
| 63 | - $this->aCalls[$sMethod] = $aParams; |
|
| 64 | - } |
|
| 56 | +public function addCall(string $sMethod, array $aParams): void |
|
| 57 | +{ |
|
| 58 | +if(!$this->validateMethod($sMethod)) |
|
| 59 | +{ |
|
| 60 | +$sType = $this->getType(); |
|
| 61 | +throw new SetupException("'$sMethod' is not a valid \"call\" value for $sType."); |
|
| 62 | +} |
|
| 63 | +$this->aCalls[$sMethod] = $aParams; |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * @inheritDoc |
| 68 | 68 | */ |
| 69 | - public function encode(string $sVarName): array |
|
| 70 | - { |
|
| 71 | - $aCalls = []; |
|
| 72 | - foreach($this->aCalls as $sMethod => $aParams) |
|
| 73 | - { |
|
| 74 | - $sParams = addslashes(json_encode($aParams)); |
|
| 75 | - $aCalls[] = "{$sVarName}->addCall('$sMethod', json_decode(\"$sParams\", true));"; |
|
| 76 | - } |
|
| 77 | - return $aCalls; |
|
| 78 | - } |
|
| 69 | +public function encode(string $sVarName): array |
|
| 70 | +{ |
|
| 71 | +$aCalls = []; |
|
| 72 | +foreach($this->aCalls as $sMethod => $aParams) |
|
| 73 | +{ |
|
| 74 | +$sParams = addslashes(json_encode($aParams)); |
|
| 75 | +$aCalls[] = "{$sVarName}->addCall('$sMethod', json_decode(\"$sParams\", true));"; |
|
| 76 | +} |
|
| 77 | +return $aCalls; |
|
| 78 | +} |
|
| 79 | 79 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function addCall(string $sMethod, array $aParams): void |
| 57 | 57 | { |
| 58 | - if(!$this->validateMethod($sMethod)) |
|
| 58 | + if (!$this->validateMethod($sMethod)) |
|
| 59 | 59 | { |
| 60 | 60 | $sType = $this->getType(); |
| 61 | 61 | throw new SetupException("'$sMethod' is not a valid \"call\" value for $sType."); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function encode(string $sVarName): array |
| 70 | 70 | { |
| 71 | 71 | $aCalls = []; |
| 72 | - foreach($this->aCalls as $sMethod => $aParams) |
|
| 72 | + foreach ($this->aCalls as $sMethod => $aParams) |
|
| 73 | 73 | { |
| 74 | 74 | $sParams = addslashes(json_encode($aParams)); |
| 75 | 75 | $aCalls[] = "{$sVarName}->addCall('$sMethod', json_decode(\"$sParams\", true));"; |
@@ -18,22 +18,22 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class AbstractData |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Generate the PHP code to populate a Metadata object |
| 23 | 23 | * |
| 24 | 24 | * @param string $sVarName |
| 25 | 25 | * |
| 26 | 26 | * @return array |
| 27 | 27 | */ |
| 28 | - abstract public function encode(string $sVarName): array; |
|
| 28 | +abstract public function encode(string $sVarName): array; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @param string $sMethod |
| 32 | 32 | * |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - protected function validateMethod(string $sMethod): bool |
|
| 36 | - { |
|
| 37 | - return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 38 | - } |
|
| 35 | +protected function validateMethod(string $sMethod): bool |
|
| 36 | +{ |
|
| 37 | +return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 38 | +} |
|
| 39 | 39 | } |
@@ -22,53 +22,53 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ExportData extends AbstractData |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * @var array |
| 27 | 27 | */ |
| 28 | - private array $aMethods = []; |
|
| 28 | +private array $aMethods = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function getName(): string |
|
| 34 | - { |
|
| 35 | - return 'export'; |
|
| 36 | - } |
|
| 33 | +public function getName(): string |
|
| 34 | +{ |
|
| 35 | +return 'export'; |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @return mixed |
| 40 | 40 | */ |
| 41 | - public function getMethods(): mixed |
|
| 42 | - { |
|
| 43 | - return $this->aMethods; |
|
| 44 | - } |
|
| 41 | +public function getMethods(): mixed |
|
| 42 | +{ |
|
| 43 | +return $this->aMethods; |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @param array $aMethods |
| 48 | 48 | * |
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | - public function setMethods(array $aMethods): void |
|
| 51 | +public function setMethods(array $aMethods): void |
|
| 52 | +{ |
|
| 53 | +foreach(['base', 'only', 'except'] as $sKey) |
|
| 54 | +{ |
|
| 55 | +foreach($aMethods[$sKey] as $sMethod) |
|
| 56 | +{ |
|
| 57 | + if(!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 52 | 58 | { |
| 53 | - foreach(['base', 'only', 'except'] as $sKey) |
|
| 54 | - { |
|
| 55 | - foreach($aMethods[$sKey] as $sMethod) |
|
| 56 | - { |
|
| 57 | - if(!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 58 | - { |
|
| 59 | - throw new SetupException("'$sMethod' is not a valid method name."); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $this->aMethods = $aMethods; |
|
| 59 | + throw new SetupException("'$sMethod' is not a valid method name."); |
|
| 64 | 60 | } |
| 61 | +} |
|
| 62 | +} |
|
| 63 | +$this->aMethods = $aMethods; |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * @inheritDoc |
| 68 | 68 | */ |
| 69 | - public function encode(string $sVarName): array |
|
| 70 | - { |
|
| 71 | - $sMethods = addslashes(json_encode($this->aMethods)); |
|
| 72 | - return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"]; |
|
| 73 | - } |
|
| 69 | +public function encode(string $sVarName): array |
|
| 70 | +{ |
|
| 71 | +$sMethods = addslashes(json_encode($this->aMethods)); |
|
| 72 | +return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"]; |
|
| 73 | +} |
|
| 74 | 74 | } |
@@ -50,11 +50,11 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | public function setMethods(array $aMethods): void |
| 52 | 52 | { |
| 53 | - foreach(['base', 'only', 'except'] as $sKey) |
|
| 53 | + foreach (['base', 'only', 'except'] as $sKey) |
|
| 54 | 54 | { |
| 55 | - foreach($aMethods[$sKey] as $sMethod) |
|
| 55 | + foreach ($aMethods[$sKey] as $sMethod) |
|
| 56 | 56 | { |
| 57 | - if(!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 57 | + if (!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 58 | 58 | { |
| 59 | 59 | throw new SetupException("'$sMethod' is not a valid method name."); |
| 60 | 60 | } |
@@ -73,8 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function excluded(?string $sMethodName = null): bool |
| 75 | 75 | { |
| 76 | - return $sMethodName === null ? $this->xOptions->excluded() : |
|
| 77 | - !$this->xOptions->isPublicMethod($sMethodName); |
|
| 76 | + return $sMethodName === null ? $this->xOptions->excluded() : !$this->xOptions->isPublicMethod($sMethodName); |
|
| 78 | 77 | } |
| 79 | 78 | |
| 80 | 79 | /** |
@@ -160,11 +159,11 @@ discard block |
||
| 160 | 159 | $sMethod = $this->xTarget->getMethodName(); |
| 161 | 160 | // The hooks defined at method level are merged with those defined at class level. |
| 162 | 161 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
| 163 | - foreach($aMethods as $xKey => $xValue) |
|
| 162 | + foreach ($aMethods as $xKey => $xValue) |
|
| 164 | 163 | { |
| 165 | 164 | $sHookName = $xValue; |
| 166 | 165 | $aHookArgs = []; |
| 167 | - if(is_string($xKey)) |
|
| 166 | + if (is_string($xKey)) |
|
| 168 | 167 | { |
| 169 | 168 | $sHookName = $xKey; |
| 170 | 169 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -202,7 +201,7 @@ discard block |
||
| 202 | 201 | // Warning: dynamic properties will be deprecated in PHP8.2. |
| 203 | 202 | $this->$sAttr = $xDiValue; |
| 204 | 203 | }; |
| 205 | - foreach($aDiOptions as $sAttr => $sClass) |
|
| 204 | + foreach ($aDiOptions as $sAttr => $sClass) |
|
| 206 | 205 | { |
| 207 | 206 | $this->setDiAttribute($xComponent, $sAttr, $this->di->get($sClass), $cSetter); |
| 208 | 207 | } |
@@ -107,33 +107,33 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $this->bExcluded = ($xMetadata?->isExcluded() ?? false) || |
| 109 | 109 | (bool)($aOptions['excluded'] ?? false); |
| 110 | - if($this->bExcluded) |
|
| 110 | + if ($this->bExcluded) |
|
| 111 | 111 | { |
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $sSeparator = $aOptions['separator']; |
| 116 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 116 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
| 117 | 117 | { |
| 118 | 118 | $this->sSeparator = $sSeparator; |
| 119 | 119 | } |
| 120 | 120 | $this->addProtectedMethods($aOptions['protected']); |
| 121 | 121 | |
| 122 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 122 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 123 | 123 | { |
| 124 | 124 | // Names are in a comma-separated list. |
| 125 | 125 | $aFunctionNames = explode(',', $sNames); |
| 126 | - foreach($aFunctionNames as $sFunctionName) |
|
| 126 | + foreach ($aFunctionNames as $sFunctionName) |
|
| 127 | 127 | { |
| 128 | 128 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($xMetadata !== null) |
|
| 132 | + if ($xMetadata !== null) |
|
| 133 | 133 | { |
| 134 | 134 | $this->aExportMethods = $xMetadata->getExportMethods(); |
| 135 | 135 | $this->addProtectedMethods($xMetadata->getProtectedMethods()); |
| 136 | - foreach($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions) |
|
| 136 | + foreach ($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions) |
|
| 137 | 137 | { |
| 138 | 138 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
| 139 | 139 | } |
@@ -150,8 +150,7 @@ discard block |
||
| 150 | 150 | private function addProtectedMethods(array|string $xMethods): void |
| 151 | 151 | { |
| 152 | 152 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, |
| 153 | - !is_array($xMethods) ? [trim((string)$xMethods)] : |
|
| 154 | - array_map(fn($sMethod) => trim((string)$sMethod), $xMethods)); |
|
| 153 | + !is_array($xMethods) ? [trim((string)$xMethods)] : array_map(fn($sMethod) => trim((string)$sMethod), $xMethods)); |
|
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 156 | /** |
@@ -161,7 +160,7 @@ discard block |
||
| 161 | 160 | */ |
| 162 | 161 | private function filterPublicMethods(array $aMethods): array |
| 163 | 162 | { |
| 164 | - if($this->bExcluded || in_array('*', $this->aProtectedMethods)) |
|
| 163 | + if ($this->bExcluded || in_array('*', $this->aProtectedMethods)) |
|
| 165 | 164 | { |
| 166 | 165 | return []; |
| 167 | 166 | } |
@@ -169,13 +168,13 @@ discard block |
||
| 169 | 168 | $aBaseMethods = $aMethods[1]; |
| 170 | 169 | $aMethods = $aMethods[0]; |
| 171 | 170 | |
| 172 | - if(isset($this->aExportMethods['only'])) |
|
| 171 | + if (isset($this->aExportMethods['only'])) |
|
| 173 | 172 | { |
| 174 | 173 | $aMethods = array_intersect($aMethods, $this->aExportMethods['only']); |
| 175 | 174 | } |
| 176 | 175 | $aMethods = array_diff($aMethods, $this->aProtectedMethods, |
| 177 | 176 | $this->aExportMethods['except'] ?? []); |
| 178 | - if(count($aBaseMethods) > 0 && isset($this->aExportMethods['base'])) |
|
| 177 | + if (count($aBaseMethods) > 0 && isset($this->aExportMethods['base'])) |
|
| 179 | 178 | { |
| 180 | 179 | $aBaseMethods = array_diff($aBaseMethods, $this->aExportMethods['base']); |
| 181 | 180 | } |
@@ -253,17 +252,17 @@ discard block |
||
| 253 | 252 | */ |
| 254 | 253 | private function setHookMethods(array &$aHookMethods, $xValue): void |
| 255 | 254 | { |
| 256 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 255 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
| 257 | 256 | { |
| 258 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 257 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
| 259 | 258 | { |
| 260 | 259 | $aHookMethods[$sCalledMethod] = []; |
| 261 | 260 | } |
| 262 | - if(is_array($xMethodToCall)) |
|
| 261 | + if (is_array($xMethodToCall)) |
|
| 263 | 262 | { |
| 264 | 263 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
| 265 | 264 | } |
| 266 | - elseif(is_string($xMethodToCall)) |
|
| 265 | + elseif (is_string($xMethodToCall)) |
|
| 267 | 266 | { |
| 268 | 267 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
| 269 | 268 | } |
@@ -288,7 +287,7 @@ discard block |
||
| 288 | 287 | */ |
| 289 | 288 | private function addOption(string $sName, $xValue): void |
| 290 | 289 | { |
| 291 | - switch($sName) |
|
| 290 | + switch ($sName) |
|
| 292 | 291 | { |
| 293 | 292 | // Set the methods to call before processing the request |
| 294 | 293 | case '__before': |
@@ -316,11 +315,11 @@ discard block |
||
| 316 | 315 | */ |
| 317 | 316 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 318 | 317 | { |
| 319 | - if(is_string($xOptionValue)) |
|
| 318 | + if (is_string($xOptionValue)) |
|
| 320 | 319 | { |
| 321 | 320 | $xOptionValue = [$xOptionValue]; |
| 322 | 321 | } |
| 323 | - if(!is_array($xOptionValue)) |
|
| 322 | + if (!is_array($xOptionValue)) |
|
| 324 | 323 | { |
| 325 | 324 | return; // Do not save. |
| 326 | 325 | } |
@@ -350,10 +349,10 @@ discard block |
||
| 350 | 349 | */ |
| 351 | 350 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue): void |
| 352 | 351 | { |
| 353 | - switch($sOptionName) |
|
| 352 | + switch ($sOptionName) |
|
| 354 | 353 | { |
| 355 | 354 | case 'excluded': |
| 356 | - if((bool)$xOptionValue) |
|
| 355 | + if ((bool)$xOptionValue) |
|
| 357 | 356 | { |
| 358 | 357 | $this->addProtectedMethods($sFunctionName); |
| 359 | 358 | } |
@@ -377,12 +376,11 @@ discard block |
||
| 377 | 376 | */ |
| 378 | 377 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions): void |
| 379 | 378 | { |
| 380 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 379 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
| 381 | 380 | { |
| 382 | 381 | substr($sOptionName, 0, 2) === '__' ? |
| 383 | 382 | // Options for PHP classes. They start with "__". |
| 384 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
| 385 | - // Options for javascript code. |
|
| 383 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
| 386 | 384 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
| 387 | 385 | } |
| 388 | 386 | } |
@@ -398,16 +396,15 @@ discard block |
||
| 398 | 396 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
| 399 | 397 | // Then add the method options. |
| 400 | 398 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
| 401 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 399 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
| 402 | 400 | { |
| 403 | 401 | // For databags and callbacks, merge the values in a single array. |
| 404 | 402 | // For all the other options, keep the last value. |
| 405 | 403 | $aOptions[$sOptionName] = !in_array($sOptionName, ['bags', 'callback']) ? |
| 406 | - $xOptionValue : |
|
| 407 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 404 | + $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
| 408 | 405 | } |
| 409 | 406 | // Since callbacks are js object names, they need a special formatting. |
| 410 | - if(isset($aOptions['callback'])) |
|
| 407 | + if (isset($aOptions['callback'])) |
|
| 411 | 408 | { |
| 412 | 409 | $aOptions['callback'] = str_replace('"', '', json_encode($aOptions['callback'])); |
| 413 | 410 | } |
@@ -38,9 +38,9 @@ |
||
| 38 | 38 | public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
| 39 | 39 | { |
| 40 | 40 | $aMethods = []; |
| 41 | - foreach(['base', 'only', 'except'] as $key) |
|
| 41 | + foreach (['base', 'only', 'except'] as $key) |
|
| 42 | 42 | { |
| 43 | - if($this->$key !== null && count($this->$key) > 0) |
|
| 43 | + if ($this->$key !== null && count($this->$key) > 0) |
|
| 44 | 44 | { |
| 45 | 45 | $aMethods[$key] = $this->$key; |
| 46 | 46 | } |