@@ -241,83 +241,83 @@ |
||
| 241 | 241 | $this->aComponentPublicMethods['node'], |
| 242 | 242 | $xReflectionClass->isSubclassOf(FuncComponent::class) => |
| 243 | 243 | $this->aComponentPublicMethods['func'], |
| 244 | - default => [[], []], |
|
| 245 | - }; |
|
| 244 | +default => [[], []], |
|
| 245 | +}; |
|
| 246 | 246 | |
| 247 | - return [$aMethods, ...$aBaseMethods]; |
|
| 248 | - } |
|
| 247 | +return [$aMethods, ...$aBaseMethods]; |
|
| 248 | +} |
|
| 249 | 249 | |
| 250 | - /** |
|
| 250 | +/** |
|
| 251 | 251 | * @param ReflectionClass $xReflectionClass |
| 252 | 252 | * @param array $aMethods |
| 253 | 253 | * @param array $aOptions |
| 254 | 254 | * |
| 255 | 255 | * @return Metadata|null |
| 256 | 256 | */ |
| 257 | - private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 258 | - array $aMethods, array $aOptions): Metadata|null |
|
| 259 | - { |
|
| 260 | - /** @var Config|null */ |
|
| 261 | - $xPackageConfig = $aOptions['config'] ?? null; |
|
| 262 | - if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 263 | - { |
|
| 264 | - return null; |
|
| 265 | - } |
|
| 266 | - $sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 267 | - if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 268 | - { |
|
| 269 | - return null; |
|
| 270 | - } |
|
| 257 | +private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 258 | +array $aMethods, array $aOptions): Metadata|null |
|
| 259 | +{ |
|
| 260 | +/** @var Config|null */ |
|
| 261 | +$xPackageConfig = $aOptions['config'] ?? null; |
|
| 262 | +if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 263 | +{ |
|
| 264 | +return null; |
|
| 265 | +} |
|
| 266 | +$sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 267 | +if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 268 | +{ |
|
| 269 | +return null; |
|
| 270 | +} |
|
| 271 | 271 | |
| 272 | - // Try to get the class metadata from the cache. |
|
| 273 | - $di = $this->cn(); |
|
| 274 | - $xMetadata = null; |
|
| 275 | - $xMetadataCache = null; |
|
| 276 | - $xConfig = $di->config(); |
|
| 277 | - if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 278 | - { |
|
| 279 | - if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 280 | - { |
|
| 281 | - $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 282 | - $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 283 | - } |
|
| 284 | - $xMetadataCache = $di->getMetadataCache(); |
|
| 285 | - $xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 286 | - if($xMetadata !== null) |
|
| 287 | - { |
|
| 288 | - return $xMetadata; |
|
| 289 | - } |
|
| 290 | - } |
|
| 272 | +// Try to get the class metadata from the cache. |
|
| 273 | +$di = $this->cn(); |
|
| 274 | +$xMetadata = null; |
|
| 275 | +$xMetadataCache = null; |
|
| 276 | +$xConfig = $di->config(); |
|
| 277 | +if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 278 | +{ |
|
| 279 | +if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 280 | +{ |
|
| 281 | + $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 282 | + $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 283 | +} |
|
| 284 | +$xMetadataCache = $di->getMetadataCache(); |
|
| 285 | +$xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 286 | +if($xMetadata !== null) |
|
| 287 | +{ |
|
| 288 | + return $xMetadata; |
|
| 289 | +} |
|
| 290 | +} |
|
| 291 | 291 | |
| 292 | - $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 293 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 294 | - ReflectionProperty::IS_PROTECTED)); |
|
| 292 | +$aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 293 | +$xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 294 | + ReflectionProperty::IS_PROTECTED)); |
|
| 295 | 295 | |
| 296 | - $xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 297 | - $xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 298 | - $xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 296 | +$xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 297 | +$xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 298 | +$xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 299 | 299 | |
| 300 | - // Try to save the metadata in the cache |
|
| 301 | - if($xMetadataCache !== null) |
|
| 302 | - { |
|
| 303 | - $xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 304 | - } |
|
| 300 | +// Try to save the metadata in the cache |
|
| 301 | +if($xMetadataCache !== null) |
|
| 302 | +{ |
|
| 303 | +$xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 304 | +} |
|
| 305 | 305 | |
| 306 | - return $xMetadata; |
|
| 307 | - } |
|
| 306 | +return $xMetadata; |
|
| 307 | +} |
|
| 308 | 308 | |
| 309 | - /** |
|
| 309 | +/** |
|
| 310 | 310 | * @param ReflectionClass $xReflectionClass |
| 311 | 311 | * @param array $aOptions |
| 312 | 312 | * |
| 313 | 313 | * @return ComponentOptions |
| 314 | 314 | */ |
| 315 | - public function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 316 | - array $aOptions): ComponentOptions |
|
| 317 | - { |
|
| 318 | - $aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 319 | - $xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 315 | +public function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 316 | +array $aOptions): ComponentOptions |
|
| 317 | +{ |
|
| 318 | +$aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 319 | +$xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 320 | 320 | |
| 321 | - return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 322 | - } |
|
| 321 | +return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 322 | +} |
|
| 323 | 323 | } |
@@ -35,154 +35,154 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | trait PluginTrait |
| 37 | 37 | { |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * Register the values into the container |
| 40 | 40 | * |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - private function registerPlugins(): void |
|
| 44 | - { |
|
| 45 | - // Plugin manager |
|
| 46 | - $this->set(PluginManager::class, function($di) { |
|
| 47 | - $xPluginManager = new PluginManager($di->g(Container::class), |
|
| 48 | - $di->g(CodeGenerator::class), $di->g(Translator::class)); |
|
| 49 | - // Register the Jaxon request and response plugins |
|
| 50 | - $xPluginManager->registerPlugins(); |
|
| 51 | - return $xPluginManager; |
|
| 52 | - }); |
|
| 53 | - // Package manager |
|
| 54 | - $this->set(PackageManager::class, function($di) { |
|
| 55 | - return new PackageManager($di->g(Container::class), $di->g(Translator::class), |
|
| 56 | - $di->g(PluginManager::class), $di->g(ConfigManager::class), |
|
| 57 | - $di->g(CodeGenerator::class), $di->g(ViewRenderer::class), |
|
| 58 | - $di->g(CallbackManager::class), $di->g(ComponentRegistry::class)); |
|
| 59 | - }); |
|
| 60 | - // Code Generation |
|
| 61 | - $this->set(MinifierInterface::class, function() { |
|
| 62 | - return new class extends FileMinifier implements MinifierInterface |
|
| 63 | - {}; |
|
| 64 | - }); |
|
| 65 | - $this->set(AssetManager::class, function($di) { |
|
| 66 | - return new AssetManager($di->g(ConfigManager::class), |
|
| 67 | - $di->g(MinifierInterface::class)); |
|
| 68 | - }); |
|
| 69 | - $this->set(CodeGenerator::class, function($di) { |
|
| 70 | - return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class), |
|
| 71 | - $di->g(TemplateEngine::class)); |
|
| 72 | - }); |
|
| 73 | - $this->set(ConfigScriptGenerator::class, function($di) { |
|
| 74 | - return new ConfigScriptGenerator($di->g(ParameterReader::class), |
|
| 75 | - $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 76 | - }); |
|
| 77 | - $this->set(ReadyScriptGenerator::class, function($di) { |
|
| 78 | - return new ReadyScriptGenerator(); |
|
| 79 | - }); |
|
| 80 | - |
|
| 81 | - // Script response plugin |
|
| 82 | - $this->set(ScriptPlugin::class, function($di) { |
|
| 83 | - return new ScriptPlugin($di->g(CallFactory::class)); |
|
| 84 | - }); |
|
| 85 | - // Databag response plugin |
|
| 86 | - $this->set(DatabagPlugin::class, function($di) { |
|
| 87 | - return new DatabagPlugin($di->g(Container::class)); |
|
| 88 | - }); |
|
| 89 | - // Dialog response plugin |
|
| 90 | - $this->set(DialogPlugin::class, function($di) { |
|
| 91 | - return new DialogPlugin($di->g(DialogCommand::class)); |
|
| 92 | - }); |
|
| 93 | - // Paginator response plugin |
|
| 94 | - $this->set(PaginatorPlugin::class, function($di) { |
|
| 95 | - return new PaginatorPlugin($di->g(RendererInterface::class)); |
|
| 96 | - }); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 43 | +private function registerPlugins(): void |
|
| 44 | +{ |
|
| 45 | +// Plugin manager |
|
| 46 | +$this->set(PluginManager::class, function($di) { |
|
| 47 | +$xPluginManager = new PluginManager($di->g(Container::class), |
|
| 48 | + $di->g(CodeGenerator::class), $di->g(Translator::class)); |
|
| 49 | +// Register the Jaxon request and response plugins |
|
| 50 | +$xPluginManager->registerPlugins(); |
|
| 51 | +return $xPluginManager; |
|
| 52 | +}); |
|
| 53 | +// Package manager |
|
| 54 | +$this->set(PackageManager::class, function($di) { |
|
| 55 | +return new PackageManager($di->g(Container::class), $di->g(Translator::class), |
|
| 56 | + $di->g(PluginManager::class), $di->g(ConfigManager::class), |
|
| 57 | + $di->g(CodeGenerator::class), $di->g(ViewRenderer::class), |
|
| 58 | + $di->g(CallbackManager::class), $di->g(ComponentRegistry::class)); |
|
| 59 | +}); |
|
| 60 | +// Code Generation |
|
| 61 | +$this->set(MinifierInterface::class, function() { |
|
| 62 | +return new class extends FileMinifier implements MinifierInterface |
|
| 63 | +{}; |
|
| 64 | +}); |
|
| 65 | +$this->set(AssetManager::class, function($di) { |
|
| 66 | +return new AssetManager($di->g(ConfigManager::class), |
|
| 67 | + $di->g(MinifierInterface::class)); |
|
| 68 | +}); |
|
| 69 | +$this->set(CodeGenerator::class, function($di) { |
|
| 70 | +return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class), |
|
| 71 | + $di->g(TemplateEngine::class)); |
|
| 72 | +}); |
|
| 73 | +$this->set(ConfigScriptGenerator::class, function($di) { |
|
| 74 | +return new ConfigScriptGenerator($di->g(ParameterReader::class), |
|
| 75 | + $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 76 | +}); |
|
| 77 | +$this->set(ReadyScriptGenerator::class, function($di) { |
|
| 78 | +return new ReadyScriptGenerator(); |
|
| 79 | +}); |
|
| 80 | + |
|
| 81 | +// Script response plugin |
|
| 82 | +$this->set(ScriptPlugin::class, function($di) { |
|
| 83 | +return new ScriptPlugin($di->g(CallFactory::class)); |
|
| 84 | +}); |
|
| 85 | +// Databag response plugin |
|
| 86 | +$this->set(DatabagPlugin::class, function($di) { |
|
| 87 | +return new DatabagPlugin($di->g(Container::class)); |
|
| 88 | +}); |
|
| 89 | +// Dialog response plugin |
|
| 90 | +$this->set(DialogPlugin::class, function($di) { |
|
| 91 | +return new DialogPlugin($di->g(DialogCommand::class)); |
|
| 92 | +}); |
|
| 93 | +// Paginator response plugin |
|
| 94 | +$this->set(PaginatorPlugin::class, function($di) { |
|
| 95 | +return new PaginatorPlugin($di->g(RendererInterface::class)); |
|
| 96 | +}); |
|
| 97 | +} |
|
| 98 | + |
|
| 99 | +/** |
|
| 100 | 100 | * Get the plugin manager |
| 101 | 101 | * |
| 102 | 102 | * @return PluginManager |
| 103 | 103 | */ |
| 104 | - public function getPluginManager(): PluginManager |
|
| 105 | - { |
|
| 106 | - return $this->g(PluginManager::class); |
|
| 107 | - } |
|
| 104 | +public function getPluginManager(): PluginManager |
|
| 105 | +{ |
|
| 106 | +return $this->g(PluginManager::class); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Get the package manager |
| 111 | 111 | * |
| 112 | 112 | * @return PackageManager |
| 113 | 113 | */ |
| 114 | - public function getPackageManager(): PackageManager |
|
| 115 | - { |
|
| 116 | - return $this->g(PackageManager::class); |
|
| 117 | - } |
|
| 114 | +public function getPackageManager(): PackageManager |
|
| 115 | +{ |
|
| 116 | +return $this->g(PackageManager::class); |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - /** |
|
| 119 | +/** |
|
| 120 | 120 | * Get the code generator |
| 121 | 121 | * |
| 122 | 122 | * @return CodeGenerator |
| 123 | 123 | */ |
| 124 | - public function getCodeGenerator(): CodeGenerator |
|
| 125 | - { |
|
| 126 | - return $this->g(CodeGenerator::class); |
|
| 127 | - } |
|
| 124 | +public function getCodeGenerator(): CodeGenerator |
|
| 125 | +{ |
|
| 126 | +return $this->g(CodeGenerator::class); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - /** |
|
| 129 | +/** |
|
| 130 | 130 | * Get the asset manager |
| 131 | 131 | * |
| 132 | 132 | * @return AssetManager |
| 133 | 133 | */ |
| 134 | - public function getAssetManager(): AssetManager |
|
| 135 | - { |
|
| 136 | - return $this->g(AssetManager::class); |
|
| 137 | - } |
|
| 134 | +public function getAssetManager(): AssetManager |
|
| 135 | +{ |
|
| 136 | +return $this->g(AssetManager::class); |
|
| 137 | +} |
|
| 138 | 138 | |
| 139 | - /** |
|
| 139 | +/** |
|
| 140 | 140 | * Get the jQuery plugin |
| 141 | 141 | * |
| 142 | 142 | * @return ScriptPlugin |
| 143 | 143 | */ |
| 144 | - public function getScriptPlugin(): ScriptPlugin |
|
| 145 | - { |
|
| 146 | - return $this->g(ScriptPlugin::class); |
|
| 147 | - } |
|
| 144 | +public function getScriptPlugin(): ScriptPlugin |
|
| 145 | +{ |
|
| 146 | +return $this->g(ScriptPlugin::class); |
|
| 147 | +} |
|
| 148 | 148 | |
| 149 | - /** |
|
| 149 | +/** |
|
| 150 | 150 | * Get the dialog plugin |
| 151 | 151 | * |
| 152 | 152 | * @return DialogPlugin |
| 153 | 153 | */ |
| 154 | - public function getDialogPlugin(): DialogPlugin |
|
| 155 | - { |
|
| 156 | - return $this->g(DialogPlugin::class); |
|
| 157 | - } |
|
| 154 | +public function getDialogPlugin(): DialogPlugin |
|
| 155 | +{ |
|
| 156 | +return $this->g(DialogPlugin::class); |
|
| 157 | +} |
|
| 158 | 158 | |
| 159 | - /** |
|
| 159 | +/** |
|
| 160 | 160 | * @param class-string $sClassName The package class name |
| 161 | 161 | * |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - private function getPackageConfigKey(string $sClassName): string |
|
| 165 | - { |
|
| 166 | - return $sClassName . '_PackageConfig'; |
|
| 167 | - } |
|
| 164 | +private function getPackageConfigKey(string $sClassName): string |
|
| 165 | +{ |
|
| 166 | +return $sClassName . '_PackageConfig'; |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * @param class-string $sClassName The package class name |
| 171 | 171 | * @param-closure-this AbstractPackage $cSetter |
| 172 | 172 | * |
| 173 | 173 | * @return void |
| 174 | 174 | */ |
| 175 | - private function extendPackage(string $sClassName, Closure $cSetter): void |
|
| 176 | - { |
|
| 177 | - // Initialize the package instance. |
|
| 178 | - $this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) { |
|
| 179 | - // Allow the setter to access protected attributes. |
|
| 180 | - call_user_func($cSetter->bindTo($xPackage, $xPackage)); |
|
| 181 | - return $xPackage; |
|
| 182 | - }); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 175 | +private function extendPackage(string $sClassName, Closure $cSetter): void |
|
| 176 | +{ |
|
| 177 | +// Initialize the package instance. |
|
| 178 | +$this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) { |
|
| 179 | +// Allow the setter to access protected attributes. |
|
| 180 | +call_user_func($cSetter->bindTo($xPackage, $xPackage)); |
|
| 181 | +return $xPackage; |
|
| 182 | +}); |
|
| 183 | +} |
|
| 184 | + |
|
| 185 | +/** |
|
| 186 | 186 | * Register a package |
| 187 | 187 | * |
| 188 | 188 | * @param class-string $sClassName The package class name |
@@ -191,45 +191,45 @@ discard block |
||
| 191 | 191 | * @return void |
| 192 | 192 | * @throws SetupException |
| 193 | 193 | */ |
| 194 | - public function registerPackage(string $sClassName, array $aUserOptions): void |
|
| 195 | - { |
|
| 196 | - // Register the user class, but only if the user didn't already. |
|
| 197 | - if(!$this->h($sClassName)) |
|
| 198 | - { |
|
| 199 | - $this->set($sClassName, fn() => $this->make($sClassName)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // Save the package config in the container. |
|
| 203 | - $sConfigKey = $this->getPackageConfigKey($sClassName); |
|
| 204 | - $this->set($sConfigKey, function($di) use($aUserOptions) { |
|
| 205 | - $xOptionsProvider = $aUserOptions['provider'] ?? null; |
|
| 206 | - // The user can provide a callable that returns the package options. |
|
| 207 | - if(is_callable($xOptionsProvider)) |
|
| 208 | - { |
|
| 209 | - $aUserOptions = $xOptionsProvider($aUserOptions); |
|
| 210 | - } |
|
| 211 | - return $di->g(ConfigManager::class)->newConfig($aUserOptions); |
|
| 212 | - }); |
|
| 213 | - |
|
| 214 | - // Initialize the package instance. |
|
| 215 | - $di = $this; |
|
| 216 | - $this->extendPackage($sClassName, function() use($di, $sConfigKey) { |
|
| 217 | - // $this here refers to the AbstractPackage instance. |
|
| 218 | - $this->xPkgConfig = $di->g($sConfigKey); |
|
| 219 | - $this->xRenderer = $di->g(ViewRenderer::class); |
|
| 220 | - $this->init(); |
|
| 221 | - }); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 194 | +public function registerPackage(string $sClassName, array $aUserOptions): void |
|
| 195 | +{ |
|
| 196 | +// Register the user class, but only if the user didn't already. |
|
| 197 | +if(!$this->h($sClassName)) |
|
| 198 | +{ |
|
| 199 | +$this->set($sClassName, fn() => $this->make($sClassName)); |
|
| 200 | +} |
|
| 201 | + |
|
| 202 | +// Save the package config in the container. |
|
| 203 | +$sConfigKey = $this->getPackageConfigKey($sClassName); |
|
| 204 | +$this->set($sConfigKey, function($di) use($aUserOptions) { |
|
| 205 | +$xOptionsProvider = $aUserOptions['provider'] ?? null; |
|
| 206 | +// The user can provide a callable that returns the package options. |
|
| 207 | +if(is_callable($xOptionsProvider)) |
|
| 208 | +{ |
|
| 209 | + $aUserOptions = $xOptionsProvider($aUserOptions); |
|
| 210 | +} |
|
| 211 | +return $di->g(ConfigManager::class)->newConfig($aUserOptions); |
|
| 212 | +}); |
|
| 213 | + |
|
| 214 | +// Initialize the package instance. |
|
| 215 | +$di = $this; |
|
| 216 | +$this->extendPackage($sClassName, function() use($di, $sConfigKey) { |
|
| 217 | +// $this here refers to the AbstractPackage instance. |
|
| 218 | +$this->xPkgConfig = $di->g($sConfigKey); |
|
| 219 | +$this->xRenderer = $di->g(ViewRenderer::class); |
|
| 220 | +$this->init(); |
|
| 221 | +}); |
|
| 222 | +} |
|
| 223 | + |
|
| 224 | +/** |
|
| 225 | 225 | * Get the config of a package |
| 226 | 226 | * |
| 227 | 227 | * @param class-string $sClassName The package class name |
| 228 | 228 | * |
| 229 | 229 | * @return Config |
| 230 | 230 | */ |
| 231 | - public function getPackageConfig(string $sClassName): Config |
|
| 232 | - { |
|
| 233 | - return $this->g($this->getPackageConfigKey($sClassName)); |
|
| 234 | - } |
|
| 231 | +public function getPackageConfig(string $sClassName): Config |
|
| 232 | +{ |
|
| 233 | +return $this->g($this->getPackageConfigKey($sClassName)); |
|
| 234 | +} |
|
| 235 | 235 | } |
@@ -9,35 +9,35 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class Store implements JsonSerializable, Stringable |
| 11 | 11 | { |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * The view renderer |
| 14 | 14 | * |
| 15 | 15 | * @var ViewInterface|null |
| 16 | 16 | */ |
| 17 | - protected $xRenderer = null; |
|
| 17 | +protected $xRenderer = null; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * The view namespace |
| 21 | 21 | * |
| 22 | 22 | * @var string |
| 23 | 23 | */ |
| 24 | - protected $sNamespace; |
|
| 24 | +protected $sNamespace; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The view name |
| 28 | 28 | * |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - protected $sViewName; |
|
| 31 | +protected $sViewName; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The view data |
| 35 | 35 | * |
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - protected $aViewData = []; |
|
| 38 | +protected $aViewData = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * Make a piece of data available for the rendered view |
| 42 | 42 | * |
| 43 | 43 | * @param string $sName The data name |
@@ -45,26 +45,26 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return Store |
| 47 | 47 | */ |
| 48 | - public function with(string $sName, $xValue): Store |
|
| 49 | - { |
|
| 50 | - $this->aViewData[$sName] = $xValue; |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 48 | +public function with(string $sName, $xValue): Store |
|
| 49 | +{ |
|
| 50 | +$this->aViewData[$sName] = $xValue; |
|
| 51 | +return $this; |
|
| 52 | +} |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Set the data to be rendered |
| 56 | 56 | * |
| 57 | 57 | * @param array $aViewData The view data |
| 58 | 58 | * |
| 59 | 59 | * @return Store |
| 60 | 60 | */ |
| 61 | - public function setData(array $aViewData): Store |
|
| 62 | - { |
|
| 63 | - $this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 61 | +public function setData(array $aViewData): Store |
|
| 62 | +{ |
|
| 63 | +$this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 64 | +return $this; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * Set the view to be rendered, with optional data |
| 69 | 69 | * |
| 70 | 70 | * @param ViewInterface $xRenderer The view renderer |
@@ -74,65 +74,65 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return Store |
| 76 | 76 | */ |
| 77 | - public function setView(ViewInterface $xRenderer, |
|
| 78 | - string $sNamespace, string $sViewName, array $aViewData = []): Store |
|
| 79 | - { |
|
| 80 | - $this->xRenderer = $xRenderer; |
|
| 81 | - $this->sNamespace = trim($sNamespace); |
|
| 82 | - $this->sViewName = trim($sViewName); |
|
| 83 | - $this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 84 | - return $this; |
|
| 85 | - } |
|
| 77 | +public function setView(ViewInterface $xRenderer, |
|
| 78 | +string $sNamespace, string $sViewName, array $aViewData = []): Store |
|
| 79 | +{ |
|
| 80 | +$this->xRenderer = $xRenderer; |
|
| 81 | +$this->sNamespace = trim($sNamespace); |
|
| 82 | +$this->sViewName = trim($sViewName); |
|
| 83 | +$this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 84 | +return $this; |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * Get the view namespace |
| 89 | 89 | * |
| 90 | 90 | * @return string The view namespace |
| 91 | 91 | */ |
| 92 | - public function getNamespace(): string |
|
| 93 | - { |
|
| 94 | - return $this->sNamespace; |
|
| 95 | - } |
|
| 92 | +public function getNamespace(): string |
|
| 93 | +{ |
|
| 94 | +return $this->sNamespace; |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * Get the view name |
| 99 | 99 | * |
| 100 | 100 | * @return string The view name |
| 101 | 101 | */ |
| 102 | - public function getViewName(): string |
|
| 103 | - { |
|
| 104 | - return $this->sViewName; |
|
| 105 | - } |
|
| 102 | +public function getViewName(): string |
|
| 103 | +{ |
|
| 104 | +return $this->sViewName; |
|
| 105 | +} |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * Get the view data |
| 109 | 109 | * |
| 110 | 110 | * @return array The view data |
| 111 | 111 | */ |
| 112 | - public function getViewData(): array |
|
| 113 | - { |
|
| 114 | - return $this->aViewData; |
|
| 115 | - } |
|
| 112 | +public function getViewData(): array |
|
| 113 | +{ |
|
| 114 | +return $this->aViewData; |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - /** |
|
| 117 | +/** |
|
| 118 | 118 | * Render a view using third party view system |
| 119 | 119 | * |
| 120 | 120 | * @return string The string representation of the view |
| 121 | 121 | */ |
| 122 | - public function __toString(): string |
|
| 123 | - { |
|
| 124 | - return !$this->xRenderer ? '' : $this->xRenderer->render($this); |
|
| 125 | - } |
|
| 122 | +public function __toString(): string |
|
| 123 | +{ |
|
| 124 | +return !$this->xRenderer ? '' : $this->xRenderer->render($this); |
|
| 125 | +} |
|
| 126 | 126 | |
| 127 | - /** |
|
| 127 | +/** |
|
| 128 | 128 | * Convert this object to string for json. |
| 129 | 129 | * |
| 130 | 130 | * This is a method of the JsonSerializable interface. |
| 131 | 131 | * |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function jsonSerialize(): string |
|
| 135 | - { |
|
| 136 | - return $this->__toString(); |
|
| 137 | - } |
|
| 134 | +public function jsonSerialize(): string |
|
| 135 | +{ |
|
| 136 | +return $this->__toString(); |
|
| 137 | +} |
|
| 138 | 138 | } |
@@ -13,58 +13,58 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class ViewRenderer |
| 15 | 15 | { |
| 16 | - /** |
|
| 16 | +/** |
|
| 17 | 17 | * @var Container |
| 18 | 18 | */ |
| 19 | - protected $di; |
|
| 19 | +protected $di; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * The view data store |
| 23 | 23 | * |
| 24 | 24 | * @var Store|null |
| 25 | 25 | */ |
| 26 | - protected $xStore = null; |
|
| 26 | +protected $xStore = null; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * The view data store |
| 30 | 30 | * |
| 31 | 31 | * @var Store |
| 32 | 32 | */ |
| 33 | - protected $xEmptyStore = null; |
|
| 33 | +protected $xEmptyStore = null; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * The view namespaces |
| 37 | 37 | * |
| 38 | 38 | * @var array |
| 39 | 39 | */ |
| 40 | - protected $aNamespaces = []; |
|
| 40 | +protected $aNamespaces = []; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * The default namespace |
| 44 | 44 | * |
| 45 | 45 | * @var string |
| 46 | 46 | */ |
| 47 | - protected $sDefaultNamespace = 'jaxon'; |
|
| 47 | +protected $sDefaultNamespace = 'jaxon'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * The view global data |
| 51 | 51 | * |
| 52 | 52 | * @var array |
| 53 | 53 | */ |
| 54 | - protected $aViewData = []; |
|
| 54 | +protected $aViewData = []; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * The class constructor |
| 58 | 58 | * |
| 59 | 59 | * @param Container $di |
| 60 | 60 | */ |
| 61 | - public function __construct(Container $di) |
|
| 62 | - { |
|
| 63 | - $this->di = $di; |
|
| 64 | - $this->xEmptyStore = new Store(); |
|
| 65 | - } |
|
| 61 | +public function __construct(Container $di) |
|
| 62 | +{ |
|
| 63 | +$this->di = $di; |
|
| 64 | +$this->xEmptyStore = new Store(); |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * Add a view namespace, and set the corresponding renderer. |
| 69 | 69 | * |
| 70 | 70 | * @param string $sNamespace The namespace name |
@@ -74,59 +74,59 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function addNamespace(string $sNamespace, string $sDirectory, |
|
| 78 | - string $sExtension, string $sRenderer): void |
|
| 79 | - { |
|
| 80 | - $aNamespace = [ |
|
| 81 | - 'directory' => $sDirectory, |
|
| 82 | - 'extension' => $sExtension, |
|
| 83 | - 'renderer' => $sRenderer, |
|
| 84 | - ]; |
|
| 85 | - $this->aNamespaces[$sNamespace] = $aNamespace; |
|
| 86 | - } |
|
| 77 | +public function addNamespace(string $sNamespace, string $sDirectory, |
|
| 78 | +string $sExtension, string $sRenderer): void |
|
| 79 | +{ |
|
| 80 | +$aNamespace = [ |
|
| 81 | +'directory' => $sDirectory, |
|
| 82 | +'extension' => $sExtension, |
|
| 83 | +'renderer' => $sRenderer, |
|
| 84 | +]; |
|
| 85 | +$this->aNamespaces[$sNamespace] = $aNamespace; |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * Set the view namespaces. |
| 90 | 90 | * |
| 91 | 91 | * @param Config $xAppConfig The config options provided in the library |
| 92 | 92 | * |
| 93 | 93 | * @return void |
| 94 | 94 | */ |
| 95 | - public function addNamespaces(Config $xAppConfig): void |
|
| 96 | - { |
|
| 97 | - if(empty($aNamespaces = $xAppConfig->getOptionNames('views'))) |
|
| 98 | - { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 95 | +public function addNamespaces(Config $xAppConfig): void |
|
| 96 | +{ |
|
| 97 | +if(empty($aNamespaces = $xAppConfig->getOptionNames('views'))) |
|
| 98 | +{ |
|
| 99 | +return; |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - $sPackage = $xAppConfig->getOption('package', ''); |
|
| 103 | - foreach($aNamespaces as $sNamespace => $sOption) |
|
| 104 | - { |
|
| 105 | - // Save the namespace |
|
| 106 | - $aNamespace = $xAppConfig->getOption($sOption); |
|
| 107 | - $aNamespace['package'] = $sPackage; |
|
| 108 | - if(!isset($aNamespace['renderer'])) |
|
| 109 | - { |
|
| 110 | - $aNamespace['renderer'] = 'jaxon'; // 'jaxon' is the default renderer. |
|
| 111 | - } |
|
| 112 | - $this->aNamespaces[$sNamespace] = $aNamespace; |
|
| 113 | - } |
|
| 114 | - } |
|
| 102 | +$sPackage = $xAppConfig->getOption('package', ''); |
|
| 103 | +foreach($aNamespaces as $sNamespace => $sOption) |
|
| 104 | +{ |
|
| 105 | +// Save the namespace |
|
| 106 | +$aNamespace = $xAppConfig->getOption($sOption); |
|
| 107 | +$aNamespace['package'] = $sPackage; |
|
| 108 | +if(!isset($aNamespace['renderer'])) |
|
| 109 | +{ |
|
| 110 | + $aNamespace['renderer'] = 'jaxon'; // 'jaxon' is the default renderer. |
|
| 111 | +} |
|
| 112 | +$this->aNamespaces[$sNamespace] = $aNamespace; |
|
| 113 | +} |
|
| 114 | +} |
|
| 115 | 115 | |
| 116 | - /** |
|
| 116 | +/** |
|
| 117 | 117 | * Get the view renderer |
| 118 | 118 | * |
| 119 | 119 | * @param string $sId The unique identifier of the view renderer |
| 120 | 120 | * |
| 121 | 121 | * @return ViewInterface |
| 122 | 122 | */ |
| 123 | - public function getRenderer(string $sId): ViewInterface |
|
| 124 | - { |
|
| 125 | - // Return the view renderer with the given id |
|
| 126 | - return $this->di->g("jaxon.app.view.$sId"); |
|
| 127 | - } |
|
| 123 | +public function getRenderer(string $sId): ViewInterface |
|
| 124 | +{ |
|
| 125 | +// Return the view renderer with the given id |
|
| 126 | +return $this->di->g("jaxon.app.view.$sId"); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - /** |
|
| 129 | +/** |
|
| 130 | 130 | * Add a view renderer with an id |
| 131 | 131 | * |
| 132 | 132 | * @param string $sId The unique identifier of the view renderer |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | - public function addRenderer(string $sId, Closure $xClosure): void |
|
| 138 | - { |
|
| 139 | - // Return the initialized view renderer |
|
| 140 | - $this->di->set("jaxon.app.view.$sId", function($di) use($sId, $xClosure) { |
|
| 141 | - // Get the defined renderer |
|
| 142 | - $xRenderer = $xClosure($di); |
|
| 143 | - // Init the renderer with the template namespaces |
|
| 144 | - $aNamespaces = array_filter($this->aNamespaces, function($aOptions) use($sId) { |
|
| 145 | - return $aOptions['renderer'] === $sId; |
|
| 146 | - }); |
|
| 147 | - foreach($aNamespaces as $sName => $aOptions) |
|
| 148 | - { |
|
| 149 | - $xRenderer->addNamespace($sName, $aOptions['directory'], $aOptions['extension']); |
|
| 150 | - } |
|
| 151 | - return $xRenderer; |
|
| 152 | - }); |
|
| 153 | - } |
|
| 137 | +public function addRenderer(string $sId, Closure $xClosure): void |
|
| 138 | +{ |
|
| 139 | +// Return the initialized view renderer |
|
| 140 | +$this->di->set("jaxon.app.view.$sId", function($di) use($sId, $xClosure) { |
|
| 141 | +// Get the defined renderer |
|
| 142 | +$xRenderer = $xClosure($di); |
|
| 143 | +// Init the renderer with the template namespaces |
|
| 144 | +$aNamespaces = array_filter($this->aNamespaces, function($aOptions) use($sId) { |
|
| 145 | + return $aOptions['renderer'] === $sId; |
|
| 146 | +}); |
|
| 147 | +foreach($aNamespaces as $sName => $aOptions) |
|
| 148 | +{ |
|
| 149 | + $xRenderer->addNamespace($sName, $aOptions['directory'], $aOptions['extension']); |
|
| 150 | +} |
|
| 151 | +return $xRenderer; |
|
| 152 | +}); |
|
| 153 | +} |
|
| 154 | 154 | |
| 155 | - /** |
|
| 155 | +/** |
|
| 156 | 156 | * Add a view renderer with an id |
| 157 | 157 | * |
| 158 | 158 | * @param string $sId The unique identifier of the view renderer |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return void |
| 163 | 163 | */ |
| 164 | - public function setDefaultRenderer(string $sId, string $sExtension, Closure $xClosure): void |
|
| 165 | - { |
|
| 166 | - $this->setDefaultNamespace($sId); |
|
| 167 | - $this->addNamespace($sId, '', $sExtension, $sId); |
|
| 168 | - $this->addRenderer($sId, $xClosure); |
|
| 169 | - } |
|
| 164 | +public function setDefaultRenderer(string $sId, string $sExtension, Closure $xClosure): void |
|
| 165 | +{ |
|
| 166 | +$this->setDefaultNamespace($sId); |
|
| 167 | +$this->addNamespace($sId, '', $sExtension, $sId); |
|
| 168 | +$this->addRenderer($sId, $xClosure); |
|
| 169 | +} |
|
| 170 | 170 | |
| 171 | - /** |
|
| 171 | +/** |
|
| 172 | 172 | * Get the view renderer for a given namespace |
| 173 | 173 | * |
| 174 | 174 | * @param string $sNamespace The namespace name |
| 175 | 175 | * |
| 176 | 176 | * @return ViewInterface|null |
| 177 | 177 | */ |
| 178 | - public function getNamespaceRenderer(string $sNamespace): ?ViewInterface |
|
| 179 | - { |
|
| 180 | - if(!isset($this->aNamespaces[$sNamespace])) |
|
| 181 | - { |
|
| 182 | - return null; |
|
| 183 | - } |
|
| 184 | - // Return the view renderer with the configured id |
|
| 185 | - return $this->getRenderer($this->aNamespaces[$sNamespace]['renderer']); |
|
| 186 | - } |
|
| 178 | +public function getNamespaceRenderer(string $sNamespace): ?ViewInterface |
|
| 179 | +{ |
|
| 180 | +if(!isset($this->aNamespaces[$sNamespace])) |
|
| 181 | +{ |
|
| 182 | +return null; |
|
| 183 | +} |
|
| 184 | +// Return the view renderer with the configured id |
|
| 185 | +return $this->getRenderer($this->aNamespaces[$sNamespace]['renderer']); |
|
| 186 | +} |
|
| 187 | 187 | |
| 188 | - /** |
|
| 188 | +/** |
|
| 189 | 189 | * Set the default namespace |
| 190 | 190 | * |
| 191 | 191 | * @param string $sDefaultNamespace |
| 192 | 192 | */ |
| 193 | - public function setDefaultNamespace(string $sDefaultNamespace): void |
|
| 194 | - { |
|
| 195 | - $this->sDefaultNamespace = $sDefaultNamespace; |
|
| 196 | - } |
|
| 193 | +public function setDefaultNamespace(string $sDefaultNamespace): void |
|
| 194 | +{ |
|
| 195 | +$this->sDefaultNamespace = $sDefaultNamespace; |
|
| 196 | +} |
|
| 197 | 197 | |
| 198 | - /** |
|
| 198 | +/** |
|
| 199 | 199 | * Get the current store or create a new store |
| 200 | 200 | * |
| 201 | 201 | * @return Store |
| 202 | 202 | */ |
| 203 | - protected function store(): Store |
|
| 204 | - { |
|
| 205 | - if(!$this->xStore) |
|
| 206 | - { |
|
| 207 | - $this->xStore = new Store(); |
|
| 208 | - } |
|
| 209 | - return $this->xStore; |
|
| 210 | - } |
|
| 203 | +protected function store(): Store |
|
| 204 | +{ |
|
| 205 | +if(!$this->xStore) |
|
| 206 | +{ |
|
| 207 | +$this->xStore = new Store(); |
|
| 208 | +} |
|
| 209 | +return $this->xStore; |
|
| 210 | +} |
|
| 211 | 211 | |
| 212 | - /** |
|
| 212 | +/** |
|
| 213 | 213 | * Make a piece of data available for the rendered view |
| 214 | 214 | * |
| 215 | 215 | * @param string $sName The data name |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return ViewRenderer |
| 219 | 219 | */ |
| 220 | - public function set(string $sName, $xValue): ViewRenderer |
|
| 221 | - { |
|
| 222 | - $this->store()->with($sName, $xValue); |
|
| 223 | - return $this; |
|
| 224 | - } |
|
| 220 | +public function set(string $sName, $xValue): ViewRenderer |
|
| 221 | +{ |
|
| 222 | +$this->store()->with($sName, $xValue); |
|
| 223 | +return $this; |
|
| 224 | +} |
|
| 225 | 225 | |
| 226 | - /** |
|
| 226 | +/** |
|
| 227 | 227 | * Make a piece of data available for all views |
| 228 | 228 | * |
| 229 | 229 | * @param string $sName The data name |
@@ -231,29 +231,29 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return ViewRenderer |
| 233 | 233 | */ |
| 234 | - public function share(string $sName, $xValue): ViewRenderer |
|
| 235 | - { |
|
| 236 | - $this->aViewData[$sName] = $xValue; |
|
| 237 | - return $this; |
|
| 238 | - } |
|
| 234 | +public function share(string $sName, $xValue): ViewRenderer |
|
| 235 | +{ |
|
| 236 | +$this->aViewData[$sName] = $xValue; |
|
| 237 | +return $this; |
|
| 238 | +} |
|
| 239 | 239 | |
| 240 | - /** |
|
| 240 | +/** |
|
| 241 | 241 | * Make an array of data available for all views |
| 242 | 242 | * |
| 243 | 243 | * @param array $aValues The data values |
| 244 | 244 | * |
| 245 | 245 | * @return ViewRenderer |
| 246 | 246 | */ |
| 247 | - public function shareValues(array $aValues): ViewRenderer |
|
| 248 | - { |
|
| 249 | - foreach($aValues as $sName => $xValue) |
|
| 250 | - { |
|
| 251 | - $this->share($sName, $xValue); |
|
| 252 | - } |
|
| 253 | - return $this; |
|
| 254 | - } |
|
| 247 | +public function shareValues(array $aValues): ViewRenderer |
|
| 248 | +{ |
|
| 249 | +foreach($aValues as $sName => $xValue) |
|
| 250 | +{ |
|
| 251 | +$this->share($sName, $xValue); |
|
| 252 | +} |
|
| 253 | +return $this; |
|
| 254 | +} |
|
| 255 | 255 | |
| 256 | - /** |
|
| 256 | +/** |
|
| 257 | 257 | * Render a view using a store |
| 258 | 258 | * |
| 259 | 259 | * The store returned by this function will later be used with the make() method to render the view. |
@@ -263,32 +263,32 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @return Store A store populated with the view data |
| 265 | 265 | */ |
| 266 | - public function render(string $sViewName, array $aViewData = []): Store |
|
| 267 | - { |
|
| 268 | - $xStore = $this->store(); |
|
| 269 | - // Get the default view namespace |
|
| 270 | - $sNamespace = $this->sDefaultNamespace; |
|
| 271 | - // Get the namespace from the view name |
|
| 272 | - $nSeparatorPosition = strrpos($sViewName, '::'); |
|
| 273 | - if($nSeparatorPosition !== false) |
|
| 274 | - { |
|
| 275 | - $sNamespace = substr($sViewName, 0, $nSeparatorPosition); |
|
| 276 | - $sViewName = substr($sViewName, $nSeparatorPosition + 2); |
|
| 277 | - } |
|
| 266 | +public function render(string $sViewName, array $aViewData = []): Store |
|
| 267 | +{ |
|
| 268 | +$xStore = $this->store(); |
|
| 269 | +// Get the default view namespace |
|
| 270 | +$sNamespace = $this->sDefaultNamespace; |
|
| 271 | +// Get the namespace from the view name |
|
| 272 | +$nSeparatorPosition = strrpos($sViewName, '::'); |
|
| 273 | +if($nSeparatorPosition !== false) |
|
| 274 | +{ |
|
| 275 | +$sNamespace = substr($sViewName, 0, $nSeparatorPosition); |
|
| 276 | +$sViewName = substr($sViewName, $nSeparatorPosition + 2); |
|
| 277 | +} |
|
| 278 | 278 | |
| 279 | - $xRenderer = $this->getNamespaceRenderer($sNamespace); |
|
| 280 | - if(!$xRenderer) |
|
| 281 | - { |
|
| 282 | - // Cannot render a view if there's no renderer corresponding to the namespace. |
|
| 283 | - return $this->xEmptyStore; |
|
| 284 | - } |
|
| 279 | +$xRenderer = $this->getNamespaceRenderer($sNamespace); |
|
| 280 | +if(!$xRenderer) |
|
| 281 | +{ |
|
| 282 | +// Cannot render a view if there's no renderer corresponding to the namespace. |
|
| 283 | +return $this->xEmptyStore; |
|
| 284 | +} |
|
| 285 | 285 | |
| 286 | - $xStore->setData(array_merge($this->aViewData, $aViewData)) |
|
| 287 | - ->setView($xRenderer, $sNamespace, $sViewName); |
|
| 286 | +$xStore->setData(array_merge($this->aViewData, $aViewData)) |
|
| 287 | +->setView($xRenderer, $sNamespace, $sViewName); |
|
| 288 | 288 | |
| 289 | - // Set the store to null so a new store will be created for the next view. |
|
| 290 | - $this->xStore = null; |
|
| 291 | - // Return the store |
|
| 292 | - return $xStore; |
|
| 293 | - } |
|
| 289 | +// Set the store to null so a new store will be created for the next view. |
|
| 290 | +$this->xStore = null; |
|
| 291 | +// Return the store |
|
| 292 | +return $xStore; |
|
| 293 | +} |
|
| 294 | 294 | } |
@@ -45,49 +45,49 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | class PluginManager |
| 47 | 47 | { |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Request plugins, indexed by name |
| 50 | 50 | * |
| 51 | 51 | * @var array<string> |
| 52 | 52 | */ |
| 53 | - private $aRegistryPlugins = []; |
|
| 53 | +private $aRegistryPlugins = []; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Request handlers, indexed by name |
| 57 | 57 | * |
| 58 | 58 | * @var array<string> |
| 59 | 59 | */ |
| 60 | - private $aRequestHandlers = []; |
|
| 60 | +private $aRequestHandlers = []; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * Response plugins, indexed by name |
| 64 | 64 | * |
| 65 | 65 | * @var array<string> |
| 66 | 66 | */ |
| 67 | - private $aResponsePlugins = []; |
|
| 67 | +private $aResponsePlugins = []; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * The constructor |
| 71 | 71 | * |
| 72 | 72 | * @param Container $di |
| 73 | 73 | * @param CodeGenerator $xCodeGenerator |
| 74 | 74 | * @param Translator $xTranslator |
| 75 | 75 | */ |
| 76 | - public function __construct(private Container $di, |
|
| 77 | - private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 78 | - {} |
|
| 76 | +public function __construct(private Container $di, |
|
| 77 | +private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 78 | +{} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * Get the request plugins |
| 82 | 82 | * |
| 83 | 83 | * @return array<class-string> |
| 84 | 84 | */ |
| 85 | - public function getRequestHandlers(): array |
|
| 86 | - { |
|
| 87 | - return $this->aRequestHandlers; |
|
| 88 | - } |
|
| 85 | +public function getRequestHandlers(): array |
|
| 86 | +{ |
|
| 87 | +return $this->aRequestHandlers; |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register a plugin |
| 92 | 92 | * |
| 93 | 93 | * @param class-string $sClassName The plugin class |
@@ -97,40 +97,40 @@ discard block |
||
| 97 | 97 | * @return int |
| 98 | 98 | * @throws SetupException |
| 99 | 99 | */ |
| 100 | - private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 101 | - { |
|
| 102 | - // Any plugin must implement the PluginInterface interface. |
|
| 103 | - if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 104 | - { |
|
| 105 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 106 | - 'name' => $sClassName, |
|
| 107 | - ]); |
|
| 108 | - throw new SetupException($sMessage); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Response plugin. |
|
| 112 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 113 | - { |
|
| 114 | - $this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Request plugin. |
|
| 119 | - $nCount = 0; |
|
| 120 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 121 | - { |
|
| 122 | - $this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 123 | - $nCount++; |
|
| 124 | - } |
|
| 125 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 126 | - { |
|
| 127 | - $this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 128 | - $nCount++; |
|
| 129 | - } |
|
| 130 | - return $nCount; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 100 | +private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 101 | +{ |
|
| 102 | +// Any plugin must implement the PluginInterface interface. |
|
| 103 | +if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 104 | +{ |
|
| 105 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 106 | + 'name' => $sClassName, |
|
| 107 | +]); |
|
| 108 | +throw new SetupException($sMessage); |
|
| 109 | +} |
|
| 110 | + |
|
| 111 | +// Response plugin. |
|
| 112 | +if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 113 | +{ |
|
| 114 | +$this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 115 | +return 1; |
|
| 116 | +} |
|
| 117 | + |
|
| 118 | +// Request plugin. |
|
| 119 | +$nCount = 0; |
|
| 120 | +if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 121 | +{ |
|
| 122 | +$this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 123 | +$nCount++; |
|
| 124 | +} |
|
| 125 | +if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 126 | +{ |
|
| 127 | +$this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 128 | +$nCount++; |
|
| 129 | +} |
|
| 130 | +return $nCount; |
|
| 131 | +} |
|
| 132 | + |
|
| 133 | +/** |
|
| 134 | 134 | * Register a plugin |
| 135 | 135 | * |
| 136 | 136 | * Below is a table for priorities and their description: |
@@ -145,34 +145,34 @@ discard block |
||
| 145 | 145 | * @return void |
| 146 | 146 | * @throws SetupException |
| 147 | 147 | */ |
| 148 | - public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 149 | - { |
|
| 150 | - $aInterfaces = class_implements($sClassName); |
|
| 151 | - $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 152 | - |
|
| 153 | - // Any plugin can implement the CodeGeneratorInterface interface. |
|
| 154 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 155 | - { |
|
| 156 | - $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 157 | - $nCount++; |
|
| 158 | - } |
|
| 159 | - // The class is not a valid plugin. |
|
| 160 | - if($nCount === 0) |
|
| 161 | - { |
|
| 162 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 163 | - 'name' => $sClassName, |
|
| 164 | - ]); |
|
| 165 | - throw new SetupException($sMessage); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Register the plugin in the DI container, if necessary |
|
| 169 | - if(!$this->di->has($sClassName)) |
|
| 170 | - { |
|
| 171 | - $this->di->auto($sClassName); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 148 | +public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 149 | +{ |
|
| 150 | +$aInterfaces = class_implements($sClassName); |
|
| 151 | +$nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 152 | + |
|
| 153 | +// Any plugin can implement the CodeGeneratorInterface interface. |
|
| 154 | +if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 155 | +{ |
|
| 156 | +$this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 157 | +$nCount++; |
|
| 158 | +} |
|
| 159 | +// The class is not a valid plugin. |
|
| 160 | +if($nCount === 0) |
|
| 161 | +{ |
|
| 162 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 163 | + 'name' => $sClassName, |
|
| 164 | +]); |
|
| 165 | +throw new SetupException($sMessage); |
|
| 166 | +} |
|
| 167 | + |
|
| 168 | +// Register the plugin in the DI container, if necessary |
|
| 169 | +if(!$this->di->has($sClassName)) |
|
| 170 | +{ |
|
| 171 | +$this->di->auto($sClassName); |
|
| 172 | +} |
|
| 173 | +} |
|
| 174 | + |
|
| 175 | +/** |
|
| 176 | 176 | * Find the specified response plugin by name or class name |
| 177 | 177 | * |
| 178 | 178 | * @template R of ResponsePluginInterface |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return ($sName is class-string ? R|null : ResponsePluginInterface|null) |
| 182 | 182 | */ |
| 183 | - public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 184 | - { |
|
| 185 | - return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 186 | - (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 187 | - $this->di->g($this->aResponsePlugins[$sName])); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 183 | +public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 184 | +{ |
|
| 185 | +return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 186 | +(!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 187 | +$this->di->g($this->aResponsePlugins[$sName])); |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +/** |
|
| 191 | 191 | * Register a callable function or class |
| 192 | 192 | * |
| 193 | 193 | * Call the request plugin with the $sType defined as name. |
@@ -199,46 +199,46 @@ discard block |
||
| 199 | 199 | * @return void |
| 200 | 200 | * @throws SetupException |
| 201 | 201 | */ |
| 202 | - public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 203 | - { |
|
| 204 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
| 205 | - ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 206 | - { |
|
| 207 | - $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 208 | - return; |
|
| 209 | - } |
|
| 210 | - throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 211 | - ['name' => $sType, 'callable' => $sCallable])); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 202 | +public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 203 | +{ |
|
| 204 | +if(isset($this->aRegistryPlugins[$sType]) && |
|
| 205 | +($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 206 | +{ |
|
| 207 | +$xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 208 | +return; |
|
| 209 | +} |
|
| 210 | +throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 211 | +['name' => $sType, 'callable' => $sCallable])); |
|
| 212 | +} |
|
| 213 | + |
|
| 214 | +/** |
|
| 215 | 215 | * Register the Jaxon request plugins |
| 216 | 216 | * |
| 217 | 217 | * @return void |
| 218 | 218 | * @throws SetupException |
| 219 | 219 | */ |
| 220 | - public function registerPlugins(): void |
|
| 221 | - { |
|
| 222 | - // Request plugins |
|
| 223 | - $this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 224 | - $this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 225 | - $this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 226 | - |
|
| 227 | - // Response plugins |
|
| 228 | - $this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 229 | - $this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 230 | - $this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 231 | - $this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 232 | - $this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 220 | +public function registerPlugins(): void |
|
| 221 | +{ |
|
| 222 | +// Request plugins |
|
| 223 | +$this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 224 | +$this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 225 | +$this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 226 | + |
|
| 227 | +// Response plugins |
|
| 228 | +$this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 229 | +$this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 230 | +$this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 231 | +$this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 232 | +$this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 233 | +} |
|
| 234 | + |
|
| 235 | +/** |
|
| 236 | 236 | * Get the parameter reader |
| 237 | 237 | * |
| 238 | 238 | * @return ParameterReader |
| 239 | 239 | */ |
| 240 | - public function getParameterReader(): ParameterReader |
|
| 241 | - { |
|
| 242 | - return $this->di->g(ParameterReader::class); |
|
| 243 | - } |
|
| 240 | +public function getParameterReader(): ParameterReader |
|
| 241 | +{ |
|
| 242 | +return $this->di->g(ParameterReader::class); |
|
| 243 | +} |
|
| 244 | 244 | } |
@@ -19,46 +19,46 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | abstract class AbstractPackage extends AbstractCodeGenerator |
| 21 | 21 | { |
| 22 | - /** |
|
| 22 | +/** |
|
| 23 | 23 | * The configuration options of the package |
| 24 | 24 | * |
| 25 | 25 | * @var Config |
| 26 | 26 | */ |
| 27 | - protected $xPkgConfig; |
|
| 27 | +protected $xPkgConfig; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The view renderer |
| 31 | 31 | * |
| 32 | 32 | * @var ViewRenderer |
| 33 | 33 | */ |
| 34 | - protected $xRenderer; |
|
| 34 | +protected $xRenderer; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the path to the config file, or the config options in an array. |
| 38 | 38 | * |
| 39 | 39 | * @return string|array |
| 40 | 40 | */ |
| 41 | - abstract public static function config(): string|array; |
|
| 41 | +abstract public static function config(): string|array; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * Get the package config object |
| 45 | 45 | * |
| 46 | 46 | * @return Config |
| 47 | 47 | */ |
| 48 | - final public function getConfig(): Config |
|
| 49 | - { |
|
| 50 | - return $this->xPkgConfig; |
|
| 51 | - } |
|
| 48 | +final public function getConfig(): Config |
|
| 49 | +{ |
|
| 50 | +return $this->xPkgConfig; |
|
| 51 | +} |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * This method is automatically called after the package instance is created and configured. |
| 55 | 55 | * |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - protected function init(): void |
|
| 59 | - {} |
|
| 58 | +protected function init(): void |
|
| 59 | +{} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * Get the value of a given package option |
| 63 | 63 | * |
| 64 | 64 | * @param string $sOption The option name |
@@ -66,59 +66,59 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return mixed |
| 68 | 68 | */ |
| 69 | - final public function getOption(string $sOption, $xDefault = null): mixed |
|
| 70 | - { |
|
| 71 | - return $this->xPkgConfig->getOption($sOption, $xDefault); |
|
| 72 | - } |
|
| 69 | +final public function getOption(string $sOption, $xDefault = null): mixed |
|
| 70 | +{ |
|
| 71 | +return $this->xPkgConfig->getOption($sOption, $xDefault); |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * Get the view renderer |
| 76 | 76 | * |
| 77 | 77 | * @return ViewRenderer |
| 78 | 78 | */ |
| 79 | - final public function view(): ViewRenderer |
|
| 80 | - { |
|
| 81 | - return $this->xRenderer; |
|
| 82 | - } |
|
| 79 | +final public function view(): ViewRenderer |
|
| 80 | +{ |
|
| 81 | +return $this->xRenderer; |
|
| 82 | +} |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * @inheritDoc |
| 86 | 86 | */ |
| 87 | - final public function getHash(): string |
|
| 88 | - { |
|
| 89 | - // Packages do not generate hash on their own. So we make this method final. |
|
| 90 | - return ''; |
|
| 91 | - } |
|
| 87 | +final public function getHash(): string |
|
| 88 | +{ |
|
| 89 | +// Packages do not generate hash on their own. So we make this method final. |
|
| 90 | +return ''; |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Get the HTML code of the package home page |
| 95 | 95 | * |
| 96 | 96 | * @return string|Stringable |
| 97 | 97 | */ |
| 98 | - public function getHtml(): string|Stringable |
|
| 99 | - { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 98 | +public function getHtml(): string|Stringable |
|
| 99 | +{ |
|
| 100 | +return ''; |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Get the HTML code of the package home page |
| 105 | 105 | * |
| 106 | 106 | * This method is an alias for getHtml(). |
| 107 | 107 | * |
| 108 | 108 | * @return string|Stringable |
| 109 | 109 | */ |
| 110 | - public function html(): string|Stringable |
|
| 111 | - { |
|
| 112 | - return $this->getHtml(); |
|
| 113 | - } |
|
| 110 | +public function html(): string|Stringable |
|
| 111 | +{ |
|
| 112 | +return $this->getHtml(); |
|
| 113 | +} |
|
| 114 | 114 | |
| 115 | - /** |
|
| 115 | +/** |
|
| 116 | 116 | * Get the Js code of the ready() callback |
| 117 | 117 | * |
| 118 | 118 | * @return string|Stringable |
| 119 | 119 | */ |
| 120 | - public function getReadyScript(): string|Stringable |
|
| 121 | - { |
|
| 122 | - return ''; |
|
| 123 | - } |
|
| 120 | +public function getReadyScript(): string|Stringable |
|
| 121 | +{ |
|
| 122 | +return ''; |
|
| 123 | +} |
|
| 124 | 124 | } |
@@ -38,81 +38,81 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | class ResponseManager |
| 40 | 40 | { |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * The current response object that will be sent back to the browser |
| 43 | 43 | * once the request processing phase is complete |
| 44 | 44 | * |
| 45 | 45 | * @var AjaxResponse|null |
| 46 | 46 | */ |
| 47 | - private $xResponse = null; |
|
| 47 | +private $xResponse = null; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * The error message |
| 51 | 51 | * |
| 52 | 52 | * @var string |
| 53 | 53 | */ |
| 54 | - private $sErrorMessage = ''; |
|
| 54 | +private $sErrorMessage = ''; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * The debug messages |
| 58 | 58 | * |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - private $aDebugMessages = []; |
|
| 61 | +private $aDebugMessages = []; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * The commands that will be sent to the browser in the response |
| 65 | 65 | * |
| 66 | 66 | * @var array |
| 67 | 67 | */ |
| 68 | - protected $aCommands = []; |
|
| 68 | +protected $aCommands = []; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 70 | +/** |
|
| 71 | 71 | * If the commands beeing added are to be confirmed |
| 72 | 72 | * |
| 73 | 73 | * @var bool |
| 74 | 74 | */ |
| 75 | - private $bOnConfirm = false; |
|
| 75 | +private $bOnConfirm = false; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * The commands that will be sent to the browser in the response |
| 79 | 79 | * |
| 80 | 80 | * @var array |
| 81 | 81 | */ |
| 82 | - private $aConfirmCommands = []; |
|
| 82 | +private $aConfirmCommands = []; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * @param Container $di |
| 86 | 86 | * @param Translator $xTranslator |
| 87 | 87 | * @param string $sCharacterEncoding |
| 88 | 88 | */ |
| 89 | - public function __construct(private Container $di, |
|
| 90 | - private Translator $xTranslator, private string $sCharacterEncoding) |
|
| 91 | - {} |
|
| 89 | +public function __construct(private Container $di, |
|
| 90 | +private Translator $xTranslator, private string $sCharacterEncoding) |
|
| 91 | +{} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Get the configured character encoding |
| 95 | 95 | * |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getCharacterEncoding(): string |
|
| 99 | - { |
|
| 100 | - return $this->sCharacterEncoding; |
|
| 101 | - } |
|
| 98 | +public function getCharacterEncoding(): string |
|
| 99 | +{ |
|
| 100 | +return $this->sCharacterEncoding; |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Convert to string |
| 105 | 105 | * |
| 106 | 106 | * @param mixed $xData |
| 107 | 107 | * |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public function str($xData): string |
|
| 111 | - { |
|
| 112 | - return trim((string)$xData, " \t\n"); |
|
| 113 | - } |
|
| 110 | +public function str($xData): string |
|
| 111 | +{ |
|
| 112 | +return trim((string)$xData, " \t\n"); |
|
| 113 | +} |
|
| 114 | 114 | |
| 115 | - /** |
|
| 115 | +/** |
|
| 116 | 116 | * Get a translated string |
| 117 | 117 | * |
| 118 | 118 | * @param string $sText The key of the translated string |
@@ -120,81 +120,81 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return string |
| 122 | 122 | */ |
| 123 | - public function trans(string $sText, array $aPlaceHolders = []): string |
|
| 124 | - { |
|
| 125 | - return $this->xTranslator->trans($sText, $aPlaceHolders); |
|
| 126 | - } |
|
| 123 | +public function trans(string $sText, array $aPlaceHolders = []): string |
|
| 124 | +{ |
|
| 125 | +return $this->xTranslator->trans($sText, $aPlaceHolders); |
|
| 126 | +} |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Set the error message |
| 130 | 130 | * |
| 131 | 131 | * @param string $sErrorMessage |
| 132 | 132 | * |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - public function setErrorMessage(string $sErrorMessage): void |
|
| 136 | - { |
|
| 137 | - $this->sErrorMessage = $sErrorMessage; |
|
| 138 | - } |
|
| 135 | +public function setErrorMessage(string $sErrorMessage): void |
|
| 136 | +{ |
|
| 137 | +$this->sErrorMessage = $sErrorMessage; |
|
| 138 | +} |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | +/** |
|
| 141 | 141 | * Get the error message |
| 142 | 142 | * |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function getErrorMessage(): string |
|
| 146 | - { |
|
| 147 | - return $this->sErrorMessage; |
|
| 148 | - } |
|
| 145 | +public function getErrorMessage(): string |
|
| 146 | +{ |
|
| 147 | +return $this->sErrorMessage; |
|
| 148 | +} |
|
| 149 | 149 | |
| 150 | - /** |
|
| 150 | +/** |
|
| 151 | 151 | * Get the commands in the response |
| 152 | 152 | * |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - public function getCommands(): array |
|
| 156 | - { |
|
| 157 | - return $this->aCommands; |
|
| 158 | - } |
|
| 155 | +public function getCommands(): array |
|
| 156 | +{ |
|
| 157 | +return $this->aCommands; |
|
| 158 | +} |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * Get the number of commands in the response |
| 162 | 162 | * |
| 163 | 163 | * @return int |
| 164 | 164 | */ |
| 165 | - public function getCommandCount(): int |
|
| 166 | - { |
|
| 167 | - return count($this->aCommands); |
|
| 168 | - } |
|
| 165 | +public function getCommandCount(): int |
|
| 166 | +{ |
|
| 167 | +return count($this->aCommands); |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * Clear all the commands already added to the response |
| 172 | 172 | * |
| 173 | 173 | * @return void |
| 174 | 174 | */ |
| 175 | - public function clearCommands(): void |
|
| 176 | - { |
|
| 177 | - $this->aCommands = []; |
|
| 178 | - } |
|
| 175 | +public function clearCommands(): void |
|
| 176 | +{ |
|
| 177 | +$this->aCommands = []; |
|
| 178 | +} |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | +/** |
|
| 181 | 181 | * @param array|JsonSerializable $aArgs The command arguments |
| 182 | 182 | * @param bool $bRemoveEmpty If true, remove empty arguments |
| 183 | 183 | * |
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array |
|
| 187 | - { |
|
| 188 | - if(!$bRemoveEmpty) |
|
| 189 | - { |
|
| 190 | - return $aArgs; |
|
| 191 | - } |
|
| 192 | - return array_filter($aArgs, function($xArg) { |
|
| 193 | - return !empty($xArg); |
|
| 194 | - }); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 186 | +private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array |
|
| 187 | +{ |
|
| 188 | +if(!$bRemoveEmpty) |
|
| 189 | +{ |
|
| 190 | +return $aArgs; |
|
| 191 | +} |
|
| 192 | +return array_filter($aArgs, function($xArg) { |
|
| 193 | +return !empty($xArg); |
|
| 194 | +}); |
|
| 195 | +} |
|
| 196 | + |
|
| 197 | +/** |
|
| 198 | 198 | * Add a response command to the array of commands |
| 199 | 199 | * |
| 200 | 200 | * @param string $sName The command name |
@@ -203,25 +203,25 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @return Command |
| 205 | 205 | */ |
| 206 | - public function addCommand(string $sName, array|JsonSerializable $aArgs, |
|
| 207 | - bool $bRemoveEmpty = false): Command |
|
| 208 | - { |
|
| 209 | - $xCommand = new Command([ |
|
| 210 | - 'name' => $this->str($sName), |
|
| 211 | - 'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty), |
|
| 212 | - ]); |
|
| 213 | - if($this->bOnConfirm) |
|
| 214 | - { |
|
| 215 | - $this->aConfirmCommands[] = $xCommand; |
|
| 216 | - } |
|
| 217 | - else |
|
| 218 | - { |
|
| 219 | - $this->aCommands[] = $xCommand; |
|
| 220 | - } |
|
| 221 | - return $xCommand; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 206 | +public function addCommand(string $sName, array|JsonSerializable $aArgs, |
|
| 207 | +bool $bRemoveEmpty = false): Command |
|
| 208 | +{ |
|
| 209 | +$xCommand = new Command([ |
|
| 210 | +'name' => $this->str($sName), |
|
| 211 | +'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty), |
|
| 212 | +]); |
|
| 213 | +if($this->bOnConfirm) |
|
| 214 | +{ |
|
| 215 | +$this->aConfirmCommands[] = $xCommand; |
|
| 216 | +} |
|
| 217 | +else |
|
| 218 | +{ |
|
| 219 | +$this->aCommands[] = $xCommand; |
|
| 220 | +} |
|
| 221 | +return $xCommand; |
|
| 222 | +} |
|
| 223 | + |
|
| 224 | +/** |
|
| 225 | 225 | * Response command that prompts user with [ok] [cancel] style message box |
| 226 | 226 | * |
| 227 | 227 | * The provided closure will be called with a response object as unique parameter. |
@@ -236,29 +236,29 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return self |
| 238 | 238 | */ |
| 239 | - public function addConfirmCommand(string $sName, Closure $fConfirm, |
|
| 240 | - string $sQuestion, array $aArgs = []): self |
|
| 241 | - { |
|
| 242 | - if($this->bOnConfirm) |
|
| 243 | - { |
|
| 244 | - throw new AppException($this->xTranslator->trans('errors.app.confirm.nested')); |
|
| 245 | - } |
|
| 246 | - $this->bOnConfirm = true; |
|
| 247 | - $fConfirm(); |
|
| 248 | - $this->bOnConfirm = false; |
|
| 249 | - if(($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 250 | - { |
|
| 251 | - $aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs); |
|
| 252 | - $aCommand['count'] = $nCommandCount; |
|
| 253 | - // The confirm command must be inserted before the commands to be confirmed. |
|
| 254 | - $this->addCommand($sName, $aCommand); |
|
| 255 | - $this->aCommands = array_merge($this->aCommands, $this->aConfirmCommands); |
|
| 256 | - $this->aConfirmCommands = []; |
|
| 257 | - } |
|
| 258 | - return $this; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 239 | +public function addConfirmCommand(string $sName, Closure $fConfirm, |
|
| 240 | +string $sQuestion, array $aArgs = []): self |
|
| 241 | +{ |
|
| 242 | +if($this->bOnConfirm) |
|
| 243 | +{ |
|
| 244 | +throw new AppException($this->xTranslator->trans('errors.app.confirm.nested')); |
|
| 245 | +} |
|
| 246 | +$this->bOnConfirm = true; |
|
| 247 | +$fConfirm(); |
|
| 248 | +$this->bOnConfirm = false; |
|
| 249 | +if(($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 250 | +{ |
|
| 251 | +$aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs); |
|
| 252 | +$aCommand['count'] = $nCommandCount; |
|
| 253 | +// The confirm command must be inserted before the commands to be confirmed. |
|
| 254 | +$this->addCommand($sName, $aCommand); |
|
| 255 | +$this->aCommands = array_merge($this->aCommands, $this->aConfirmCommands); |
|
| 256 | +$this->aConfirmCommands = []; |
|
| 257 | +} |
|
| 258 | +return $this; |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +/** |
|
| 262 | 262 | * Add a command to display an alert message to the user |
| 263 | 263 | * |
| 264 | 264 | * @param string $sName The command name |
@@ -269,56 +269,56 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return self |
| 271 | 271 | */ |
| 272 | - public function addAlertCommand(string $sName, string $sMessage, array $aArgs = []): self |
|
| 273 | - { |
|
| 274 | - $aCommand = $this->di->getDialogCommand()->info($this->str($sMessage), $aArgs); |
|
| 275 | - $this->addCommand($sName, $aCommand); |
|
| 276 | - return $this; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 272 | +public function addAlertCommand(string $sName, string $sMessage, array $aArgs = []): self |
|
| 273 | +{ |
|
| 274 | +$aCommand = $this->di->getDialogCommand()->info($this->str($sMessage), $aArgs); |
|
| 275 | +$this->addCommand($sName, $aCommand); |
|
| 276 | +return $this; |
|
| 277 | +} |
|
| 278 | + |
|
| 279 | +/** |
|
| 280 | 280 | * Get the response to the Jaxon request |
| 281 | 281 | * |
| 282 | 282 | * @return Response |
| 283 | 283 | */ |
| 284 | - public function getResponse(): Response |
|
| 285 | - { |
|
| 286 | - return $this->di->getResponse(); |
|
| 287 | - } |
|
| 284 | +public function getResponse(): Response |
|
| 285 | +{ |
|
| 286 | +return $this->di->getResponse(); |
|
| 287 | +} |
|
| 288 | 288 | |
| 289 | - /** |
|
| 289 | +/** |
|
| 290 | 290 | * Create a new Jaxon response |
| 291 | 291 | * |
| 292 | 292 | * @return Response |
| 293 | 293 | */ |
| 294 | - public function newResponse(): Response |
|
| 295 | - { |
|
| 296 | - return $this->xResponse = $this->di->newResponse(); |
|
| 297 | - } |
|
| 294 | +public function newResponse(): Response |
|
| 295 | +{ |
|
| 296 | +return $this->xResponse = $this->di->newResponse(); |
|
| 297 | +} |
|
| 298 | 298 | |
| 299 | - /** |
|
| 299 | +/** |
|
| 300 | 300 | * Get the Jaxon ajax response returned |
| 301 | 301 | * |
| 302 | 302 | * @return AjaxResponse |
| 303 | 303 | */ |
| 304 | - public function ajaxResponse(): AjaxResponse |
|
| 305 | - { |
|
| 306 | - return $this->xResponse ?: $this->di->getResponse(); |
|
| 307 | - } |
|
| 304 | +public function ajaxResponse(): AjaxResponse |
|
| 305 | +{ |
|
| 306 | +return $this->xResponse ?: $this->di->getResponse(); |
|
| 307 | +} |
|
| 308 | 308 | |
| 309 | - /** |
|
| 309 | +/** |
|
| 310 | 310 | * Create a new reponse for a Jaxon component |
| 311 | 311 | * |
| 312 | 312 | * @param JxnCall $xJxnCall |
| 313 | 313 | * |
| 314 | 314 | * @return NodeResponse |
| 315 | 315 | */ |
| 316 | - public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 317 | - { |
|
| 318 | - return $this->di->newNodeResponse($xJxnCall); |
|
| 319 | - } |
|
| 316 | +public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 317 | +{ |
|
| 318 | +return $this->di->newNodeResponse($xJxnCall); |
|
| 319 | +} |
|
| 320 | 320 | |
| 321 | - /** |
|
| 321 | +/** |
|
| 322 | 322 | * Appends a debug message on the end of the debug message queue |
| 323 | 323 | * |
| 324 | 324 | * Debug messages will be sent to the client with the normal response |
@@ -328,66 +328,66 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return void |
| 330 | 330 | */ |
| 331 | - public function debug(string $sMessage): void |
|
| 332 | - { |
|
| 333 | - $this->aDebugMessages[] = $sMessage; |
|
| 334 | - } |
|
| 331 | +public function debug(string $sMessage): void |
|
| 332 | +{ |
|
| 333 | +$this->aDebugMessages[] = $sMessage; |
|
| 334 | +} |
|
| 335 | 335 | |
| 336 | - /** |
|
| 336 | +/** |
|
| 337 | 337 | * Clear the response and appends a debug message on the end of the debug message queue |
| 338 | 338 | * |
| 339 | 339 | * @param string $sMessage The debug message |
| 340 | 340 | * |
| 341 | 341 | * @return void |
| 342 | 342 | */ |
| 343 | - public function error(string $sMessage): void |
|
| 344 | - { |
|
| 345 | - $this->clearCommands(); |
|
| 346 | - $this->debug($sMessage); |
|
| 347 | - } |
|
| 343 | +public function error(string $sMessage): void |
|
| 344 | +{ |
|
| 345 | +$this->clearCommands(); |
|
| 346 | +$this->debug($sMessage); |
|
| 347 | +} |
|
| 348 | 348 | |
| 349 | - /** |
|
| 349 | +/** |
|
| 350 | 350 | * Prints the debug messages into the current response object |
| 351 | 351 | * |
| 352 | 352 | * @return void |
| 353 | 353 | */ |
| 354 | - public function printDebug() |
|
| 355 | - { |
|
| 356 | - foreach($this->aDebugMessages as $sMessage) |
|
| 357 | - { |
|
| 358 | - $this->addCommand('script.debug', ['message' => $this->str($sMessage)]); |
|
| 359 | - } |
|
| 360 | - // $this->aDebugMessages = []; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 354 | +public function printDebug() |
|
| 355 | +{ |
|
| 356 | +foreach($this->aDebugMessages as $sMessage) |
|
| 357 | +{ |
|
| 358 | +$this->addCommand('script.debug', ['message' => $this->str($sMessage)]); |
|
| 359 | +} |
|
| 360 | +// $this->aDebugMessages = []; |
|
| 361 | +} |
|
| 362 | + |
|
| 363 | +/** |
|
| 364 | 364 | * Get the content type of the HTTP response |
| 365 | 365 | * |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function getContentType(): string |
|
| 369 | - { |
|
| 370 | - return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : |
|
| 371 | - $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 372 | - } |
|
| 368 | +public function getContentType(): string |
|
| 369 | +{ |
|
| 370 | +return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : |
|
| 371 | +$this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 372 | +} |
|
| 373 | 373 | |
| 374 | - /** |
|
| 374 | +/** |
|
| 375 | 375 | * Get the JSON output of the response |
| 376 | 376 | * |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function getOutput(): string |
|
| 380 | - { |
|
| 381 | - return $this->getResponse()->getOutput(); |
|
| 382 | - } |
|
| 379 | +public function getOutput(): string |
|
| 380 | +{ |
|
| 381 | +return $this->getResponse()->getOutput(); |
|
| 382 | +} |
|
| 383 | 383 | |
| 384 | - /** |
|
| 384 | +/** |
|
| 385 | 385 | * Get the debug messages |
| 386 | 386 | * |
| 387 | 387 | * @return array |
| 388 | 388 | */ |
| 389 | - public function getDebugMessages(): array |
|
| 390 | - { |
|
| 391 | - return $this->aDebugMessages; |
|
| 392 | - } |
|
| 389 | +public function getDebugMessages(): array |
|
| 390 | +{ |
|
| 391 | +return $this->aDebugMessages; |
|
| 392 | +} |
|
| 393 | 393 | } |
@@ -21,42 +21,42 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | class Command implements ArrayAccess, JsonSerializable |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - private $aCommand; |
|
| 27 | +private $aCommand; |
|
| 28 | 28 | |
| 29 | - public function __construct(array $aCommand) |
|
| 30 | - { |
|
| 31 | - $this->aCommand = $aCommand; |
|
| 32 | - } |
|
| 29 | +public function __construct(array $aCommand) |
|
| 30 | +{ |
|
| 31 | +$this->aCommand = $aCommand; |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * Set a component on the command |
| 36 | 36 | * |
| 37 | 37 | * @param array $aComponent |
| 38 | 38 | * |
| 39 | 39 | * @return Command |
| 40 | 40 | */ |
| 41 | - public function setComponent(array $aComponent): Command |
|
| 42 | - { |
|
| 43 | - $this->aCommand['component'] = $aComponent; |
|
| 44 | - return $this; |
|
| 45 | - } |
|
| 41 | +public function setComponent(array $aComponent): Command |
|
| 42 | +{ |
|
| 43 | +$this->aCommand['component'] = $aComponent; |
|
| 44 | +return $this; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * Convert to string |
| 49 | 49 | * |
| 50 | 50 | * @param mixed $xData |
| 51 | 51 | * |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - private function str($xData): string |
|
| 55 | - { |
|
| 56 | - return trim((string)$xData, " \t\n"); |
|
| 57 | - } |
|
| 54 | +private function str($xData): string |
|
| 55 | +{ |
|
| 56 | +return trim((string)$xData, " \t\n"); |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * Add an option to the command |
| 61 | 61 | * |
| 62 | 62 | * @param string $sName The option name |
@@ -64,50 +64,50 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return Command |
| 66 | 66 | */ |
| 67 | - public function setOption(string $sName, string|array|JsonSerializable $xValue): Command |
|
| 68 | - { |
|
| 69 | - if(isset($this->aCommand['options'])) |
|
| 70 | - { |
|
| 71 | - $this->aCommand['options'][$this->str($sName)] = $xValue; |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 74 | - $this->aCommand['options'] = [$this->str($sName) => $xValue]; |
|
| 75 | - return $this; |
|
| 76 | - } |
|
| 67 | +public function setOption(string $sName, string|array|JsonSerializable $xValue): Command |
|
| 68 | +{ |
|
| 69 | +if(isset($this->aCommand['options'])) |
|
| 70 | +{ |
|
| 71 | +$this->aCommand['options'][$this->str($sName)] = $xValue; |
|
| 72 | +return $this; |
|
| 73 | +} |
|
| 74 | +$this->aCommand['options'] = [$this->str($sName) => $xValue]; |
|
| 75 | +return $this; |
|
| 76 | +} |
|
| 77 | 77 | |
| 78 | - /** |
|
| 78 | +/** |
|
| 79 | 79 | * @inheritDoc |
| 80 | 80 | */ |
| 81 | - public function jsonSerialize(): array |
|
| 82 | - { |
|
| 83 | - return $this->aCommand; |
|
| 84 | - } |
|
| 81 | +public function jsonSerialize(): array |
|
| 82 | +{ |
|
| 83 | +return $this->aCommand; |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * @inheritDoc |
| 88 | 88 | */ |
| 89 | - public function offsetExists($offset): bool |
|
| 90 | - { |
|
| 91 | - return isset($this->aCommand[$offset]); |
|
| 92 | - } |
|
| 89 | +public function offsetExists($offset): bool |
|
| 90 | +{ |
|
| 91 | +return isset($this->aCommand[$offset]); |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * @inheritDoc |
| 96 | 96 | */ |
| 97 | - public function offsetGet($offset): mixed |
|
| 98 | - { |
|
| 99 | - return $this->aCommand[$offset] ?? null; |
|
| 100 | - } |
|
| 97 | +public function offsetGet($offset): mixed |
|
| 98 | +{ |
|
| 99 | +return $this->aCommand[$offset] ?? null; |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - /** |
|
| 102 | +/** |
|
| 103 | 103 | * @inheritDoc |
| 104 | 104 | */ |
| 105 | - public function offsetSet($offset, $value): void |
|
| 106 | - {} // Not implemented |
|
| 105 | +public function offsetSet($offset, $value): void |
|
| 106 | +{} // Not implemented |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * @inheritDoc |
| 110 | 110 | */ |
| 111 | - public function offsetUnset($offset): void |
|
| 112 | - {} // Not implemented |
|
| 111 | +public function offsetUnset($offset): void |
|
| 112 | +{} // Not implemented |
|
| 113 | 113 | } |
@@ -28,40 +28,40 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class NodeResponse extends AjaxResponse |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @var array |
| 33 | 33 | */ |
| 34 | - private $aComponent = []; |
|
| 34 | +private $aComponent = []; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * The constructor |
| 38 | 38 | * |
| 39 | 39 | * @param ResponseManager $xManager |
| 40 | 40 | * @param PluginManager $xPluginManager |
| 41 | 41 | * @param JxnCall $xJxnCall |
| 42 | 42 | */ |
| 43 | - public function __construct(ResponseManager $xManager, |
|
| 44 | - PluginManager $xPluginManager, JxnCall $xJxnCall) |
|
| 45 | - { |
|
| 46 | - parent::__construct($xManager, $xPluginManager); |
|
| 47 | - // The js class name is also the component name. |
|
| 48 | - $this->aComponent['name'] = $this->str($xJxnCall->_class()); |
|
| 49 | - } |
|
| 43 | +public function __construct(ResponseManager $xManager, |
|
| 44 | +PluginManager $xPluginManager, JxnCall $xJxnCall) |
|
| 45 | +{ |
|
| 46 | +parent::__construct($xManager, $xPluginManager); |
|
| 47 | +// The js class name is also the component name. |
|
| 48 | +$this->aComponent['name'] = $this->str($xJxnCall->_class()); |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Set the component item |
| 53 | 53 | * |
| 54 | 54 | * @param string $sItem |
| 55 | 55 | * |
| 56 | 56 | * @return self |
| 57 | 57 | */ |
| 58 | - public function item(string $sItem = 'main'): self |
|
| 59 | - { |
|
| 60 | - $this->aComponent['item'] = $this->str($sItem); |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 58 | +public function item(string $sItem = 'main'): self |
|
| 59 | +{ |
|
| 60 | +$this->aComponent['item'] = $this->str($sItem); |
|
| 61 | +return $this; |
|
| 62 | +} |
|
| 63 | 63 | |
| 64 | - /** |
|
| 64 | +/** |
|
| 65 | 65 | * Add a response command to the array of commands |
| 66 | 66 | * |
| 67 | 67 | * @param string $sName The command name |
@@ -70,15 +70,15 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return Command |
| 72 | 72 | */ |
| 73 | - public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
|
| 74 | - bool $bRemoveEmpty = false): Command |
|
| 75 | - { |
|
| 76 | - return $this->xManager |
|
| 77 | - ->addCommand($sName, $aArgs, $bRemoveEmpty) |
|
| 78 | - ->setComponent($this->aComponent); |
|
| 79 | - } |
|
| 73 | +public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
|
| 74 | +bool $bRemoveEmpty = false): Command |
|
| 75 | +{ |
|
| 76 | +return $this->xManager |
|
| 77 | +->addCommand($sName, $aArgs, $bRemoveEmpty) |
|
| 78 | +->setComponent($this->aComponent); |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * Add a command to assign the specified value to the given element's attribute |
| 83 | 83 | * |
| 84 | 84 | * @param string $sAttribute The attribute to be assigned |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return self |
| 88 | 88 | */ |
| 89 | - public function assign(string $sAttribute, string $sValue): self |
|
| 90 | - { |
|
| 91 | - $this->addCommand('node.assign', [ |
|
| 92 | - 'attr' => $this->str($sAttribute), |
|
| 93 | - 'value' => $this->str($sValue), |
|
| 94 | - ]); |
|
| 95 | - return $this; |
|
| 96 | - } |
|
| 89 | +public function assign(string $sAttribute, string $sValue): self |
|
| 90 | +{ |
|
| 91 | +$this->addCommand('node.assign', [ |
|
| 92 | +'attr' => $this->str($sAttribute), |
|
| 93 | +'value' => $this->str($sValue), |
|
| 94 | +]); |
|
| 95 | +return $this; |
|
| 96 | +} |
|
| 97 | 97 | |
| 98 | - /** |
|
| 98 | +/** |
|
| 99 | 99 | * Add a command to assign the specified HTML content to the given element |
| 100 | 100 | * |
| 101 | 101 | * This is a shortcut for assign() on the innerHTML attribute. |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return self |
| 106 | 106 | */ |
| 107 | - public function html(string $sValue): self |
|
| 108 | - { |
|
| 109 | - return $this->assign('innerHTML', $sValue); |
|
| 110 | - } |
|
| 107 | +public function html(string $sValue): self |
|
| 108 | +{ |
|
| 109 | +return $this->assign('innerHTML', $sValue); |
|
| 110 | +} |
|
| 111 | 111 | |
| 112 | - /** |
|
| 112 | +/** |
|
| 113 | 113 | * Add a command to assign the specified value to the given CSS attribute |
| 114 | 114 | * |
| 115 | 115 | * @param string $sCssAttribute The CSS attribute to be assigned |
@@ -117,12 +117,12 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return self |
| 119 | 119 | */ |
| 120 | - public function style(string $sCssAttribute, string $sValue): self |
|
| 121 | - { |
|
| 122 | - return $this->assign("style.$sCssAttribute", $sValue); |
|
| 123 | - } |
|
| 120 | +public function style(string $sCssAttribute, string $sValue): self |
|
| 121 | +{ |
|
| 122 | +return $this->assign("style.$sCssAttribute", $sValue); |
|
| 123 | +} |
|
| 124 | 124 | |
| 125 | - /** |
|
| 125 | +/** |
|
| 126 | 126 | * Add a command to append the specified data to the given element's attribute |
| 127 | 127 | * |
| 128 | 128 | * @param string $sAttribute The name of the attribute to be appended to |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return self |
| 132 | 132 | */ |
| 133 | - public function append(string $sAttribute, string $sValue): self |
|
| 134 | - { |
|
| 135 | - $this->addCommand('node.append', [ |
|
| 136 | - 'attr' => $this->str($sAttribute), |
|
| 137 | - 'value' => $this->str($sValue), |
|
| 138 | - ]); |
|
| 139 | - return $this; |
|
| 140 | - } |
|
| 133 | +public function append(string $sAttribute, string $sValue): self |
|
| 134 | +{ |
|
| 135 | +$this->addCommand('node.append', [ |
|
| 136 | +'attr' => $this->str($sAttribute), |
|
| 137 | +'value' => $this->str($sValue), |
|
| 138 | +]); |
|
| 139 | +return $this; |
|
| 140 | +} |
|
| 141 | 141 | |
| 142 | - /** |
|
| 142 | +/** |
|
| 143 | 143 | * Add a command to prepend the specified data to the given element's attribute |
| 144 | 144 | * |
| 145 | 145 | * @param string $sAttribute The name of the attribute to be prepended to |
@@ -147,16 +147,16 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return self |
| 149 | 149 | */ |
| 150 | - public function prepend(string $sAttribute, string $sValue): self |
|
| 151 | - { |
|
| 152 | - $this->addCommand('node.prepend', [ |
|
| 153 | - 'attr' => $this->str($sAttribute), |
|
| 154 | - 'value' => $this->str($sValue), |
|
| 155 | - ]); |
|
| 156 | - return $this; |
|
| 157 | - } |
|
| 150 | +public function prepend(string $sAttribute, string $sValue): self |
|
| 151 | +{ |
|
| 152 | +$this->addCommand('node.prepend', [ |
|
| 153 | +'attr' => $this->str($sAttribute), |
|
| 154 | +'value' => $this->str($sValue), |
|
| 155 | +]); |
|
| 156 | +return $this; |
|
| 157 | +} |
|
| 158 | 158 | |
| 159 | - /** |
|
| 159 | +/** |
|
| 160 | 160 | * Add a command to replace a specified value with another value within the given element's attribute |
| 161 | 161 | * |
| 162 | 162 | * @param string $sAttribute The attribute to be updated |
@@ -165,39 +165,39 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return self |
| 167 | 167 | */ |
| 168 | - public function replace(string $sAttribute, string $sSearch, string $sReplace): self |
|
| 169 | - { |
|
| 170 | - $this->addCommand('node.replace', [ |
|
| 171 | - 'attr' => $this->str($sAttribute), |
|
| 172 | - 'search' => $this->str($sSearch), |
|
| 173 | - 'replace' => $this->str($sReplace), |
|
| 174 | - ]); |
|
| 175 | - return $this; |
|
| 176 | - } |
|
| 168 | +public function replace(string $sAttribute, string $sSearch, string $sReplace): self |
|
| 169 | +{ |
|
| 170 | +$this->addCommand('node.replace', [ |
|
| 171 | +'attr' => $this->str($sAttribute), |
|
| 172 | +'search' => $this->str($sSearch), |
|
| 173 | +'replace' => $this->str($sReplace), |
|
| 174 | +]); |
|
| 175 | +return $this; |
|
| 176 | +} |
|
| 177 | 177 | |
| 178 | - /** |
|
| 178 | +/** |
|
| 179 | 179 | * Add a command to clear the specified attribute of the given element |
| 180 | 180 | * |
| 181 | 181 | * @param string $sAttribute The attribute to be cleared |
| 182 | 182 | * |
| 183 | 183 | * @return self |
| 184 | 184 | */ |
| 185 | - public function clear(string $sAttribute = 'innerHTML'): self |
|
| 186 | - { |
|
| 187 | - $this->addCommand('node.clear', [ |
|
| 188 | - 'attr' => $this->str($sAttribute), |
|
| 189 | - ]); |
|
| 190 | - return $this; |
|
| 191 | - } |
|
| 185 | +public function clear(string $sAttribute = 'innerHTML'): self |
|
| 186 | +{ |
|
| 187 | +$this->addCommand('node.clear', [ |
|
| 188 | +'attr' => $this->str($sAttribute), |
|
| 189 | +]); |
|
| 190 | +return $this; |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - /** |
|
| 193 | +/** |
|
| 194 | 194 | * Add a command to remove an element from the document |
| 195 | 195 | * |
| 196 | 196 | * @return self |
| 197 | 197 | */ |
| 198 | - public function remove(): self |
|
| 199 | - { |
|
| 200 | - $this->addCommand('node.remove', []); |
|
| 201 | - return $this; |
|
| 202 | - } |
|
| 198 | +public function remove(): self |
|
| 199 | +{ |
|
| 200 | +$this->addCommand('node.remove', []); |
|
| 201 | +return $this; |
|
| 202 | +} |
|
| 203 | 203 | } |