@@ -1,3 +1,3 @@ |
||
| 1 | -<?php foreach($this->aUrls as $sUrl): |
|
| 1 | +<?php foreach ($this->aUrls as $sUrl): |
|
| 2 | 2 | $this->include('jaxon::plugins/include.js', ['sUrl' => $sUrl, 'sJsOptions' => $this->sJsOptions]); |
| 3 | 3 | endforeach; |
@@ -237,7 +237,7 @@ |
||
| 237 | 237 | */ |
| 238 | 238 | public function val(string $sKey, $xValue) |
| 239 | 239 | { |
| 240 | - $this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 240 | + $this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -198,8 +198,7 @@ |
||
| 198 | 198 | { |
| 199 | 199 | return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
| 200 | 200 | $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
| 201 | - } |
|
| 202 | - catch(Throwable $e) |
|
| 201 | + } catch(Throwable $e) |
|
| 203 | 202 | { |
| 204 | 203 | $xLogger = $this->g(LoggerInterface::class); |
| 205 | 204 | $xTranslator = $this->g(Translator::class); |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | public function setLogger(LoggerInterface|Closure $xLogger) |
| 117 | 117 | { |
| 118 | 118 | is_a($xLogger, LoggerInterface::class) ? |
| 119 | - $this->val(LoggerInterface::class, $xLogger) : |
|
| 120 | - $this->set(LoggerInterface::class, $xLogger); |
|
| 119 | + $this->val(LoggerInterface::class, $xLogger) : $this->set(LoggerInterface::class, $xLogger); |
|
| 121 | 120 | } |
| 122 | 121 | |
| 123 | 122 | /** |
@@ -196,7 +195,7 @@ discard block |
||
| 196 | 195 | return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
| 197 | 196 | $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
| 198 | 197 | } |
| 199 | - catch(Throwable $e) |
|
| 198 | + catch (Throwable $e) |
|
| 200 | 199 | { |
| 201 | 200 | $xLogger = $this->g(LoggerInterface::class); |
| 202 | 201 | $xTranslator = $this->g(Translator::class); |
@@ -37,7 +37,6 @@ |
||
| 37 | 37 | public function getMetadataReader(string $sReaderId): MetadataReaderInterface |
| 38 | 38 | { |
| 39 | 39 | return $this->h("metadata_reader_$sReaderId") ? |
| 40 | - $this->g("metadata_reader_$sReaderId") : |
|
| 41 | - $this->g('metadata_reader_null'); |
|
| 40 | + $this->g("metadata_reader_$sReaderId") : $this->g('metadata_reader_null'); |
|
| 42 | 41 | } |
| 43 | 42 | } |
@@ -58,8 +58,7 @@ |
||
| 58 | 58 | $xParameterReader = $di->g(ParameterReader::class); |
| 59 | 59 | $xRequest = $di->g(ServerRequestInterface::class); |
| 60 | 60 | $aRequestParameter = $xParameterReader->getRequestParameter($xRequest); |
| 61 | - return !is_array($aRequestParameter) ? $xRequest : |
|
| 62 | - $xRequest->withAttribute('jxncall', $aRequestParameter); |
|
| 61 | + return !is_array($aRequestParameter) ? $xRequest : $xRequest->withAttribute('jxncall', $aRequestParameter); |
|
| 63 | 62 | }); |
| 64 | 63 | // PSR factory |
| 65 | 64 | $this->set(PsrFactory::class, function($di) { |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | public function registerPackage(string $sClassName, array $aUserOptions): void |
| 194 | 194 | { |
| 195 | 195 | // Register the user class, but only if the user didn't already. |
| 196 | - if(!$this->h($sClassName)) |
|
| 196 | + if (!$this->h($sClassName)) |
|
| 197 | 197 | { |
| 198 | 198 | $this->set($sClassName, fn() => $this->make($sClassName)); |
| 199 | 199 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $this->set($sConfigKey, function($di) use($aUserOptions) { |
| 204 | 204 | $xOptionsProvider = $aUserOptions['provider'] ?? null; |
| 205 | 205 | // The user can provide a callable that returns the package options. |
| 206 | - if(is_callable($xOptionsProvider)) |
|
| 206 | + if (is_callable($xOptionsProvider)) |
|
| 207 | 207 | { |
| 208 | 208 | $aUserOptions = $xOptionsProvider($aUserOptions); |
| 209 | 209 | } |
@@ -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 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array |
| 188 | 188 | { |
| 189 | - if(!$bRemoveEmpty) |
|
| 189 | + if (!$bRemoveEmpty) |
|
| 190 | 190 | { |
| 191 | 191 | return $aArgs; |
| 192 | 192 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | 'name' => $this->str($sName), |
| 212 | 212 | 'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty), |
| 213 | 213 | ]); |
| 214 | - if($this->bOnConfirm) |
|
| 214 | + if ($this->bOnConfirm) |
|
| 215 | 215 | { |
| 216 | 216 | $this->aConfirmCommands[] = $xCommand; |
| 217 | 217 | } |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | public function addConfirmCommand(string $sName, Closure $fConfirm, |
| 241 | 241 | string $sQuestion, array $aArgs = []): self |
| 242 | 242 | { |
| 243 | - if($this->bOnConfirm) |
|
| 243 | + if ($this->bOnConfirm) |
|
| 244 | 244 | { |
| 245 | 245 | throw new AppException($this->xTranslator->trans('errors.app.confirm.nested')); |
| 246 | 246 | } |
| 247 | 247 | $this->bOnConfirm = true; |
| 248 | 248 | $fConfirm(); |
| 249 | 249 | $this->bOnConfirm = false; |
| 250 | - if(($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 250 | + if (($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 251 | 251 | { |
| 252 | 252 | $aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs); |
| 253 | 253 | $aCommand['count'] = $nCommandCount; |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | public function printDebug() |
| 356 | 356 | { |
| 357 | - foreach($this->aDebugMessages as $sMessage) |
|
| 357 | + foreach ($this->aDebugMessages as $sMessage) |
|
| 358 | 358 | { |
| 359 | 359 | $this->addCommand('script.debug', ['message' => $this->str($sMessage)]); |
| 360 | 360 | } |
@@ -368,8 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | public function getContentType(): string |
| 370 | 370 | { |
| 371 | - return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : |
|
| 372 | - $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 371 | + return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 373 | 372 | } |
| 374 | 373 | |
| 375 | 374 | /** |
@@ -214,8 +214,7 @@ |
||
| 214 | 214 | if($this->bOnConfirm) |
| 215 | 215 | { |
| 216 | 216 | $this->aConfirmCommands[] = $xCommand; |
| 217 | - } |
|
| 218 | - else |
|
| 217 | + } else |
|
| 219 | 218 | { |
| 220 | 219 | $this->aCommands[] = $xCommand; |
| 221 | 220 | } |
@@ -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 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | */ |
| 67 | 67 | public function setOption(string $sName, string|array|JsonSerializable $xValue): Command |
| 68 | 68 | { |
| 69 | - if(isset($this->aCommand['options'])) |
|
| 69 | + if (isset($this->aCommand['options'])) |
|
| 70 | 70 | { |
| 71 | 71 | $this->aCommand['options'][$this->str($sName)] = $xValue; |
| 72 | 72 | return $this; |
@@ -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 | } |
@@ -91,15 +91,15 @@ |
||
| 91 | 91 | return $this->xManager->getErrorMessage(); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Add a response command to the array of commands |
|
| 96 | - * |
|
| 97 | - * @param string $sName The command name |
|
| 98 | - * @param array|JsonSerializable $aArgs The command arguments |
|
| 99 | - * @param bool $bRemoveEmpty |
|
| 100 | - * |
|
| 101 | - * @return Command |
|
| 102 | - */ |
|
| 94 | + /** |
|
| 95 | + * Add a response command to the array of commands |
|
| 96 | + * |
|
| 97 | + * @param string $sName The command name |
|
| 98 | + * @param array|JsonSerializable $aArgs The command arguments |
|
| 99 | + * @param bool $bRemoveEmpty |
|
| 100 | + * |
|
| 101 | + * @return Command |
|
| 102 | + */ |
|
| 103 | 103 | public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
| 104 | 104 | bool $bRemoveEmpty = false): Command |
| 105 | 105 | { |
@@ -30,68 +30,68 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | abstract class AbstractResponse |
| 32 | 32 | { |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * @var ResponseManager |
| 35 | 35 | */ |
| 36 | - protected $xManager; |
|
| 36 | +protected $xManager; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @var PluginManager |
| 40 | 40 | */ |
| 41 | - protected $xPluginManager; |
|
| 41 | +protected $xPluginManager; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The constructor |
| 45 | 45 | * |
| 46 | 46 | * @param ResponseManager $xManager |
| 47 | 47 | * @param PluginManager $xPluginManager |
| 48 | 48 | */ |
| 49 | - public function __construct(ResponseManager $xManager, PluginManager $xPluginManager) |
|
| 50 | - { |
|
| 51 | - $this->xManager = $xManager; |
|
| 52 | - $this->xPluginManager = $xPluginManager; |
|
| 53 | - } |
|
| 49 | +public function __construct(ResponseManager $xManager, PluginManager $xPluginManager) |
|
| 50 | +{ |
|
| 51 | +$this->xManager = $xManager; |
|
| 52 | +$this->xPluginManager = $xPluginManager; |
|
| 53 | +} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * @inheritDoc |
| 57 | 57 | */ |
| 58 | - abstract public function getContentType(): string; |
|
| 58 | +abstract public function getContentType(): string; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @inheritDoc |
| 62 | 62 | */ |
| 63 | - abstract public function getOutput(): string; |
|
| 63 | +abstract public function getOutput(): string; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * Convert this response to a PSR7 response object |
| 67 | 67 | * |
| 68 | 68 | * @return PsrResponseInterface |
| 69 | 69 | */ |
| 70 | - abstract public function toPsr(): PsrResponseInterface; |
|
| 70 | +abstract public function toPsr(): PsrResponseInterface; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * Convert to string |
| 74 | 74 | * |
| 75 | 75 | * @param mixed $xData |
| 76 | 76 | * |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - protected function str($xData): string |
|
| 80 | - { |
|
| 81 | - return $this->xManager->str($xData); |
|
| 82 | - } |
|
| 79 | +protected function str($xData): string |
|
| 80 | +{ |
|
| 81 | +return $this->xManager->str($xData); |
|
| 82 | +} |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * Get the error message |
| 86 | 86 | * |
| 87 | 87 | * @return string |
| 88 | 88 | */ |
| 89 | - public function getErrorMessage(): string |
|
| 90 | - { |
|
| 91 | - return $this->xManager->getErrorMessage(); |
|
| 92 | - } |
|
| 89 | +public function getErrorMessage(): string |
|
| 90 | +{ |
|
| 91 | +return $this->xManager->getErrorMessage(); |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * Add a response command to the array of commands |
| 96 | 96 | * |
| 97 | 97 | * @param string $sName The command name |
@@ -100,43 +100,43 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @return Command |
| 102 | 102 | */ |
| 103 | - public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
|
| 104 | - bool $bRemoveEmpty = false): Command |
|
| 105 | - { |
|
| 106 | - return $this->xManager->addCommand($sName, $aArgs, $bRemoveEmpty); |
|
| 107 | - } |
|
| 103 | +public function addCommand(string $sName, array|JsonSerializable $aArgs = [], |
|
| 104 | +bool $bRemoveEmpty = false): Command |
|
| 105 | +{ |
|
| 106 | +return $this->xManager->addCommand($sName, $aArgs, $bRemoveEmpty); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Get the commands in the response |
| 111 | 111 | * |
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | - public function getCommands(): array |
|
| 115 | - { |
|
| 116 | - return $this->xManager->getCommands(); |
|
| 117 | - } |
|
| 114 | +public function getCommands(): array |
|
| 115 | +{ |
|
| 116 | +return $this->xManager->getCommands(); |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - /** |
|
| 119 | +/** |
|
| 120 | 120 | * Get the number of commands in the response |
| 121 | 121 | * |
| 122 | 122 | * @return int |
| 123 | 123 | */ |
| 124 | - public function getCommandCount(): int |
|
| 125 | - { |
|
| 126 | - return $this->xManager->getCommandCount(); |
|
| 127 | - } |
|
| 124 | +public function getCommandCount(): int |
|
| 125 | +{ |
|
| 126 | +return $this->xManager->getCommandCount(); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - /** |
|
| 129 | +/** |
|
| 130 | 130 | * Clear all the commands already added to the response |
| 131 | 131 | * |
| 132 | 132 | * @return void |
| 133 | 133 | */ |
| 134 | - public function clearCommands(): void |
|
| 135 | - { |
|
| 136 | - $this->xManager->clearCommands(); |
|
| 137 | - } |
|
| 134 | +public function clearCommands(): void |
|
| 135 | +{ |
|
| 136 | +$this->xManager->clearCommands(); |
|
| 137 | +} |
|
| 138 | 138 | |
| 139 | - /** |
|
| 139 | +/** |
|
| 140 | 140 | * Find a response plugin by name or class name |
| 141 | 141 | * |
| 142 | 142 | * @template R of ResponsePluginInterface |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return ($sName is class-string ? R|null : ResponsePluginInterface|null) |
| 146 | 146 | */ |
| 147 | - public function plugin(string $sName): ?ResponsePluginInterface |
|
| 148 | - { |
|
| 149 | - $xResponsePlugin = $this->xPluginManager->getResponsePlugin($sName); |
|
| 150 | - return !$xResponsePlugin ? null : $xResponsePlugin->initPlugin($this); |
|
| 151 | - } |
|
| 147 | +public function plugin(string $sName): ?ResponsePluginInterface |
|
| 148 | +{ |
|
| 149 | +$xResponsePlugin = $this->xPluginManager->getResponsePlugin($sName); |
|
| 150 | +return !$xResponsePlugin ? null : $xResponsePlugin->initPlugin($this); |
|
| 151 | +} |
|
| 152 | 152 | |
| 153 | - /** |
|
| 153 | +/** |
|
| 154 | 154 | * Magic PHP function |
| 155 | 155 | * |
| 156 | 156 | * Used to permit plugins to be called as if they were native members of the Response instance. |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return null|ResponsePluginInterface |
| 161 | 161 | */ |
| 162 | - public function __get(string $sPluginName) |
|
| 163 | - { |
|
| 164 | - return $this->plugin($sPluginName); |
|
| 165 | - } |
|
| 162 | +public function __get(string $sPluginName) |
|
| 163 | +{ |
|
| 164 | +return $this->plugin($sPluginName); |
|
| 165 | +} |
|
| 166 | 166 | } |
@@ -218,8 +218,7 @@ |
||
| 218 | 218 | { |
| 219 | 219 | // A string is supposed to be the path to a config file. |
| 220 | 220 | $aLibOptions = $this->xConfigManager->read($aLibOptions); |
| 221 | - } |
|
| 222 | - elseif(!is_array($aLibOptions)) |
|
| 221 | + } elseif(!is_array($aLibOptions)) |
|
| 223 | 222 | { |
| 224 | 223 | // Otherwise, anything else than an array is not accepted. |
| 225 | 224 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -62,25 +62,25 @@ discard block |
||
| 62 | 62 | private function updateContainer(Config $xConfig): void |
| 63 | 63 | { |
| 64 | 64 | $aOptions = $xConfig->getOption('container.set', []); |
| 65 | - foreach($aOptions as $xKey => $xValue) |
|
| 65 | + foreach ($aOptions as $xKey => $xValue) |
|
| 66 | 66 | { |
| 67 | 67 | // The key is the class name. It must be a string. |
| 68 | 68 | $this->di->set((string)$xKey, $xValue); |
| 69 | 69 | } |
| 70 | 70 | $aOptions = $xConfig->getOption('container.val', []); |
| 71 | - foreach($aOptions as $xKey => $xValue) |
|
| 71 | + foreach ($aOptions as $xKey => $xValue) |
|
| 72 | 72 | { |
| 73 | 73 | // The key is the class name. It must be a string. |
| 74 | 74 | $this->di->val((string)$xKey, $xValue); |
| 75 | 75 | } |
| 76 | 76 | $aOptions = $xConfig->getOption('container.auto', []); |
| 77 | - foreach($aOptions as $xValue) |
|
| 77 | + foreach ($aOptions as $xValue) |
|
| 78 | 78 | { |
| 79 | 79 | // The key is the class name. It must be a string. |
| 80 | 80 | $this->di->auto((string)$xValue); |
| 81 | 81 | } |
| 82 | 82 | $aOptions = $xConfig->getOption('container.alias', []); |
| 83 | - foreach($aOptions as $xKey => $xValue) |
|
| 83 | + foreach ($aOptions as $xKey => $xValue) |
|
| 84 | 84 | { |
| 85 | 85 | // The key is the class name. It must be a string. |
| 86 | 86 | $this->di->alias((string)$xKey, (string)$xValue); |
@@ -98,16 +98,16 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | private function registerCallables(array $aOptions, string $sCallableType): void |
| 100 | 100 | { |
| 101 | - foreach($aOptions as $xKey => $xValue) |
|
| 101 | + foreach ($aOptions as $xKey => $xValue) |
|
| 102 | 102 | { |
| 103 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 103 | + if (is_integer($xKey) && is_string($xValue)) |
|
| 104 | 104 | { |
| 105 | 105 | // Register a function without options |
| 106 | 106 | $this->xPluginManager->registerCallable($sCallableType, $xValue); |
| 107 | 107 | continue; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 110 | + if (is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | 111 | { |
| 112 | 112 | // Register a function with options |
| 113 | 113 | $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | private function registerExceptionHandlers(Config $xConfig): void |
| 126 | 126 | { |
| 127 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 127 | + foreach ($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | 128 | { |
| 129 | 129 | $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
| 130 | 130 | } |
@@ -147,20 +147,20 @@ discard block |
||
| 147 | 147 | // key of the array item, a string as the value of an entry without a key, |
| 148 | 148 | // or set with the key $sOptionKey in an array entry without a key. |
| 149 | 149 | $aCallables = []; |
| 150 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 150 | + foreach ($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | 151 | { |
| 152 | - if(is_string($xKey)) |
|
| 152 | + if (is_string($xKey)) |
|
| 153 | 153 | { |
| 154 | 154 | $aCallables[$xKey] = $xValue; |
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | - if(is_string($xValue)) |
|
| 157 | + if (is_string($xValue)) |
|
| 158 | 158 | { |
| 159 | 159 | $aCallables[] = $xValue; |
| 160 | 160 | continue; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 163 | + if (is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | 164 | { |
| 165 | 165 | $aCallables[$xValue[$sOptionKey]] = $xValue; |
| 166 | 166 | } |
@@ -215,12 +215,12 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | // $this->aPackages contains packages config file paths. |
| 217 | 217 | $aLibOptions = $sClassName::config(); |
| 218 | - if(is_string($aLibOptions)) |
|
| 218 | + if (is_string($aLibOptions)) |
|
| 219 | 219 | { |
| 220 | 220 | // A string is supposed to be the path to a config file. |
| 221 | 221 | $aLibOptions = $this->xConfigManager->read($aLibOptions); |
| 222 | 222 | } |
| 223 | - elseif(!is_array($aLibOptions)) |
|
| 223 | + elseif (!is_array($aLibOptions)) |
|
| 224 | 224 | { |
| 225 | 225 | // Otherwise, anything else than an array is not accepted. |
| 226 | 226 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | public function registerPackage(string $sClassName, array $aUserOptions = []): void |
| 244 | 244 | { |
| 245 | 245 | $sClassName = trim($sClassName, '\\ '); |
| 246 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 246 | + if (!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | 247 | { |
| 248 | 248 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
| 249 | 249 | throw new SetupException($sMessage); |
@@ -287,9 +287,9 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | // Register packages |
| 289 | 289 | $aPackageConfig = $xAppConfig->getOption('packages', []); |
| 290 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 290 | + foreach ($aPackageConfig as $xKey => $xValue) |
|
| 291 | 291 | { |
| 292 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 292 | + if (is_integer($xKey) && is_string($xValue)) |
|
| 293 | 293 | { |
| 294 | 294 | // Register a package without options |
| 295 | 295 | $sClassName = $xValue; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | continue; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if(is_string($xKey) && is_array($xValue)) |
|
| 300 | + if (is_string($xKey) && is_array($xValue)) |
|
| 301 | 301 | { |
| 302 | 302 | // Register a package with options |
| 303 | 303 | $sClassName = $xKey; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class PackageManager |
| 36 | 36 | { |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The constructor |
| 39 | 39 | * |
| 40 | 40 | * @param Container $di |
@@ -46,48 +46,48 @@ discard block |
||
| 46 | 46 | * @param CallbackManager $xCallbackManager |
| 47 | 47 | * @param ComponentRegistry $xRegistry |
| 48 | 48 | */ |
| 49 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | - private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | - private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | - private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | - {} |
|
| 49 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | +private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | +private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | +private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | +{} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Save items in the DI container |
| 57 | 57 | * |
| 58 | 58 | * @param Config $xConfig |
| 59 | 59 | * |
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | - private function updateContainer(Config $xConfig): void |
|
| 63 | - { |
|
| 64 | - $aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | - foreach($aOptions as $xKey => $xValue) |
|
| 66 | - { |
|
| 67 | - // The key is the class name. It must be a string. |
|
| 68 | - $this->di->set((string)$xKey, $xValue); |
|
| 69 | - } |
|
| 70 | - $aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | - foreach($aOptions as $xKey => $xValue) |
|
| 72 | - { |
|
| 73 | - // The key is the class name. It must be a string. |
|
| 74 | - $this->di->val((string)$xKey, $xValue); |
|
| 75 | - } |
|
| 76 | - $aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | - foreach($aOptions as $xValue) |
|
| 78 | - { |
|
| 79 | - // The key is the class name. It must be a string. |
|
| 80 | - $this->di->auto((string)$xValue); |
|
| 81 | - } |
|
| 82 | - $aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | - foreach($aOptions as $xKey => $xValue) |
|
| 84 | - { |
|
| 85 | - // The key is the class name. It must be a string. |
|
| 86 | - $this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | - } |
|
| 88 | - } |
|
| 62 | +private function updateContainer(Config $xConfig): void |
|
| 63 | +{ |
|
| 64 | +$aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | +foreach($aOptions as $xKey => $xValue) |
|
| 66 | +{ |
|
| 67 | +// The key is the class name. It must be a string. |
|
| 68 | +$this->di->set((string)$xKey, $xValue); |
|
| 69 | +} |
|
| 70 | +$aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | +foreach($aOptions as $xKey => $xValue) |
|
| 72 | +{ |
|
| 73 | +// The key is the class name. It must be a string. |
|
| 74 | +$this->di->val((string)$xKey, $xValue); |
|
| 75 | +} |
|
| 76 | +$aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | +foreach($aOptions as $xValue) |
|
| 78 | +{ |
|
| 79 | +// The key is the class name. It must be a string. |
|
| 80 | +$this->di->auto((string)$xValue); |
|
| 81 | +} |
|
| 82 | +$aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | +foreach($aOptions as $xKey => $xValue) |
|
| 84 | +{ |
|
| 85 | +// The key is the class name. It must be a string. |
|
| 86 | +$this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | +} |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register callables from a section of the config |
| 92 | 92 | * |
| 93 | 93 | * @param array $aOptions The content of the config section |
@@ -96,41 +96,41 @@ discard block |
||
| 96 | 96 | * @return void |
| 97 | 97 | * @throws SetupException |
| 98 | 98 | */ |
| 99 | - private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | - { |
|
| 101 | - foreach($aOptions as $xKey => $xValue) |
|
| 102 | - { |
|
| 103 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | - { |
|
| 105 | - // Register a function without options |
|
| 106 | - $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 99 | +private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | +{ |
|
| 101 | +foreach($aOptions as $xKey => $xValue) |
|
| 102 | +{ |
|
| 103 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | +{ |
|
| 105 | + // Register a function without options |
|
| 106 | + $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | + continue; |
|
| 108 | +} |
|
| 109 | 109 | |
| 110 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | - { |
|
| 112 | - // Register a function with options |
|
| 113 | - $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | +if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | +{ |
|
| 112 | + // Register a function with options |
|
| 113 | + $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | +} |
|
| 115 | +} |
|
| 116 | +} |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | +/** |
|
| 119 | 119 | * Register exceptions handlers |
| 120 | 120 | * |
| 121 | 121 | * @param Config $xConfig |
| 122 | 122 | * |
| 123 | 123 | * @return void |
| 124 | 124 | */ |
| 125 | - private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | - { |
|
| 127 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | - { |
|
| 129 | - $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | - } |
|
| 131 | - } |
|
| 125 | +private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | +{ |
|
| 127 | +foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | +{ |
|
| 129 | +$this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | +} |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get a callable list from config |
| 135 | 135 | * |
| 136 | 136 | * @param Config $xConfig |
@@ -140,36 +140,36 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | - private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | - string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | - { |
|
| 146 | - // The callable (directory path, class or function name) can be used as the |
|
| 147 | - // key of the array item, a string as the value of an entry without a key, |
|
| 148 | - // or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | - $aCallables = []; |
|
| 150 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | - { |
|
| 152 | - if(is_string($xKey)) |
|
| 153 | - { |
|
| 154 | - $aCallables[$xKey] = $xValue; |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - if(is_string($xValue)) |
|
| 158 | - { |
|
| 159 | - $aCallables[] = $xValue; |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 143 | +private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | +string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | +{ |
|
| 146 | +// The callable (directory path, class or function name) can be used as the |
|
| 147 | +// key of the array item, a string as the value of an entry without a key, |
|
| 148 | +// or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | +$aCallables = []; |
|
| 150 | +foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | +{ |
|
| 152 | +if(is_string($xKey)) |
|
| 153 | +{ |
|
| 154 | + $aCallables[$xKey] = $xValue; |
|
| 155 | + continue; |
|
| 156 | +} |
|
| 157 | +if(is_string($xValue)) |
|
| 158 | +{ |
|
| 159 | + $aCallables[] = $xValue; |
|
| 160 | + continue; |
|
| 161 | +} |
|
| 162 | 162 | |
| 163 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | - { |
|
| 165 | - $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | - } |
|
| 167 | - // Invalid values are ignored. |
|
| 168 | - } |
|
| 169 | - $this->registerCallables($aCallables, $sCallableType); |
|
| 170 | - } |
|
| 163 | +if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | +{ |
|
| 165 | + $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | +} |
|
| 167 | +// Invalid values are ignored. |
|
| 168 | +} |
|
| 169 | +$this->registerCallables($aCallables, $sCallableType); |
|
| 170 | +} |
|
| 171 | 171 | |
| 172 | - /** |
|
| 172 | +/** |
|
| 173 | 173 | * Read and set Jaxon options from a JSON config file |
| 174 | 174 | * |
| 175 | 175 | * @param Config $xConfig The config options |
@@ -177,33 +177,33 @@ discard block |
||
| 177 | 177 | * @return void |
| 178 | 178 | * @throws SetupException |
| 179 | 179 | */ |
| 180 | - private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | - { |
|
| 182 | - // Set the config for the registered callables. |
|
| 183 | - $this->xRegistry->setPackageConfig($xConfig); |
|
| 180 | +private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | +{ |
|
| 182 | +// Set the config for the registered callables. |
|
| 183 | +$this->xRegistry->setPackageConfig($xConfig); |
|
| 184 | 184 | |
| 185 | - // Register functions, classes and directories |
|
| 186 | - $this->registerCallablesFromConfig($xConfig, |
|
| 187 | - 'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | - $this->registerCallablesFromConfig($xConfig, |
|
| 189 | - 'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | - $this->registerCallablesFromConfig($xConfig, |
|
| 191 | - 'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 185 | +// Register functions, classes and directories |
|
| 186 | +$this->registerCallablesFromConfig($xConfig, |
|
| 187 | +'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | +$this->registerCallablesFromConfig($xConfig, |
|
| 189 | +'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | +$this->registerCallablesFromConfig($xConfig, |
|
| 191 | +'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 192 | 192 | |
| 193 | - // Unset the current config. |
|
| 194 | - $this->xRegistry->unsetPackageConfig(); |
|
| 193 | +// Unset the current config. |
|
| 194 | +$this->xRegistry->unsetPackageConfig(); |
|
| 195 | 195 | |
| 196 | - // Register the view namespaces |
|
| 197 | - // Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | - // the user defined view namespaces. That's why it is needed here. |
|
| 199 | - $this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | - // Save items in the DI container |
|
| 201 | - $this->updateContainer($xConfig); |
|
| 202 | - // Register the exception handlers |
|
| 203 | - $this->registerExceptionHandlers($xConfig); |
|
| 204 | - } |
|
| 196 | +// Register the view namespaces |
|
| 197 | +// Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | +// the user defined view namespaces. That's why it is needed here. |
|
| 199 | +$this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | +// Save items in the DI container |
|
| 201 | +$this->updateContainer($xConfig); |
|
| 202 | +// Register the exception handlers |
|
| 203 | +$this->registerExceptionHandlers($xConfig); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Get the options provided by the package library |
| 208 | 208 | * |
| 209 | 209 | * @param class-string $sClassName The package class |
@@ -211,27 +211,27 @@ discard block |
||
| 211 | 211 | * @return Config |
| 212 | 212 | * @throws SetupException |
| 213 | 213 | */ |
| 214 | - private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | - { |
|
| 216 | - // $this->aPackages contains packages config file paths. |
|
| 217 | - $aLibOptions = $sClassName::config(); |
|
| 218 | - if(is_string($aLibOptions)) |
|
| 219 | - { |
|
| 220 | - // A string is supposed to be the path to a config file. |
|
| 221 | - $aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | - } |
|
| 223 | - elseif(!is_array($aLibOptions)) |
|
| 224 | - { |
|
| 225 | - // Otherwise, anything else than an array is not accepted. |
|
| 226 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | - throw new SetupException($sMessage); |
|
| 228 | - } |
|
| 229 | - // Add the package name to the config |
|
| 230 | - $aLibOptions['package'] = $sClassName; |
|
| 231 | - return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | - } |
|
| 214 | +private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | +{ |
|
| 216 | +// $this->aPackages contains packages config file paths. |
|
| 217 | +$aLibOptions = $sClassName::config(); |
|
| 218 | +if(is_string($aLibOptions)) |
|
| 219 | +{ |
|
| 220 | +// A string is supposed to be the path to a config file. |
|
| 221 | +$aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | +} |
|
| 223 | +elseif(!is_array($aLibOptions)) |
|
| 224 | +{ |
|
| 225 | +// Otherwise, anything else than an array is not accepted. |
|
| 226 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | +throw new SetupException($sMessage); |
|
| 228 | +} |
|
| 229 | +// Add the package name to the config |
|
| 230 | +$aLibOptions['package'] = $sClassName; |
|
| 231 | +return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 234 | +/** |
|
| 235 | 235 | * Register a package |
| 236 | 236 | * |
| 237 | 237 | * @param class-string $sClassName The package class |
@@ -240,27 +240,27 @@ discard block |
||
| 240 | 240 | * @return void |
| 241 | 241 | * @throws SetupException |
| 242 | 242 | */ |
| 243 | - public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | - { |
|
| 245 | - $sClassName = trim($sClassName, '\\ '); |
|
| 246 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | - { |
|
| 248 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | - throw new SetupException($sMessage); |
|
| 250 | - } |
|
| 243 | +public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | +{ |
|
| 245 | +$sClassName = trim($sClassName, '\\ '); |
|
| 246 | +if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | +{ |
|
| 248 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | +throw new SetupException($sMessage); |
|
| 250 | +} |
|
| 251 | 251 | |
| 252 | - // Register the declarations in the package config. |
|
| 253 | - $xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 252 | +// Register the declarations in the package config. |
|
| 253 | +$xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 255 | 255 | |
| 256 | - // Register the package and its options in the DI |
|
| 257 | - $this->di->registerPackage($sClassName, $aUserOptions); |
|
| 256 | +// Register the package and its options in the DI |
|
| 257 | +$this->di->registerPackage($sClassName, $aUserOptions); |
|
| 258 | 258 | |
| 259 | - // Register the package as a code generator. |
|
| 260 | - $this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | - } |
|
| 259 | +// Register the package as a code generator. |
|
| 260 | +$this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | +} |
|
| 262 | 262 | |
| 263 | - /** |
|
| 263 | +/** |
|
| 264 | 264 | * Get a package instance |
| 265 | 265 | * |
| 266 | 266 | * @template T of AbstractPackage |
@@ -268,42 +268,42 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return T|null |
| 270 | 270 | */ |
| 271 | - public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | - { |
|
| 273 | - $sClassName = trim($sClassName, '\\ '); |
|
| 274 | - return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | - } |
|
| 271 | +public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | +{ |
|
| 273 | +$sClassName = trim($sClassName, '\\ '); |
|
| 274 | +return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | +} |
|
| 276 | 276 | |
| 277 | - /** |
|
| 277 | +/** |
|
| 278 | 278 | * Read and set Jaxon options from the config |
| 279 | 279 | * |
| 280 | 280 | * @return void |
| 281 | 281 | * @throws SetupException |
| 282 | 282 | */ |
| 283 | - public function registerFromConfig(): void |
|
| 284 | - { |
|
| 285 | - $xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 283 | +public function registerFromConfig(): void |
|
| 284 | +{ |
|
| 285 | +$xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 287 | 287 | |
| 288 | - // Register packages |
|
| 289 | - $aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | - { |
|
| 292 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | - { |
|
| 294 | - // Register a package without options |
|
| 295 | - $sClassName = $xValue; |
|
| 296 | - $this->registerPackage($sClassName); |
|
| 297 | - continue; |
|
| 298 | - } |
|
| 288 | +// Register packages |
|
| 289 | +$aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | +foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | +{ |
|
| 292 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | +{ |
|
| 294 | + // Register a package without options |
|
| 295 | + $sClassName = $xValue; |
|
| 296 | + $this->registerPackage($sClassName); |
|
| 297 | + continue; |
|
| 298 | +} |
|
| 299 | 299 | |
| 300 | - if(is_string($xKey) && is_array($xValue)) |
|
| 301 | - { |
|
| 302 | - // Register a package with options |
|
| 303 | - $sClassName = $xKey; |
|
| 304 | - $aPkgOptions = $xValue; |
|
| 305 | - $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 300 | +if(is_string($xKey) && is_array($xValue)) |
|
| 301 | +{ |
|
| 302 | + // Register a package with options |
|
| 303 | + $sClassName = $xKey; |
|
| 304 | + $aPkgOptions = $xValue; |
|
| 305 | + $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | +} |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | } |