@@ -36,154 +36,154 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | trait PluginTrait |
| 38 | 38 | { |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * Register the values into the container |
| 41 | 41 | * |
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | - private function registerPlugins(): void |
|
| 45 | - { |
|
| 46 | - // Plugin manager |
|
| 47 | - $this->set(PluginManager::class, function($di) { |
|
| 48 | - $xPluginManager = new PluginManager($di->g(Container::class), |
|
| 49 | - $di->g(CodeGenerator::class), $di->g(Translator::class)); |
|
| 50 | - // Register the Jaxon request and response plugins |
|
| 51 | - $xPluginManager->registerPlugins(); |
|
| 52 | - return $xPluginManager; |
|
| 53 | - }); |
|
| 54 | - // Package manager |
|
| 55 | - $this->set(PackageManager::class, function($di) { |
|
| 56 | - return new PackageManager($di->g(Container::class), $di->g(Translator::class), |
|
| 57 | - $di->g(PluginManager::class), $di->g(ConfigManager::class), |
|
| 58 | - $di->g(ViewRenderer::class), $di->g(CallbackManager::class), |
|
| 59 | - $di->g(ComponentRegistry::class)); |
|
| 60 | - }); |
|
| 61 | - // Code Generation |
|
| 62 | - $this->set(MinifierInterface::class, function() { |
|
| 63 | - return new class extends FileMinifier implements MinifierInterface |
|
| 64 | - {}; |
|
| 65 | - }); |
|
| 66 | - $this->set(AssetManager::class, function($di) { |
|
| 67 | - return new AssetManager($di->g(ConfigManager::class), |
|
| 68 | - $di->g(StorageManager::class), $di->g(MinifierInterface::class)); |
|
| 69 | - }); |
|
| 70 | - $this->set(CodeGenerator::class, function($di) { |
|
| 71 | - return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class), |
|
| 72 | - $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 73 | - }); |
|
| 74 | - $this->set(ConfigScriptGenerator::class, function($di) { |
|
| 75 | - return new ConfigScriptGenerator($di->g(ParameterReader::class), |
|
| 76 | - $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 77 | - }); |
|
| 78 | - $this->set(ReadyScriptGenerator::class, function($di) { |
|
| 79 | - return new ReadyScriptGenerator(); |
|
| 80 | - }); |
|
| 81 | - |
|
| 82 | - // Script response plugin |
|
| 83 | - $this->set(ScriptPlugin::class, function($di) { |
|
| 84 | - return new ScriptPlugin($di->g(CallFactory::class)); |
|
| 85 | - }); |
|
| 86 | - // Databag response plugin. Get the databag contents from the HTTP request parameters. |
|
| 87 | - $this->set(DatabagPlugin::class, function($di) { |
|
| 88 | - return new DatabagPlugin(fn() => $di->getRequest()->getAttribute('jxnbags', [])); |
|
| 89 | - }); |
|
| 90 | - // Dialog response plugin |
|
| 91 | - $this->set(DialogPlugin::class, function($di) { |
|
| 92 | - return new DialogPlugin($di->g(DialogCommand::class)); |
|
| 93 | - }); |
|
| 94 | - // Paginator response plugin |
|
| 95 | - $this->set(PaginatorPlugin::class, function($di) { |
|
| 96 | - return new PaginatorPlugin($di->g(RendererInterface::class)); |
|
| 97 | - }); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 44 | +private function registerPlugins(): void |
|
| 45 | +{ |
|
| 46 | +// Plugin manager |
|
| 47 | +$this->set(PluginManager::class, function($di) { |
|
| 48 | +$xPluginManager = new PluginManager($di->g(Container::class), |
|
| 49 | + $di->g(CodeGenerator::class), $di->g(Translator::class)); |
|
| 50 | +// Register the Jaxon request and response plugins |
|
| 51 | +$xPluginManager->registerPlugins(); |
|
| 52 | +return $xPluginManager; |
|
| 53 | +}); |
|
| 54 | +// Package manager |
|
| 55 | +$this->set(PackageManager::class, function($di) { |
|
| 56 | +return new PackageManager($di->g(Container::class), $di->g(Translator::class), |
|
| 57 | + $di->g(PluginManager::class), $di->g(ConfigManager::class), |
|
| 58 | + $di->g(ViewRenderer::class), $di->g(CallbackManager::class), |
|
| 59 | + $di->g(ComponentRegistry::class)); |
|
| 60 | +}); |
|
| 61 | +// Code Generation |
|
| 62 | +$this->set(MinifierInterface::class, function() { |
|
| 63 | +return new class extends FileMinifier implements MinifierInterface |
|
| 64 | +{}; |
|
| 65 | +}); |
|
| 66 | +$this->set(AssetManager::class, function($di) { |
|
| 67 | +return new AssetManager($di->g(ConfigManager::class), |
|
| 68 | + $di->g(StorageManager::class), $di->g(MinifierInterface::class)); |
|
| 69 | +}); |
|
| 70 | +$this->set(CodeGenerator::class, function($di) { |
|
| 71 | +return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class), |
|
| 72 | + $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 73 | +}); |
|
| 74 | +$this->set(ConfigScriptGenerator::class, function($di) { |
|
| 75 | +return new ConfigScriptGenerator($di->g(ParameterReader::class), |
|
| 76 | + $di->g(TemplateEngine::class), $di->g(ConfigManager::class)); |
|
| 77 | +}); |
|
| 78 | +$this->set(ReadyScriptGenerator::class, function($di) { |
|
| 79 | +return new ReadyScriptGenerator(); |
|
| 80 | +}); |
|
| 81 | + |
|
| 82 | +// Script response plugin |
|
| 83 | +$this->set(ScriptPlugin::class, function($di) { |
|
| 84 | +return new ScriptPlugin($di->g(CallFactory::class)); |
|
| 85 | +}); |
|
| 86 | +// Databag response plugin. Get the databag contents from the HTTP request parameters. |
|
| 87 | +$this->set(DatabagPlugin::class, function($di) { |
|
| 88 | +return new DatabagPlugin(fn() => $di->getRequest()->getAttribute('jxnbags', [])); |
|
| 89 | +}); |
|
| 90 | +// Dialog response plugin |
|
| 91 | +$this->set(DialogPlugin::class, function($di) { |
|
| 92 | +return new DialogPlugin($di->g(DialogCommand::class)); |
|
| 93 | +}); |
|
| 94 | +// Paginator response plugin |
|
| 95 | +$this->set(PaginatorPlugin::class, function($di) { |
|
| 96 | +return new PaginatorPlugin($di->g(RendererInterface::class)); |
|
| 97 | +}); |
|
| 98 | +} |
|
| 99 | + |
|
| 100 | +/** |
|
| 101 | 101 | * Get the plugin manager |
| 102 | 102 | * |
| 103 | 103 | * @return PluginManager |
| 104 | 104 | */ |
| 105 | - public function getPluginManager(): PluginManager |
|
| 106 | - { |
|
| 107 | - return $this->g(PluginManager::class); |
|
| 108 | - } |
|
| 105 | +public function getPluginManager(): PluginManager |
|
| 106 | +{ |
|
| 107 | +return $this->g(PluginManager::class); |
|
| 108 | +} |
|
| 109 | 109 | |
| 110 | - /** |
|
| 110 | +/** |
|
| 111 | 111 | * Get the package manager |
| 112 | 112 | * |
| 113 | 113 | * @return PackageManager |
| 114 | 114 | */ |
| 115 | - public function getPackageManager(): PackageManager |
|
| 116 | - { |
|
| 117 | - return $this->g(PackageManager::class); |
|
| 118 | - } |
|
| 115 | +public function getPackageManager(): PackageManager |
|
| 116 | +{ |
|
| 117 | +return $this->g(PackageManager::class); |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - /** |
|
| 120 | +/** |
|
| 121 | 121 | * Get the code generator |
| 122 | 122 | * |
| 123 | 123 | * @return CodeGenerator |
| 124 | 124 | */ |
| 125 | - public function getCodeGenerator(): CodeGenerator |
|
| 126 | - { |
|
| 127 | - return $this->g(CodeGenerator::class); |
|
| 128 | - } |
|
| 125 | +public function getCodeGenerator(): CodeGenerator |
|
| 126 | +{ |
|
| 127 | +return $this->g(CodeGenerator::class); |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - /** |
|
| 130 | +/** |
|
| 131 | 131 | * Get the storage manager |
| 132 | 132 | * |
| 133 | 133 | * @return AssetManager |
| 134 | 134 | */ |
| 135 | - public function getAssetManager(): AssetManager |
|
| 136 | - { |
|
| 137 | - return $this->g(AssetManager::class); |
|
| 138 | - } |
|
| 135 | +public function getAssetManager(): AssetManager |
|
| 136 | +{ |
|
| 137 | +return $this->g(AssetManager::class); |
|
| 138 | +} |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | +/** |
|
| 141 | 141 | * Get the jQuery plugin |
| 142 | 142 | * |
| 143 | 143 | * @return ScriptPlugin |
| 144 | 144 | */ |
| 145 | - public function getScriptPlugin(): ScriptPlugin |
|
| 146 | - { |
|
| 147 | - return $this->g(ScriptPlugin::class); |
|
| 148 | - } |
|
| 145 | +public function getScriptPlugin(): ScriptPlugin |
|
| 146 | +{ |
|
| 147 | +return $this->g(ScriptPlugin::class); |
|
| 148 | +} |
|
| 149 | 149 | |
| 150 | - /** |
|
| 150 | +/** |
|
| 151 | 151 | * Get the dialog plugin |
| 152 | 152 | * |
| 153 | 153 | * @return DialogPlugin |
| 154 | 154 | */ |
| 155 | - public function getDialogPlugin(): DialogPlugin |
|
| 156 | - { |
|
| 157 | - return $this->g(DialogPlugin::class); |
|
| 158 | - } |
|
| 155 | +public function getDialogPlugin(): DialogPlugin |
|
| 156 | +{ |
|
| 157 | +return $this->g(DialogPlugin::class); |
|
| 158 | +} |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * @param class-string $sClassName The package class name |
| 162 | 162 | * |
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | - private function getPackageConfigKey(string $sClassName): string |
|
| 166 | - { |
|
| 167 | - return $sClassName . '_PackageConfig'; |
|
| 168 | - } |
|
| 165 | +private function getPackageConfigKey(string $sClassName): string |
|
| 166 | +{ |
|
| 167 | +return $sClassName . '_PackageConfig'; |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * @param class-string $sClassName The package class name |
| 172 | 172 | * @param-closure-this AbstractPackage $cSetter |
| 173 | 173 | * |
| 174 | 174 | * @return void |
| 175 | 175 | */ |
| 176 | - private function extendPackage(string $sClassName, Closure $cSetter): void |
|
| 177 | - { |
|
| 178 | - // Initialize the package instance. |
|
| 179 | - $this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) { |
|
| 180 | - // Allow the setter to access protected attributes. |
|
| 181 | - call_user_func($cSetter->bindTo($xPackage, $xPackage)); |
|
| 182 | - return $xPackage; |
|
| 183 | - }); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 176 | +private function extendPackage(string $sClassName, Closure $cSetter): void |
|
| 177 | +{ |
|
| 178 | +// Initialize the package instance. |
|
| 179 | +$this->xLibContainer->extend($sClassName, function($xPackage) use($cSetter) { |
|
| 180 | +// Allow the setter to access protected attributes. |
|
| 181 | +call_user_func($cSetter->bindTo($xPackage, $xPackage)); |
|
| 182 | +return $xPackage; |
|
| 183 | +}); |
|
| 184 | +} |
|
| 185 | + |
|
| 186 | +/** |
|
| 187 | 187 | * Register a package |
| 188 | 188 | * |
| 189 | 189 | * @param class-string $sClassName The package class name |
@@ -192,45 +192,45 @@ discard block |
||
| 192 | 192 | * @return void |
| 193 | 193 | * @throws SetupException |
| 194 | 194 | */ |
| 195 | - public function registerPackage(string $sClassName, array $aUserOptions): void |
|
| 196 | - { |
|
| 197 | - // Register the user class, but only if the user didn't already. |
|
| 198 | - if(!$this->h($sClassName)) |
|
| 199 | - { |
|
| 200 | - $this->set($sClassName, fn() => $this->make($sClassName)); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // Save the package config in the container. |
|
| 204 | - $sConfigKey = $this->getPackageConfigKey($sClassName); |
|
| 205 | - $this->set($sConfigKey, function($di) use($aUserOptions) { |
|
| 206 | - $xOptionsProvider = $aUserOptions['provider'] ?? null; |
|
| 207 | - // The user can provide a callable that returns the package options. |
|
| 208 | - if(is_callable($xOptionsProvider)) |
|
| 209 | - { |
|
| 210 | - $aUserOptions = $xOptionsProvider($aUserOptions); |
|
| 211 | - } |
|
| 212 | - return $di->g(ConfigManager::class)->newConfig($aUserOptions); |
|
| 213 | - }); |
|
| 214 | - |
|
| 215 | - // Initialize the package instance. |
|
| 216 | - $di = $this; |
|
| 217 | - $this->extendPackage($sClassName, function() use($di, $sConfigKey) { |
|
| 218 | - // $this here refers to the AbstractPackage instance. |
|
| 219 | - $this->xPkgConfig = $di->g($sConfigKey); |
|
| 220 | - $this->xRenderer = $di->g(ViewRenderer::class); |
|
| 221 | - $this->init(); |
|
| 222 | - }); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 195 | +public function registerPackage(string $sClassName, array $aUserOptions): void |
|
| 196 | +{ |
|
| 197 | +// Register the user class, but only if the user didn't already. |
|
| 198 | +if(!$this->h($sClassName)) |
|
| 199 | +{ |
|
| 200 | +$this->set($sClassName, fn() => $this->make($sClassName)); |
|
| 201 | +} |
|
| 202 | + |
|
| 203 | +// Save the package config in the container. |
|
| 204 | +$sConfigKey = $this->getPackageConfigKey($sClassName); |
|
| 205 | +$this->set($sConfigKey, function($di) use($aUserOptions) { |
|
| 206 | +$xOptionsProvider = $aUserOptions['provider'] ?? null; |
|
| 207 | +// The user can provide a callable that returns the package options. |
|
| 208 | +if(is_callable($xOptionsProvider)) |
|
| 209 | +{ |
|
| 210 | + $aUserOptions = $xOptionsProvider($aUserOptions); |
|
| 211 | +} |
|
| 212 | +return $di->g(ConfigManager::class)->newConfig($aUserOptions); |
|
| 213 | +}); |
|
| 214 | + |
|
| 215 | +// Initialize the package instance. |
|
| 216 | +$di = $this; |
|
| 217 | +$this->extendPackage($sClassName, function() use($di, $sConfigKey) { |
|
| 218 | +// $this here refers to the AbstractPackage instance. |
|
| 219 | +$this->xPkgConfig = $di->g($sConfigKey); |
|
| 220 | +$this->xRenderer = $di->g(ViewRenderer::class); |
|
| 221 | +$this->init(); |
|
| 222 | +}); |
|
| 223 | +} |
|
| 224 | + |
|
| 225 | +/** |
|
| 226 | 226 | * Get the config of a package |
| 227 | 227 | * |
| 228 | 228 | * @param class-string $sClassName The package class name |
| 229 | 229 | * |
| 230 | 230 | * @return Config |
| 231 | 231 | */ |
| 232 | - public function getPackageConfig(string $sClassName): Config |
|
| 233 | - { |
|
| 234 | - return $this->g($this->getPackageConfigKey($sClassName)); |
|
| 235 | - } |
|
| 232 | +public function getPackageConfig(string $sClassName): Config |
|
| 233 | +{ |
|
| 234 | +return $this->g($this->getPackageConfigKey($sClassName)); |
|
| 235 | +} |
|
| 236 | 236 | } |
@@ -18,104 +18,104 @@ |
||
| 18 | 18 | |
| 19 | 19 | trait AppTrait |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * @var string |
| 23 | 23 | */ |
| 24 | - private $sJsLibVersion = 'jaxon_javascript_library_version'; |
|
| 24 | +private $sJsLibVersion = 'jaxon_javascript_library_version'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * Register the values into the container |
| 28 | 28 | * |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - private function registerApp(): void |
|
| 32 | - { |
|
| 33 | - // Config Manager |
|
| 34 | - $this->set(ConfigEventManager::class, function($di) { |
|
| 35 | - return new ConfigEventManager($di->g(Container::class)); |
|
| 36 | - }); |
|
| 37 | - $this->set(ConfigManager::class, function($di) { |
|
| 38 | - $aDefaultOptions = require(dirname(__DIR__, 3) . '/config/lib.php'); |
|
| 39 | - return new ConfigManager($aDefaultOptions, $di->g(Translator::class), |
|
| 40 | - $di->g(ConfigReader::class), $di->g(ConfigSetter::class), |
|
| 41 | - $di->g(ConfigEventManager::class)); |
|
| 42 | - }); |
|
| 31 | +private function registerApp(): void |
|
| 32 | +{ |
|
| 33 | +// Config Manager |
|
| 34 | +$this->set(ConfigEventManager::class, function($di) { |
|
| 35 | +return new ConfigEventManager($di->g(Container::class)); |
|
| 36 | +}); |
|
| 37 | +$this->set(ConfigManager::class, function($di) { |
|
| 38 | +$aDefaultOptions = require(dirname(__DIR__, 3) . '/config/lib.php'); |
|
| 39 | +return new ConfigManager($aDefaultOptions, $di->g(Translator::class), |
|
| 40 | + $di->g(ConfigReader::class), $di->g(ConfigSetter::class), |
|
| 41 | + $di->g(ConfigEventManager::class)); |
|
| 42 | +}); |
|
| 43 | 43 | |
| 44 | - // Jaxon App |
|
| 45 | - $this->set(AppInterface::class, fn() => new App()); |
|
| 46 | - // Jaxon App bootstrap |
|
| 47 | - $this->set(Bootstrap::class, function($di) { |
|
| 48 | - return new Bootstrap($di->g(ConfigManager::class), |
|
| 49 | - $di->g(PackageManager::class), $di->g(CallbackManager::class)); |
|
| 50 | - }); |
|
| 51 | - // The javascript library version |
|
| 52 | - $this->set($this->sJsLibVersion, function($di) { |
|
| 53 | - $xRequest = $di->getRequest(); |
|
| 54 | - $aParams = $xRequest->getMethod() === 'POST' ? |
|
| 55 | - $xRequest->getParsedBody() : $xRequest->getQueryParams(); |
|
| 56 | - return $aParams['jxnv'] ?? '3.3.0'; |
|
| 57 | - }); |
|
| 58 | - } |
|
| 44 | +// Jaxon App |
|
| 45 | +$this->set(AppInterface::class, fn() => new App()); |
|
| 46 | +// Jaxon App bootstrap |
|
| 47 | +$this->set(Bootstrap::class, function($di) { |
|
| 48 | +return new Bootstrap($di->g(ConfigManager::class), |
|
| 49 | + $di->g(PackageManager::class), $di->g(CallbackManager::class)); |
|
| 50 | +}); |
|
| 51 | +// The javascript library version |
|
| 52 | +$this->set($this->sJsLibVersion, function($di) { |
|
| 53 | +$xRequest = $di->getRequest(); |
|
| 54 | +$aParams = $xRequest->getMethod() === 'POST' ? |
|
| 55 | + $xRequest->getParsedBody() : $xRequest->getQueryParams(); |
|
| 56 | +return $aParams['jxnv'] ?? '3.3.0'; |
|
| 57 | +}); |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * Register the event handlers |
| 62 | 62 | * |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | - private function setEventHandlers(): void |
|
| 66 | - { |
|
| 67 | - $xEventManager = $this->g(ConfigEventManager::class); |
|
| 68 | - $xEventManager->addLibConfigListener(Translator::class); |
|
| 69 | - } |
|
| 65 | +private function setEventHandlers(): void |
|
| 66 | +{ |
|
| 67 | +$xEventManager = $this->g(ConfigEventManager::class); |
|
| 68 | +$xEventManager->addLibConfigListener(Translator::class); |
|
| 69 | +} |
|
| 70 | 70 | |
| 71 | - /** |
|
| 71 | +/** |
|
| 72 | 72 | * Get the App instance |
| 73 | 73 | * |
| 74 | 74 | * @return AppInterface |
| 75 | 75 | */ |
| 76 | - public function getApp(): AppInterface |
|
| 77 | - { |
|
| 78 | - return $this->g(AppInterface::class); |
|
| 79 | - } |
|
| 76 | +public function getApp(): AppInterface |
|
| 77 | +{ |
|
| 78 | +return $this->g(AppInterface::class); |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * Get the App bootstrap |
| 83 | 83 | * |
| 84 | 84 | * @return Bootstrap |
| 85 | 85 | */ |
| 86 | - public function getBootstrap(): Bootstrap |
|
| 87 | - { |
|
| 88 | - return $this->g(Bootstrap::class); |
|
| 89 | - } |
|
| 86 | +public function getBootstrap(): Bootstrap |
|
| 87 | +{ |
|
| 88 | +return $this->g(Bootstrap::class); |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * Get the config manager |
| 93 | 93 | * |
| 94 | 94 | * @return ConfigManager |
| 95 | 95 | */ |
| 96 | - public function config(): ConfigManager |
|
| 97 | - { |
|
| 98 | - return $this->g(ConfigManager::class); |
|
| 99 | - } |
|
| 96 | +public function config(): ConfigManager |
|
| 97 | +{ |
|
| 98 | +return $this->g(ConfigManager::class); |
|
| 99 | +} |
|
| 100 | 100 | |
| 101 | - /** |
|
| 101 | +/** |
|
| 102 | 102 | * Get the javascript library version |
| 103 | 103 | * |
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | - public function getJsLibVersion(): string |
|
| 107 | - { |
|
| 108 | - return $this->g($this->sJsLibVersion); |
|
| 109 | - } |
|
| 106 | +public function getJsLibVersion(): string |
|
| 107 | +{ |
|
| 108 | +return $this->g($this->sJsLibVersion); |
|
| 109 | +} |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | +/** |
|
| 112 | 112 | * Get the default request URI |
| 113 | 113 | * |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public function getRequestUri(): string |
|
| 117 | - { |
|
| 118 | - return $this->config()->getOption('core.request.uri', |
|
| 119 | - $this->getParameterReader()->uri()); |
|
| 120 | - } |
|
| 116 | +public function getRequestUri(): string |
|
| 117 | +{ |
|
| 118 | +return $this->config()->getOption('core.request.uri', |
|
| 119 | +$this->getParameterReader()->uri()); |
|
| 120 | +} |
|
| 121 | 121 | } |
@@ -29,144 +29,144 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class Container implements ContainerInterface |
| 31 | 31 | { |
| 32 | - use Traits\AppTrait; |
|
| 33 | - use Traits\PsrTrait; |
|
| 34 | - use Traits\RequestTrait; |
|
| 35 | - use Traits\ResponseTrait; |
|
| 36 | - use Traits\PluginTrait; |
|
| 37 | - use Traits\CallableTrait; |
|
| 38 | - use Traits\ViewTrait; |
|
| 39 | - use Traits\UtilTrait; |
|
| 40 | - use Traits\MetadataTrait; |
|
| 41 | - use Traits\DiAutoTrait; |
|
| 32 | +use Traits\AppTrait; |
|
| 33 | +use Traits\PsrTrait; |
|
| 34 | +use Traits\RequestTrait; |
|
| 35 | +use Traits\ResponseTrait; |
|
| 36 | +use Traits\PluginTrait; |
|
| 37 | +use Traits\CallableTrait; |
|
| 38 | +use Traits\ViewTrait; |
|
| 39 | +use Traits\UtilTrait; |
|
| 40 | +use Traits\MetadataTrait; |
|
| 41 | +use Traits\DiAutoTrait; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The library Dependency Injection Container |
| 45 | 45 | * |
| 46 | 46 | * @var PimpleContainer |
| 47 | 47 | */ |
| 48 | - private $xLibContainer; |
|
| 48 | +private $xLibContainer; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * The application or framework Dependency Injection Container |
| 52 | 52 | * |
| 53 | 53 | * @var ContainerInterface |
| 54 | 54 | */ |
| 55 | - private $xAppContainer = null; |
|
| 55 | +private $xAppContainer = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * The class constructor |
| 59 | 59 | */ |
| 60 | - public function __construct() |
|
| 61 | - { |
|
| 62 | - $this->xLibContainer = new PimpleContainer(); |
|
| 60 | +public function __construct() |
|
| 61 | +{ |
|
| 62 | +$this->xLibContainer = new PimpleContainer(); |
|
| 63 | 63 | |
| 64 | - $this->val(Container::class, $this); |
|
| 64 | +$this->val(Container::class, $this); |
|
| 65 | 65 | |
| 66 | - // Register the null logger by default |
|
| 67 | - $this->setLogger(new NullLogger()); |
|
| 66 | +// Register the null logger by default |
|
| 67 | +$this->setLogger(new NullLogger()); |
|
| 68 | 68 | |
| 69 | - $sBaseDir = dirname(__DIR__, 2); |
|
| 70 | - // Template directory |
|
| 71 | - $this->val('jaxon.core.dir.template', "$sBaseDir/templates"); |
|
| 69 | +$sBaseDir = dirname(__DIR__, 2); |
|
| 70 | +// Template directory |
|
| 71 | +$this->val('jaxon.core.dir.template', "$sBaseDir/templates"); |
|
| 72 | 72 | |
| 73 | - // Translation directory |
|
| 74 | - $this->val('jaxon.core.dir.translation', "$sBaseDir/translations"); |
|
| 73 | +// Translation directory |
|
| 74 | +$this->val('jaxon.core.dir.translation', "$sBaseDir/translations"); |
|
| 75 | 75 | |
| 76 | - $this->registerAll(); |
|
| 77 | - $this->setEventHandlers(); |
|
| 78 | - } |
|
| 76 | +$this->registerAll(); |
|
| 77 | +$this->setEventHandlers(); |
|
| 78 | +} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * The container for parameters |
| 82 | 82 | * |
| 83 | 83 | * @return Container |
| 84 | 84 | */ |
| 85 | - protected function cn(): Container |
|
| 86 | - { |
|
| 87 | - return $this; |
|
| 88 | - } |
|
| 85 | +protected function cn(): Container |
|
| 86 | +{ |
|
| 87 | +return $this; |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register the values into the container |
| 92 | 92 | * |
| 93 | 93 | * @return void |
| 94 | 94 | */ |
| 95 | - private function registerAll() |
|
| 96 | - { |
|
| 97 | - $this->registerApp(); |
|
| 98 | - $this->registerPsr(); |
|
| 99 | - $this->registerRequests(); |
|
| 100 | - $this->registerResponses(); |
|
| 101 | - $this->registerPlugins(); |
|
| 102 | - $this->registerCallables(); |
|
| 103 | - $this->registerViews(); |
|
| 104 | - $this->registerUtils(); |
|
| 105 | - $this->registerMetadataReader(); |
|
| 106 | - } |
|
| 95 | +private function registerAll() |
|
| 96 | +{ |
|
| 97 | +$this->registerApp(); |
|
| 98 | +$this->registerPsr(); |
|
| 99 | +$this->registerRequests(); |
|
| 100 | +$this->registerResponses(); |
|
| 101 | +$this->registerPlugins(); |
|
| 102 | +$this->registerCallables(); |
|
| 103 | +$this->registerViews(); |
|
| 104 | +$this->registerUtils(); |
|
| 105 | +$this->registerMetadataReader(); |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Set the logger |
| 110 | 110 | * |
| 111 | 111 | * @param LoggerInterface|Closure $xLogger |
| 112 | 112 | * |
| 113 | 113 | * @return void |
| 114 | 114 | */ |
| 115 | - public function setLogger(LoggerInterface|Closure $xLogger) |
|
| 116 | - { |
|
| 117 | - is_a($xLogger, LoggerInterface::class) ? |
|
| 118 | - $this->val(LoggerInterface::class, $xLogger) : |
|
| 119 | - $this->set(LoggerInterface::class, $xLogger); |
|
| 120 | - } |
|
| 115 | +public function setLogger(LoggerInterface|Closure $xLogger) |
|
| 116 | +{ |
|
| 117 | +is_a($xLogger, LoggerInterface::class) ? |
|
| 118 | +$this->val(LoggerInterface::class, $xLogger) : |
|
| 119 | +$this->set(LoggerInterface::class, $xLogger); |
|
| 120 | +} |
|
| 121 | 121 | |
| 122 | - /** |
|
| 122 | +/** |
|
| 123 | 123 | * Get the logger |
| 124 | 124 | * |
| 125 | 125 | * @return LoggerInterface |
| 126 | 126 | */ |
| 127 | - public function getLogger(): LoggerInterface |
|
| 128 | - { |
|
| 129 | - return $this->get(LoggerInterface::class); |
|
| 130 | - } |
|
| 127 | +public function getLogger(): LoggerInterface |
|
| 128 | +{ |
|
| 129 | +return $this->get(LoggerInterface::class); |
|
| 130 | +} |
|
| 131 | 131 | |
| 132 | - /** |
|
| 132 | +/** |
|
| 133 | 133 | * Set the container provided by the integrated framework |
| 134 | 134 | * |
| 135 | 135 | * @param ContainerInterface $xContainer The container implementation |
| 136 | 136 | * |
| 137 | 137 | * @return void |
| 138 | 138 | */ |
| 139 | - public function setContainer(ContainerInterface $xContainer) |
|
| 140 | - { |
|
| 141 | - $this->xAppContainer = $xContainer; |
|
| 142 | - } |
|
| 139 | +public function setContainer(ContainerInterface $xContainer) |
|
| 140 | +{ |
|
| 141 | +$this->xAppContainer = $xContainer; |
|
| 142 | +} |
|
| 143 | 143 | |
| 144 | - /** |
|
| 144 | +/** |
|
| 145 | 145 | * Check if a class is defined in the container |
| 146 | 146 | * |
| 147 | 147 | * @param string $sClass The full class name |
| 148 | 148 | * |
| 149 | 149 | * @return bool |
| 150 | 150 | */ |
| 151 | - public function h(string $sClass): bool |
|
| 152 | - { |
|
| 153 | - return $this->xLibContainer->offsetExists($sClass); |
|
| 154 | - } |
|
| 151 | +public function h(string $sClass): bool |
|
| 152 | +{ |
|
| 153 | +return $this->xLibContainer->offsetExists($sClass); |
|
| 154 | +} |
|
| 155 | 155 | |
| 156 | - /** |
|
| 156 | +/** |
|
| 157 | 157 | * Check if a class is defined in the container |
| 158 | 158 | * |
| 159 | 159 | * @param string $sClass The full class name |
| 160 | 160 | * |
| 161 | 161 | * @return bool |
| 162 | 162 | */ |
| 163 | - public function has(string $sClass): bool |
|
| 164 | - { |
|
| 165 | - return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 166 | - true : $this->xLibContainer->offsetExists($sClass); |
|
| 167 | - } |
|
| 163 | +public function has(string $sClass): bool |
|
| 164 | +{ |
|
| 165 | +return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 166 | +true : $this->xLibContainer->offsetExists($sClass); |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * Get a class instance |
| 171 | 171 | * |
| 172 | 172 | * @template T |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return T |
| 176 | 176 | */ |
| 177 | - public function g(string $sClass): mixed |
|
| 178 | - { |
|
| 179 | - return $this->xLibContainer->offsetGet($sClass); |
|
| 180 | - } |
|
| 177 | +public function g(string $sClass): mixed |
|
| 178 | +{ |
|
| 179 | +return $this->xLibContainer->offsetGet($sClass); |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Get a class instance |
| 184 | 184 | * |
| 185 | 185 | * @template T |
@@ -188,24 +188,24 @@ discard block |
||
| 188 | 188 | * @return T |
| 189 | 189 | * @throws SetupException |
| 190 | 190 | */ |
| 191 | - public function get(string $sClass): mixed |
|
| 192 | - { |
|
| 193 | - try |
|
| 194 | - { |
|
| 195 | - return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 196 | - $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
|
| 197 | - } |
|
| 198 | - catch(Throwable $e) |
|
| 199 | - { |
|
| 200 | - $xLogger = $this->g(LoggerInterface::class); |
|
| 201 | - $xTranslator = $this->g(Translator::class); |
|
| 202 | - $sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
|
| 203 | - $xLogger->error($e->getMessage(), ['message' => $sMessage]); |
|
| 204 | - throw new SetupException($sMessage); |
|
| 205 | - } |
|
| 206 | - } |
|
| 191 | +public function get(string $sClass): mixed |
|
| 192 | +{ |
|
| 193 | +try |
|
| 194 | +{ |
|
| 195 | +return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 196 | + $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
|
| 197 | +} |
|
| 198 | +catch(Throwable $e) |
|
| 199 | +{ |
|
| 200 | +$xLogger = $this->g(LoggerInterface::class); |
|
| 201 | +$xTranslator = $this->g(Translator::class); |
|
| 202 | +$sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
|
| 203 | +$xLogger->error($e->getMessage(), ['message' => $sMessage]); |
|
| 204 | +throw new SetupException($sMessage); |
|
| 205 | +} |
|
| 206 | +} |
|
| 207 | 207 | |
| 208 | - /** |
|
| 208 | +/** |
|
| 209 | 209 | * Save a closure in the container |
| 210 | 210 | * |
| 211 | 211 | * @param string|class-string $sClass The full class name |
@@ -214,15 +214,15 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @return void |
| 216 | 216 | */ |
| 217 | - public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true) |
|
| 218 | - { |
|
| 219 | - // Wrap the user closure into a new closure, so it can take this container as a parameter. |
|
| 220 | - $xClosure = fn() => $xClosure($this); |
|
| 221 | - $this->xLibContainer->offsetSet($sClass, $bIsSingleton ? |
|
| 222 | - $xClosure : $this->xLibContainer->factory($xClosure)); |
|
| 223 | - } |
|
| 217 | +public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true) |
|
| 218 | +{ |
|
| 219 | +// Wrap the user closure into a new closure, so it can take this container as a parameter. |
|
| 220 | +$xClosure = fn() => $xClosure($this); |
|
| 221 | +$this->xLibContainer->offsetSet($sClass, $bIsSingleton ? |
|
| 222 | +$xClosure : $this->xLibContainer->factory($xClosure)); |
|
| 223 | +} |
|
| 224 | 224 | |
| 225 | - /** |
|
| 225 | +/** |
|
| 226 | 226 | * Save a value in the container |
| 227 | 227 | * |
| 228 | 228 | * @param string|class-string $sKey The key |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return void |
| 232 | 232 | */ |
| 233 | - public function val(string $sKey, $xValue) |
|
| 234 | - { |
|
| 235 | - $this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 236 | - } |
|
| 233 | +public function val(string $sKey, $xValue) |
|
| 234 | +{ |
|
| 235 | +$this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 236 | +} |
|
| 237 | 237 | |
| 238 | - /** |
|
| 238 | +/** |
|
| 239 | 239 | * Set an alias in the container |
| 240 | 240 | * |
| 241 | 241 | * @param string|class-string $sAlias The alias name |
@@ -243,32 +243,32 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function alias(string $sAlias, string $sClass) |
|
| 247 | - { |
|
| 248 | - $this->set($sAlias, function($di) use ($sClass) { |
|
| 249 | - return $di->get($sClass); |
|
| 250 | - }); |
|
| 251 | - } |
|
| 246 | +public function alias(string $sAlias, string $sClass) |
|
| 247 | +{ |
|
| 248 | +$this->set($sAlias, function($di) use ($sClass) { |
|
| 249 | +return $di->get($sClass); |
|
| 250 | +}); |
|
| 251 | +} |
|
| 252 | 252 | |
| 253 | - /** |
|
| 253 | +/** |
|
| 254 | 254 | * Get the session manager |
| 255 | 255 | * |
| 256 | 256 | * @return SessionInterface|null |
| 257 | 257 | */ |
| 258 | - public function getSessionManager(): ?SessionInterface |
|
| 259 | - { |
|
| 260 | - return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null; |
|
| 261 | - } |
|
| 258 | +public function getSessionManager(): ?SessionInterface |
|
| 259 | +{ |
|
| 260 | +return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null; |
|
| 261 | +} |
|
| 262 | 262 | |
| 263 | - /** |
|
| 263 | +/** |
|
| 264 | 264 | * Set the session manager |
| 265 | 265 | * |
| 266 | 266 | * @param Closure $xClosure A closure to create the session manager instance |
| 267 | 267 | * |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public function setSessionManager(Closure $xClosure) |
|
| 271 | - { |
|
| 272 | - $this->set(SessionInterface::class, $xClosure); |
|
| 273 | - } |
|
| 270 | +public function setSessionManager(Closure $xClosure) |
|
| 271 | +{ |
|
| 272 | +$this->set(SessionInterface::class, $xClosure); |
|
| 273 | +} |
|
| 274 | 274 | } |
@@ -23,58 +23,58 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | class Bootstrap |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The library options |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - private $aLibOptions = []; |
|
| 31 | +private $aLibOptions = []; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The application options |
| 35 | 35 | * |
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - private $aAppOptions = []; |
|
| 38 | +private $aAppOptions = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The class constructor |
| 42 | 42 | * |
| 43 | 43 | * @param ConfigManager $xConfigManager |
| 44 | 44 | * @param PackageManager $xPackageManager |
| 45 | 45 | * @param CallbackManager $xCallbackManager |
| 46 | 46 | */ |
| 47 | - public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | - private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | - {} |
|
| 47 | +public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | +private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | +{} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Set the library options |
| 53 | 53 | * |
| 54 | 54 | * @param array $aLibOptions The library options |
| 55 | 55 | * |
| 56 | 56 | * @return Bootstrap |
| 57 | 57 | */ |
| 58 | - public function lib(array $aLibOptions): Bootstrap |
|
| 59 | - { |
|
| 60 | - $this->aLibOptions = $aLibOptions; |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 58 | +public function lib(array $aLibOptions): Bootstrap |
|
| 59 | +{ |
|
| 60 | +$this->aLibOptions = $aLibOptions; |
|
| 61 | +return $this; |
|
| 62 | +} |
|
| 63 | 63 | |
| 64 | - /** |
|
| 64 | +/** |
|
| 65 | 65 | * Set the applications options |
| 66 | 66 | * |
| 67 | 67 | * @param array $aAppOptions The application options |
| 68 | 68 | * |
| 69 | 69 | * @return Bootstrap |
| 70 | 70 | */ |
| 71 | - public function app(array $aAppOptions): Bootstrap |
|
| 72 | - { |
|
| 73 | - $this->aAppOptions = $aAppOptions; |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 71 | +public function app(array $aAppOptions): Bootstrap |
|
| 72 | +{ |
|
| 73 | +$this->aAppOptions = $aAppOptions; |
|
| 74 | +return $this; |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * Set the javascript asset |
| 79 | 79 | * |
| 80 | 80 | * @param bool $bExport Whether to export the js code in a file |
@@ -84,76 +84,76 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return Bootstrap |
| 86 | 86 | */ |
| 87 | - public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | - { |
|
| 89 | - // Jaxon library settings |
|
| 90 | - $aJsOptions = [ |
|
| 91 | - 'export' => $bExport, |
|
| 92 | - 'minify' => $bMinify, |
|
| 93 | - ]; |
|
| 94 | - if($sUri !== '') |
|
| 95 | - { |
|
| 96 | - $aJsOptions['uri'] = $sUri; |
|
| 97 | - } |
|
| 98 | - if($sDir !== '') |
|
| 99 | - { |
|
| 100 | - $aJsOptions['dir'] = $sDir; |
|
| 101 | - } |
|
| 102 | - // The export options are saved in the "app" section of the config. |
|
| 103 | - $this->xConfigManager->setAppOptions($aJsOptions, 'assets.js'); |
|
| 104 | - return $this; |
|
| 105 | - } |
|
| 87 | +public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | +{ |
|
| 89 | +// Jaxon library settings |
|
| 90 | +$aJsOptions = [ |
|
| 91 | +'export' => $bExport, |
|
| 92 | +'minify' => $bMinify, |
|
| 93 | +]; |
|
| 94 | +if($sUri !== '') |
|
| 95 | +{ |
|
| 96 | +$aJsOptions['uri'] = $sUri; |
|
| 97 | +} |
|
| 98 | +if($sDir !== '') |
|
| 99 | +{ |
|
| 100 | +$aJsOptions['dir'] = $sDir; |
|
| 101 | +} |
|
| 102 | +// The export options are saved in the "app" section of the config. |
|
| 103 | +$this->xConfigManager->setAppOptions($aJsOptions, 'assets.js'); |
|
| 104 | +return $this; |
|
| 105 | +} |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * Set the Jaxon application options. |
| 109 | 109 | * |
| 110 | 110 | * @return void |
| 111 | 111 | * @throws SetupException |
| 112 | 112 | */ |
| 113 | - private function setupApp(): void |
|
| 114 | - { |
|
| 115 | - // Save the app config. |
|
| 116 | - $this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 117 | - // Register user functions and classes |
|
| 118 | - $this->xPackageManager->registerFromConfig(); |
|
| 119 | - } |
|
| 113 | +private function setupApp(): void |
|
| 114 | +{ |
|
| 115 | +// Save the app config. |
|
| 116 | +$this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 117 | +// Register user functions and classes |
|
| 118 | +$this->xPackageManager->registerFromConfig(); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Wraps the module/package/bundle setup method. |
| 123 | 123 | * |
| 124 | 124 | * @return void |
| 125 | 125 | * @throws SetupException |
| 126 | 126 | */ |
| 127 | - public function setup(): void |
|
| 128 | - { |
|
| 129 | - // Prevent the Jaxon library from sending the response or exiting |
|
| 130 | - $this->xConfigManager->setOptions([ |
|
| 131 | - 'response' => [ |
|
| 132 | - 'send' => false, |
|
| 133 | - ], |
|
| 134 | - 'process' => [ |
|
| 135 | - 'exit' => false, |
|
| 136 | - ], |
|
| 137 | - ], 'core'); |
|
| 138 | - // Setup the lib config options. |
|
| 139 | - $this->xConfigManager->setOptions($this->aLibOptions); |
|
| 127 | +public function setup(): void |
|
| 128 | +{ |
|
| 129 | +// Prevent the Jaxon library from sending the response or exiting |
|
| 130 | +$this->xConfigManager->setOptions([ |
|
| 131 | +'response' => [ |
|
| 132 | + 'send' => false, |
|
| 133 | +], |
|
| 134 | +'process' => [ |
|
| 135 | + 'exit' => false, |
|
| 136 | +], |
|
| 137 | +], 'core'); |
|
| 138 | +// Setup the lib config options. |
|
| 139 | +$this->xConfigManager->setOptions($this->aLibOptions); |
|
| 140 | 140 | |
| 141 | - // Setup the app. |
|
| 142 | - $this->setupApp(); |
|
| 143 | - } |
|
| 141 | +// Setup the app. |
|
| 142 | +$this->setupApp(); |
|
| 143 | +} |
|
| 144 | 144 | |
| 145 | - /** |
|
| 145 | +/** |
|
| 146 | 146 | * These callbacks are called once, after the library is initialized. |
| 147 | 147 | * |
| 148 | 148 | * @return void |
| 149 | 149 | */ |
| 150 | - public function onBoot(): void |
|
| 151 | - { |
|
| 152 | - // Popping the callbacks makes each of them to be called once. |
|
| 153 | - $aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 154 | - foreach($aBootCallbacks as $aBootCallback) |
|
| 155 | - { |
|
| 156 | - call_user_func($aBootCallback); |
|
| 157 | - } |
|
| 158 | - } |
|
| 150 | +public function onBoot(): void |
|
| 151 | +{ |
|
| 152 | +// Popping the callbacks makes each of them to be called once. |
|
| 153 | +$aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 154 | +foreach($aBootCallbacks as $aBootCallback) |
|
| 155 | +{ |
|
| 156 | +call_user_func($aBootCallback); |
|
| 157 | +} |
|
| 158 | +} |
|
| 159 | 159 | } |
@@ -31,40 +31,40 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | class HtmlAttrHelper |
| 33 | 33 | { |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @var string|null |
| 36 | 36 | */ |
| 37 | - private string|null $sPaginationComponent = null; |
|
| 37 | +private string|null $sPaginationComponent = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * The constructor |
| 41 | 41 | * |
| 42 | 42 | * @param ComponentContainer $cdi |
| 43 | 43 | */ |
| 44 | - public function __construct(protected ComponentContainer $cdi) |
|
| 45 | - {} |
|
| 44 | +public function __construct(protected ComponentContainer $cdi) |
|
| 45 | +{} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * Get the component HTML code |
| 49 | 49 | * |
| 50 | 50 | * @param JxnCall $xJsCall |
| 51 | 51 | * |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public function html(JxnCall $xJsCall): string |
|
| 55 | - { |
|
| 56 | - $sClassName = $xJsCall->_class(); |
|
| 57 | - if(!$sClassName) |
|
| 58 | - { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $xComponent = $this->cdi->makeComponent($sClassName); |
|
| 63 | - return is_a($xComponent, NodeComponent::class) ? |
|
| 64 | - (string)$xComponent->html() : ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 54 | +public function html(JxnCall $xJsCall): string |
|
| 55 | +{ |
|
| 56 | +$sClassName = $xJsCall->_class(); |
|
| 57 | +if(!$sClassName) |
|
| 58 | +{ |
|
| 59 | +return ''; |
|
| 60 | +} |
|
| 61 | + |
|
| 62 | +$xComponent = $this->cdi->makeComponent($sClassName); |
|
| 63 | +return is_a($xComponent, NodeComponent::class) ? |
|
| 64 | +(string)$xComponent->html() : ''; |
|
| 65 | +} |
|
| 66 | + |
|
| 67 | +/** |
|
| 68 | 68 | * Attach a component to a DOM node |
| 69 | 69 | * |
| 70 | 70 | * @param JxnCall $xJsCall |
@@ -72,41 +72,41 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | - public function bind(JxnCall $xJsCall, string $item = ''): string |
|
| 76 | - { |
|
| 77 | - $item = trim($item); |
|
| 78 | - return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"'); |
|
| 79 | - } |
|
| 75 | +public function bind(JxnCall $xJsCall, string $item = ''): string |
|
| 76 | +{ |
|
| 77 | +$item = trim($item); |
|
| 78 | +return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"'); |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * Attach the pagination component to a DOM node |
| 83 | 83 | * |
| 84 | 84 | * @param JxnCall $xJsCall |
| 85 | 85 | * |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function pagination(JxnCall $xJsCall): string |
|
| 89 | - { |
|
| 90 | - // The pagination is always rendered with the same Pagination component. |
|
| 91 | - $sComponent = $this->sPaginationComponent ?: |
|
| 92 | - ($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 93 | - $sItem = $xJsCall->_class(); |
|
| 94 | - return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\""; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 88 | +public function pagination(JxnCall $xJsCall): string |
|
| 89 | +{ |
|
| 90 | +// The pagination is always rendered with the same Pagination component. |
|
| 91 | +$sComponent = $this->sPaginationComponent ?: |
|
| 92 | +($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 93 | +$sItem = $xJsCall->_class(); |
|
| 94 | +return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\""; |
|
| 95 | +} |
|
| 96 | + |
|
| 97 | +/** |
|
| 98 | 98 | * Set a selector for the next event handler |
| 99 | 99 | * |
| 100 | 100 | * @param string $sSelector |
| 101 | 101 | * |
| 102 | 102 | * @return EventAttr |
| 103 | 103 | */ |
| 104 | - public function select(string $sSelector): EventAttr |
|
| 105 | - { |
|
| 106 | - return new EventAttr($sSelector); |
|
| 107 | - } |
|
| 104 | +public function select(string $sSelector): EventAttr |
|
| 105 | +{ |
|
| 106 | +return new EventAttr($sSelector); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Set an event handler |
| 111 | 111 | * |
| 112 | 112 | * @param string $event |
@@ -114,83 +114,83 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | - public function on(string $event, JsExpr $xJsExpr): string |
|
| 118 | - { |
|
| 119 | - $event = trim($event); |
|
| 120 | - $sCall = htmlentities(json_encode($xJsExpr->jsonSerialize())); |
|
| 121 | - return "jxn-on=\"$event\" jxn-call=\"$sCall\""; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 117 | +public function on(string $event, JsExpr $xJsExpr): string |
|
| 118 | +{ |
|
| 119 | +$event = trim($event); |
|
| 120 | +$sCall = htmlentities(json_encode($xJsExpr->jsonSerialize())); |
|
| 121 | +return "jxn-on=\"$event\" jxn-call=\"$sCall\""; |
|
| 122 | +} |
|
| 123 | + |
|
| 124 | +/** |
|
| 125 | 125 | * Shortcut to set a click event handler |
| 126 | 126 | * |
| 127 | 127 | * @param JsExpr $xJsExpr |
| 128 | 128 | * |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | - public function click(JsExpr $xJsExpr): string |
|
| 132 | - { |
|
| 133 | - return $this->on('click', $xJsExpr); |
|
| 134 | - } |
|
| 131 | +public function click(JsExpr $xJsExpr): string |
|
| 132 | +{ |
|
| 133 | +return $this->on('click', $xJsExpr); |
|
| 134 | +} |
|
| 135 | 135 | |
| 136 | - /** |
|
| 136 | +/** |
|
| 137 | 137 | * @param array $aHandler |
| 138 | 138 | * |
| 139 | 139 | * @return bool |
| 140 | 140 | */ |
| 141 | - private function eventIsValid(array $aHandler): bool |
|
| 142 | - { |
|
| 143 | - return count($aHandler) === 3 && |
|
| 144 | - isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) && |
|
| 145 | - is_string($aHandler[0]) && is_string($aHandler[1]) && |
|
| 146 | - is_a($aHandler[2], JsExpr::class); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 141 | +private function eventIsValid(array $aHandler): bool |
|
| 142 | +{ |
|
| 143 | +return count($aHandler) === 3 && |
|
| 144 | +isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) && |
|
| 145 | +is_string($aHandler[0]) && is_string($aHandler[1]) && |
|
| 146 | +is_a($aHandler[2], JsExpr::class); |
|
| 147 | +} |
|
| 148 | + |
|
| 149 | +/** |
|
| 150 | 150 | * @param array $aHandler |
| 151 | 151 | * @param EventAttr|null $xAttr |
| 152 | 152 | * |
| 153 | 153 | * @return EventAttr|null |
| 154 | 154 | */ |
| 155 | - private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null |
|
| 156 | - { |
|
| 157 | - if(!$this->eventIsValid($aHandler)) |
|
| 158 | - { |
|
| 159 | - return $xAttr; |
|
| 160 | - } |
|
| 161 | - // The array content is valid. |
|
| 162 | - [$sSelector, $sEvent, $xJsExpr] = $aHandler; |
|
| 163 | - return !$xAttr ? |
|
| 164 | - $this->select($sSelector)->on($sEvent, $xJsExpr) : |
|
| 165 | - $xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 155 | +private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null |
|
| 156 | +{ |
|
| 157 | +if(!$this->eventIsValid($aHandler)) |
|
| 158 | +{ |
|
| 159 | +return $xAttr; |
|
| 160 | +} |
|
| 161 | +// The array content is valid. |
|
| 162 | +[$sSelector, $sEvent, $xJsExpr] = $aHandler; |
|
| 163 | +return !$xAttr ? |
|
| 164 | +$this->select($sSelector)->on($sEvent, $xJsExpr) : |
|
| 165 | +$xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 166 | +} |
|
| 167 | + |
|
| 168 | +/** |
|
| 169 | 169 | * Set an event handler |
| 170 | 170 | * |
| 171 | 171 | * @param array $aHandler |
| 172 | 172 | * |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function event(array $aHandler): string |
|
| 176 | - { |
|
| 177 | - return $this->setEventHandler($aHandler)?->__toString() ?? ''; |
|
| 178 | - } |
|
| 175 | +public function event(array $aHandler): string |
|
| 176 | +{ |
|
| 177 | +return $this->setEventHandler($aHandler)?->__toString() ?? ''; |
|
| 178 | +} |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | +/** |
|
| 181 | 181 | * Set event handlers |
| 182 | 182 | * |
| 183 | 183 | * @param array $aHandlers |
| 184 | 184 | * |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public function events(array $aHandlers): string |
|
| 188 | - { |
|
| 189 | - return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler) |
|
| 190 | - => $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? ''; |
|
| 191 | - } |
|
| 187 | +public function events(array $aHandlers): string |
|
| 188 | +{ |
|
| 189 | +return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler) |
|
| 190 | +=> $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? ''; |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - /** |
|
| 193 | +/** |
|
| 194 | 194 | * Get the HTML or Javascript ready code for a package |
| 195 | 195 | * |
| 196 | 196 | * @param string $sClass |
@@ -198,22 +198,22 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function package(string $sClass, string $sType = 'html'): string |
|
| 202 | - { |
|
| 203 | - if(($xPackage = jaxon()->package($sClass)) === null) |
|
| 204 | - { |
|
| 205 | - return ''; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $sCode = trim(match($sType) { |
|
| 209 | - 'html' => $xPackage->getHtml(), |
|
| 210 | - 'inline' => $xPackage->getInlineScript(), |
|
| 211 | - 'ready' => $xPackage->getReadyScript(), |
|
| 212 | - default => '' |
|
| 213 | - }); |
|
| 214 | - |
|
| 215 | - return $sCode === '' || $sType !== 'ready' ? $sCode : |
|
| 216 | - // Call the ready code with the jaxon.dom.ready function. |
|
| 217 | - "jaxon.dom.ready(() => $sCode)"; |
|
| 218 | - } |
|
| 201 | +public function package(string $sClass, string $sType = 'html'): string |
|
| 202 | +{ |
|
| 203 | +if(($xPackage = jaxon()->package($sClass)) === null) |
|
| 204 | +{ |
|
| 205 | +return ''; |
|
| 206 | +} |
|
| 207 | + |
|
| 208 | +$sCode = trim(match($sType) { |
|
| 209 | +'html' => $xPackage->getHtml(), |
|
| 210 | +'inline' => $xPackage->getInlineScript(), |
|
| 211 | +'ready' => $xPackage->getReadyScript(), |
|
| 212 | +default => '' |
|
| 213 | +}); |
|
| 214 | + |
|
| 215 | +return $sCode === '' || $sType !== 'ready' ? $sCode : |
|
| 216 | +// Call the ready code with the jaxon.dom.ready function. |
|
| 217 | +"jaxon.dom.ready(() => $sCode)"; |
|
| 218 | +} |
|
| 219 | 219 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function html(JxnCall $xJsCall): string |
| 55 | 55 | { |
| 56 | 56 | $sClassName = $xJsCall->_class(); |
| 57 | - if(!$sClassName) |
|
| 57 | + if (!$sClassName) |
|
| 58 | 58 | { |
| 59 | 59 | return ''; |
| 60 | 60 | } |
@@ -88,8 +88,7 @@ discard block |
||
| 88 | 88 | public function pagination(JxnCall $xJsCall): string |
| 89 | 89 | { |
| 90 | 90 | // The pagination is always rendered with the same Pagination component. |
| 91 | - $sComponent = $this->sPaginationComponent ?: |
|
| 92 | - ($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 91 | + $sComponent = $this->sPaginationComponent ?: ($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 93 | 92 | $sItem = $xJsCall->_class(); |
| 94 | 93 | return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\""; |
| 95 | 94 | } |
@@ -154,15 +153,14 @@ discard block |
||
| 154 | 153 | */ |
| 155 | 154 | private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null |
| 156 | 155 | { |
| 157 | - if(!$this->eventIsValid($aHandler)) |
|
| 156 | + if (!$this->eventIsValid($aHandler)) |
|
| 158 | 157 | { |
| 159 | 158 | return $xAttr; |
| 160 | 159 | } |
| 161 | 160 | // The array content is valid. |
| 162 | 161 | [$sSelector, $sEvent, $xJsExpr] = $aHandler; |
| 163 | 162 | return !$xAttr ? |
| 164 | - $this->select($sSelector)->on($sEvent, $xJsExpr) : |
|
| 165 | - $xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 163 | + $this->select($sSelector)->on($sEvent, $xJsExpr) : $xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 166 | 164 | } |
| 167 | 165 | |
| 168 | 166 | /** |
@@ -200,7 +198,7 @@ discard block |
||
| 200 | 198 | */ |
| 201 | 199 | public function package(string $sClass, string $sType = 'html'): string |
| 202 | 200 | { |
| 203 | - if(($xPackage = jaxon()->package($sClass)) === null) |
|
| 201 | + if (($xPackage = jaxon()->package($sClass)) === null) |
|
| 204 | 202 | { |
| 205 | 203 | return ''; |
| 206 | 204 | } |
@@ -212,8 +210,7 @@ discard block |
||
| 212 | 210 | default => '' |
| 213 | 211 | }); |
| 214 | 212 | |
| 215 | - return $sCode === '' || $sType !== 'ready' ? $sCode : |
|
| 216 | - // Call the ready code with the jaxon.dom.ready function. |
|
| 213 | + return $sCode === '' || $sType !== 'ready' ? $sCode : // Call the ready code with the jaxon.dom.ready function. |
|
| 217 | 214 | "jaxon.dom.ready(() => $sCode)"; |
| 218 | 215 | } |
| 219 | 216 | } |
@@ -47,49 +47,49 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | class PluginManager |
| 49 | 49 | { |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * Request plugins, indexed by name |
| 52 | 52 | * |
| 53 | 53 | * @var array<string> |
| 54 | 54 | */ |
| 55 | - private $aRegistryPlugins = []; |
|
| 55 | +private $aRegistryPlugins = []; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * Request handlers, indexed by name |
| 59 | 59 | * |
| 60 | 60 | * @var array<string> |
| 61 | 61 | */ |
| 62 | - private $aRequestHandlers = []; |
|
| 62 | +private $aRequestHandlers = []; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 64 | +/** |
|
| 65 | 65 | * Response plugins, indexed by name |
| 66 | 66 | * |
| 67 | 67 | * @var array<string> |
| 68 | 68 | */ |
| 69 | - private $aResponsePlugins = []; |
|
| 69 | +private $aResponsePlugins = []; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 71 | +/** |
|
| 72 | 72 | * The constructor |
| 73 | 73 | * |
| 74 | 74 | * @param Container $di |
| 75 | 75 | * @param CodeGenerator $xCodeGenerator |
| 76 | 76 | * @param Translator $xTranslator |
| 77 | 77 | */ |
| 78 | - public function __construct(private Container $di, |
|
| 79 | - private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 80 | - {} |
|
| 78 | +public function __construct(private Container $di, |
|
| 79 | +private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 80 | +{} |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | +/** |
|
| 83 | 83 | * Get the request plugins |
| 84 | 84 | * |
| 85 | 85 | * @return array<class-string> |
| 86 | 86 | */ |
| 87 | - public function getRequestHandlers(): array |
|
| 88 | - { |
|
| 89 | - return $this->aRequestHandlers; |
|
| 90 | - } |
|
| 87 | +public function getRequestHandlers(): array |
|
| 88 | +{ |
|
| 89 | +return $this->aRequestHandlers; |
|
| 90 | +} |
|
| 91 | 91 | |
| 92 | - /** |
|
| 92 | +/** |
|
| 93 | 93 | * Register a plugin |
| 94 | 94 | * |
| 95 | 95 | * @param class-string $sClassName The plugin class |
@@ -99,81 +99,81 @@ discard block |
||
| 99 | 99 | * @return int |
| 100 | 100 | * @throws SetupException |
| 101 | 101 | */ |
| 102 | - private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 103 | - { |
|
| 104 | - // Any plugin must implement the PluginInterface interface. |
|
| 105 | - if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 106 | - { |
|
| 107 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 108 | - 'name' => $sClassName, |
|
| 109 | - ]); |
|
| 110 | - throw new SetupException($sMessage); |
|
| 111 | - } |
|
| 102 | +private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 103 | +{ |
|
| 104 | +// Any plugin must implement the PluginInterface interface. |
|
| 105 | +if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 106 | +{ |
|
| 107 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 108 | + 'name' => $sClassName, |
|
| 109 | +]); |
|
| 110 | +throw new SetupException($sMessage); |
|
| 111 | +} |
|
| 112 | 112 | |
| 113 | - // Response plugin. |
|
| 114 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 115 | - { |
|
| 116 | - $this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 117 | - return 1; |
|
| 118 | - } |
|
| 113 | +// Response plugin. |
|
| 114 | +if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 115 | +{ |
|
| 116 | +$this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 117 | +return 1; |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - // Request plugin. |
|
| 121 | - $nCount = 0; |
|
| 122 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 123 | - { |
|
| 124 | - $this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 125 | - $nCount++; |
|
| 126 | - } |
|
| 127 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 128 | - { |
|
| 129 | - $this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 130 | - $nCount++; |
|
| 131 | - } |
|
| 132 | - return $nCount; |
|
| 133 | - } |
|
| 120 | +// Request plugin. |
|
| 121 | +$nCount = 0; |
|
| 122 | +if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 123 | +{ |
|
| 124 | +$this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 125 | +$nCount++; |
|
| 126 | +} |
|
| 127 | +if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 128 | +{ |
|
| 129 | +$this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 130 | +$nCount++; |
|
| 131 | +} |
|
| 132 | +return $nCount; |
|
| 133 | +} |
|
| 134 | 134 | |
| 135 | - /** |
|
| 135 | +/** |
|
| 136 | 136 | * @param string $sClassName |
| 137 | 137 | * @param int $nPriority |
| 138 | 138 | * @param array $aInterfaces |
| 139 | 139 | * |
| 140 | 140 | * @return int |
| 141 | 141 | */ |
| 142 | - private function _registerCodeGenerator(string $sClassName, int $nPriority, array $aInterfaces): int |
|
| 143 | - { |
|
| 144 | - // Any plugin can implement the one of the 3 code generator interfaces. |
|
| 145 | - $nCount = 0; |
|
| 146 | - if(in_array(CssCodeGeneratorInterface::class, $aInterfaces)) |
|
| 147 | - { |
|
| 148 | - $this->xCodeGenerator->addCssCodeGenerator($sClassName, $nPriority); |
|
| 149 | - $nCount++; |
|
| 150 | - } |
|
| 151 | - if(in_array(JsCodeGeneratorInterface::class, $aInterfaces)) |
|
| 152 | - { |
|
| 153 | - $this->xCodeGenerator->addJsCodeGenerator($sClassName, $nPriority); |
|
| 154 | - $nCount++; |
|
| 155 | - } |
|
| 156 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 157 | - { |
|
| 158 | - $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 159 | - $nCount++; |
|
| 160 | - } |
|
| 161 | - return $nCount; |
|
| 162 | - } |
|
| 142 | +private function _registerCodeGenerator(string $sClassName, int $nPriority, array $aInterfaces): int |
|
| 143 | +{ |
|
| 144 | +// Any plugin can implement the one of the 3 code generator interfaces. |
|
| 145 | +$nCount = 0; |
|
| 146 | +if(in_array(CssCodeGeneratorInterface::class, $aInterfaces)) |
|
| 147 | +{ |
|
| 148 | +$this->xCodeGenerator->addCssCodeGenerator($sClassName, $nPriority); |
|
| 149 | +$nCount++; |
|
| 150 | +} |
|
| 151 | +if(in_array(JsCodeGeneratorInterface::class, $aInterfaces)) |
|
| 152 | +{ |
|
| 153 | +$this->xCodeGenerator->addJsCodeGenerator($sClassName, $nPriority); |
|
| 154 | +$nCount++; |
|
| 155 | +} |
|
| 156 | +if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 157 | +{ |
|
| 158 | +$this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 159 | +$nCount++; |
|
| 160 | +} |
|
| 161 | +return $nCount; |
|
| 162 | +} |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | +/** |
|
| 165 | 165 | * @param string $sClassName |
| 166 | 166 | * @param int $nPriority |
| 167 | 167 | * |
| 168 | 168 | * @return void |
| 169 | 169 | */ |
| 170 | - public function registerCodeGenerator(string $sClassName, int $nPriority): void |
|
| 171 | - { |
|
| 172 | - $aInterfaces = class_implements($sClassName); |
|
| 173 | - $this->_registerCodeGenerator($sClassName, $nPriority, $aInterfaces); |
|
| 174 | - } |
|
| 170 | +public function registerCodeGenerator(string $sClassName, int $nPriority): void |
|
| 171 | +{ |
|
| 172 | +$aInterfaces = class_implements($sClassName); |
|
| 173 | +$this->_registerCodeGenerator($sClassName, $nPriority, $aInterfaces); |
|
| 174 | +} |
|
| 175 | 175 | |
| 176 | - /** |
|
| 176 | +/** |
|
| 177 | 177 | * Register a plugin |
| 178 | 178 | * |
| 179 | 179 | * Below is a table for priorities and their description: |
@@ -188,29 +188,29 @@ discard block |
||
| 188 | 188 | * @return void |
| 189 | 189 | * @throws SetupException |
| 190 | 190 | */ |
| 191 | - public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 192 | - { |
|
| 193 | - $aInterfaces = class_implements($sClassName); |
|
| 194 | - $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 195 | - $nCount += $this->_registerCodeGenerator($sClassName, $nPriority, $aInterfaces); |
|
| 191 | +public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 192 | +{ |
|
| 193 | +$aInterfaces = class_implements($sClassName); |
|
| 194 | +$nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 195 | +$nCount += $this->_registerCodeGenerator($sClassName, $nPriority, $aInterfaces); |
|
| 196 | 196 | |
| 197 | - // The class is not a valid plugin. |
|
| 198 | - if($nCount === 0) |
|
| 199 | - { |
|
| 200 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 201 | - 'name' => $sClassName, |
|
| 202 | - ]); |
|
| 203 | - throw new SetupException($sMessage); |
|
| 204 | - } |
|
| 197 | +// The class is not a valid plugin. |
|
| 198 | +if($nCount === 0) |
|
| 199 | +{ |
|
| 200 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 201 | + 'name' => $sClassName, |
|
| 202 | +]); |
|
| 203 | +throw new SetupException($sMessage); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - // Register the plugin in the DI container, if necessary |
|
| 207 | - if(!$this->di->has($sClassName)) |
|
| 208 | - { |
|
| 209 | - $this->di->auto($sClassName); |
|
| 210 | - } |
|
| 211 | - } |
|
| 206 | +// Register the plugin in the DI container, if necessary |
|
| 207 | +if(!$this->di->has($sClassName)) |
|
| 208 | +{ |
|
| 209 | +$this->di->auto($sClassName); |
|
| 210 | +} |
|
| 211 | +} |
|
| 212 | 212 | |
| 213 | - /** |
|
| 213 | +/** |
|
| 214 | 214 | * Find the specified response plugin by name or class name |
| 215 | 215 | * |
| 216 | 216 | * @template R of ResponsePluginInterface |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return ($sName is class-string ? R|null : ResponsePluginInterface|null) |
| 220 | 220 | */ |
| 221 | - public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 222 | - { |
|
| 223 | - return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 224 | - (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 225 | - $this->di->g($this->aResponsePlugins[$sName])); |
|
| 226 | - } |
|
| 221 | +public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 222 | +{ |
|
| 223 | +return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 224 | +(!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 225 | +$this->di->g($this->aResponsePlugins[$sName])); |
|
| 226 | +} |
|
| 227 | 227 | |
| 228 | - /** |
|
| 228 | +/** |
|
| 229 | 229 | * Register a callable function or class |
| 230 | 230 | * |
| 231 | 231 | * Call the request plugin with the $sType defined as name. |
@@ -237,46 +237,46 @@ discard block |
||
| 237 | 237 | * @return void |
| 238 | 238 | * @throws SetupException |
| 239 | 239 | */ |
| 240 | - public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 241 | - { |
|
| 242 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
| 243 | - ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 244 | - { |
|
| 245 | - $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 246 | - return; |
|
| 247 | - } |
|
| 248 | - throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 249 | - ['name' => $sType, 'callable' => $sCallable])); |
|
| 250 | - } |
|
| 240 | +public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 241 | +{ |
|
| 242 | +if(isset($this->aRegistryPlugins[$sType]) && |
|
| 243 | +($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 244 | +{ |
|
| 245 | +$xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 246 | +return; |
|
| 247 | +} |
|
| 248 | +throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 249 | +['name' => $sType, 'callable' => $sCallable])); |
|
| 250 | +} |
|
| 251 | 251 | |
| 252 | - /** |
|
| 252 | +/** |
|
| 253 | 253 | * Register the Jaxon request plugins |
| 254 | 254 | * |
| 255 | 255 | * @return void |
| 256 | 256 | * @throws SetupException |
| 257 | 257 | */ |
| 258 | - public function registerPlugins(): void |
|
| 259 | - { |
|
| 260 | - // Request plugins |
|
| 261 | - $this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 262 | - $this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 263 | - $this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 258 | +public function registerPlugins(): void |
|
| 259 | +{ |
|
| 260 | +// Request plugins |
|
| 261 | +$this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 262 | +$this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 263 | +$this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 264 | 264 | |
| 265 | - // Response plugins |
|
| 266 | - $this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 267 | - $this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 268 | - $this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 269 | - $this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 270 | - $this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 271 | - } |
|
| 265 | +// Response plugins |
|
| 266 | +$this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 267 | +$this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 268 | +$this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 269 | +$this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 270 | +$this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 271 | +} |
|
| 272 | 272 | |
| 273 | - /** |
|
| 273 | +/** |
|
| 274 | 274 | * Get the parameter reader |
| 275 | 275 | * |
| 276 | 276 | * @return ParameterReader |
| 277 | 277 | */ |
| 278 | - public function getParameterReader(): ParameterReader |
|
| 279 | - { |
|
| 280 | - return $this->di->g(ParameterReader::class); |
|
| 281 | - } |
|
| 278 | +public function getParameterReader(): ParameterReader |
|
| 279 | +{ |
|
| 280 | +return $this->di->g(ParameterReader::class); |
|
| 281 | +} |
|
| 282 | 282 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
| 103 | 103 | { |
| 104 | 104 | // Any plugin must implement the PluginInterface interface. |
| 105 | - if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 105 | + if (!in_array(PluginInterface::class, $aInterfaces)) |
|
| 106 | 106 | { |
| 107 | 107 | $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
| 108 | 108 | 'name' => $sClassName, |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // Response plugin. |
| 114 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 114 | + if (in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 115 | 115 | { |
| 116 | 116 | $this->aResponsePlugins[$sPluginName] = $sClassName; |
| 117 | 117 | return 1; |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | // Request plugin. |
| 121 | 121 | $nCount = 0; |
| 122 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 122 | + if (in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 123 | 123 | { |
| 124 | 124 | $this->aRegistryPlugins[$sPluginName] = $sClassName; |
| 125 | 125 | $nCount++; |
| 126 | 126 | } |
| 127 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 127 | + if (in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 128 | 128 | { |
| 129 | 129 | $this->aRequestHandlers[$sPluginName] = $sClassName; |
| 130 | 130 | $nCount++; |
@@ -143,17 +143,17 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | // Any plugin can implement the one of the 3 code generator interfaces. |
| 145 | 145 | $nCount = 0; |
| 146 | - if(in_array(CssCodeGeneratorInterface::class, $aInterfaces)) |
|
| 146 | + if (in_array(CssCodeGeneratorInterface::class, $aInterfaces)) |
|
| 147 | 147 | { |
| 148 | 148 | $this->xCodeGenerator->addCssCodeGenerator($sClassName, $nPriority); |
| 149 | 149 | $nCount++; |
| 150 | 150 | } |
| 151 | - if(in_array(JsCodeGeneratorInterface::class, $aInterfaces)) |
|
| 151 | + if (in_array(JsCodeGeneratorInterface::class, $aInterfaces)) |
|
| 152 | 152 | { |
| 153 | 153 | $this->xCodeGenerator->addJsCodeGenerator($sClassName, $nPriority); |
| 154 | 154 | $nCount++; |
| 155 | 155 | } |
| 156 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 156 | + if (in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 157 | 157 | { |
| 158 | 158 | $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
| 159 | 159 | $nCount++; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $nCount += $this->_registerCodeGenerator($sClassName, $nPriority, $aInterfaces); |
| 196 | 196 | |
| 197 | 197 | // The class is not a valid plugin. |
| 198 | - if($nCount === 0) |
|
| 198 | + if ($nCount === 0) |
|
| 199 | 199 | { |
| 200 | 200 | $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
| 201 | 201 | 'name' => $sClassName, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Register the plugin in the DI container, if necessary |
| 207 | - if(!$this->di->has($sClassName)) |
|
| 207 | + if (!$this->di->has($sClassName)) |
|
| 208 | 208 | { |
| 209 | 209 | $this->di->auto($sClassName); |
| 210 | 210 | } |
@@ -220,8 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
| 222 | 222 | { |
| 223 | - return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 224 | - (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 223 | + return $this->di->h($sName) ? $this->di->g($sName) : (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 225 | 224 | $this->di->g($this->aResponsePlugins[$sName])); |
| 226 | 225 | } |
| 227 | 226 | |
@@ -239,7 +238,7 @@ discard block |
||
| 239 | 238 | */ |
| 240 | 239 | public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
| 241 | 240 | { |
| 242 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
| 241 | + if (isset($this->aRegistryPlugins[$sType]) && |
|
| 243 | 242 | ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
| 244 | 243 | { |
| 245 | 244 | $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | class PackageManager |
| 35 | 35 | { |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * The constructor |
| 38 | 38 | * |
| 39 | 39 | * @param Container $di |
@@ -44,48 +44,48 @@ discard block |
||
| 44 | 44 | * @param CallbackManager $xCallbackManager |
| 45 | 45 | * @param ComponentRegistry $xRegistry |
| 46 | 46 | */ |
| 47 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 48 | - private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 49 | - private ViewRenderer $xViewRenderer, private CallbackManager $xCallbackManager, |
|
| 50 | - private ComponentRegistry $xRegistry) |
|
| 51 | - {} |
|
| 47 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 48 | +private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 49 | +private ViewRenderer $xViewRenderer, private CallbackManager $xCallbackManager, |
|
| 50 | +private ComponentRegistry $xRegistry) |
|
| 51 | +{} |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * Save items in the DI container |
| 55 | 55 | * |
| 56 | 56 | * @param Config $xConfig |
| 57 | 57 | * |
| 58 | 58 | * @return void |
| 59 | 59 | */ |
| 60 | - private function updateContainer(Config $xConfig): void |
|
| 61 | - { |
|
| 62 | - $aOptions = $xConfig->getOption('container.set', []); |
|
| 63 | - foreach($aOptions as $xKey => $xValue) |
|
| 64 | - { |
|
| 65 | - // The key is the class name. It must be a string. |
|
| 66 | - $this->di->set((string)$xKey, $xValue); |
|
| 67 | - } |
|
| 68 | - $aOptions = $xConfig->getOption('container.val', []); |
|
| 69 | - foreach($aOptions as $xKey => $xValue) |
|
| 70 | - { |
|
| 71 | - // The key is the class name. It must be a string. |
|
| 72 | - $this->di->val((string)$xKey, $xValue); |
|
| 73 | - } |
|
| 74 | - $aOptions = $xConfig->getOption('container.auto', []); |
|
| 75 | - foreach($aOptions as $xValue) |
|
| 76 | - { |
|
| 77 | - // The key is the class name. It must be a string. |
|
| 78 | - $this->di->auto((string)$xValue); |
|
| 79 | - } |
|
| 80 | - $aOptions = $xConfig->getOption('container.alias', []); |
|
| 81 | - foreach($aOptions as $xKey => $xValue) |
|
| 82 | - { |
|
| 83 | - // The key is the class name. It must be a string. |
|
| 84 | - $this->di->alias((string)$xKey, (string)$xValue); |
|
| 85 | - } |
|
| 86 | - } |
|
| 60 | +private function updateContainer(Config $xConfig): void |
|
| 61 | +{ |
|
| 62 | +$aOptions = $xConfig->getOption('container.set', []); |
|
| 63 | +foreach($aOptions as $xKey => $xValue) |
|
| 64 | +{ |
|
| 65 | +// The key is the class name. It must be a string. |
|
| 66 | +$this->di->set((string)$xKey, $xValue); |
|
| 67 | +} |
|
| 68 | +$aOptions = $xConfig->getOption('container.val', []); |
|
| 69 | +foreach($aOptions as $xKey => $xValue) |
|
| 70 | +{ |
|
| 71 | +// The key is the class name. It must be a string. |
|
| 72 | +$this->di->val((string)$xKey, $xValue); |
|
| 73 | +} |
|
| 74 | +$aOptions = $xConfig->getOption('container.auto', []); |
|
| 75 | +foreach($aOptions as $xValue) |
|
| 76 | +{ |
|
| 77 | +// The key is the class name. It must be a string. |
|
| 78 | +$this->di->auto((string)$xValue); |
|
| 79 | +} |
|
| 80 | +$aOptions = $xConfig->getOption('container.alias', []); |
|
| 81 | +foreach($aOptions as $xKey => $xValue) |
|
| 82 | +{ |
|
| 83 | +// The key is the class name. It must be a string. |
|
| 84 | +$this->di->alias((string)$xKey, (string)$xValue); |
|
| 85 | +} |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * Register callables from a section of the config |
| 90 | 90 | * |
| 91 | 91 | * @param array $aOptions The content of the config section |
@@ -94,41 +94,41 @@ discard block |
||
| 94 | 94 | * @return void |
| 95 | 95 | * @throws SetupException |
| 96 | 96 | */ |
| 97 | - private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 98 | - { |
|
| 99 | - foreach($aOptions as $xKey => $xValue) |
|
| 100 | - { |
|
| 101 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 102 | - { |
|
| 103 | - // Register a function without options |
|
| 104 | - $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 97 | +private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 98 | +{ |
|
| 99 | +foreach($aOptions as $xKey => $xValue) |
|
| 100 | +{ |
|
| 101 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 102 | +{ |
|
| 103 | + // Register a function without options |
|
| 104 | + $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 105 | + continue; |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 109 | - { |
|
| 110 | - // Register a function with options |
|
| 111 | - $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 108 | +if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 109 | +{ |
|
| 110 | + // Register a function with options |
|
| 111 | + $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 112 | +} |
|
| 113 | +} |
|
| 114 | +} |
|
| 115 | 115 | |
| 116 | - /** |
|
| 116 | +/** |
|
| 117 | 117 | * Register exceptions handlers |
| 118 | 118 | * |
| 119 | 119 | * @param Config $xConfig |
| 120 | 120 | * |
| 121 | 121 | * @return void |
| 122 | 122 | */ |
| 123 | - private function registerExceptionHandlers(Config $xConfig): void |
|
| 124 | - { |
|
| 125 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 126 | - { |
|
| 127 | - $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 128 | - } |
|
| 129 | - } |
|
| 123 | +private function registerExceptionHandlers(Config $xConfig): void |
|
| 124 | +{ |
|
| 125 | +foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 126 | +{ |
|
| 127 | +$this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 128 | +} |
|
| 129 | +} |
|
| 130 | 130 | |
| 131 | - /** |
|
| 131 | +/** |
|
| 132 | 132 | * Get a callable list from config |
| 133 | 133 | * |
| 134 | 134 | * @param Config $xConfig |
@@ -138,36 +138,36 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return void |
| 140 | 140 | */ |
| 141 | - private function registerCallablesFromConfig(Config $xConfig, |
|
| 142 | - string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 143 | - { |
|
| 144 | - // The callable (directory path, class or function name) can be used as the |
|
| 145 | - // key of the array item, a string as the value of an entry without a key, |
|
| 146 | - // or set with the key $sOptionKey in an array entry without a key. |
|
| 147 | - $aCallables = []; |
|
| 148 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 149 | - { |
|
| 150 | - if(is_string($xKey)) |
|
| 151 | - { |
|
| 152 | - $aCallables[$xKey] = $xValue; |
|
| 153 | - continue; |
|
| 154 | - } |
|
| 155 | - if(is_string($xValue)) |
|
| 156 | - { |
|
| 157 | - $aCallables[] = $xValue; |
|
| 158 | - continue; |
|
| 159 | - } |
|
| 141 | +private function registerCallablesFromConfig(Config $xConfig, |
|
| 142 | +string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 143 | +{ |
|
| 144 | +// The callable (directory path, class or function name) can be used as the |
|
| 145 | +// key of the array item, a string as the value of an entry without a key, |
|
| 146 | +// or set with the key $sOptionKey in an array entry without a key. |
|
| 147 | +$aCallables = []; |
|
| 148 | +foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 149 | +{ |
|
| 150 | +if(is_string($xKey)) |
|
| 151 | +{ |
|
| 152 | + $aCallables[$xKey] = $xValue; |
|
| 153 | + continue; |
|
| 154 | +} |
|
| 155 | +if(is_string($xValue)) |
|
| 156 | +{ |
|
| 157 | + $aCallables[] = $xValue; |
|
| 158 | + continue; |
|
| 159 | +} |
|
| 160 | 160 | |
| 161 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 162 | - { |
|
| 163 | - $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 164 | - } |
|
| 165 | - // Invalid values are ignored. |
|
| 166 | - } |
|
| 167 | - $this->registerCallables($aCallables, $sCallableType); |
|
| 168 | - } |
|
| 161 | +if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 162 | +{ |
|
| 163 | + $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 164 | +} |
|
| 165 | +// Invalid values are ignored. |
|
| 166 | +} |
|
| 167 | +$this->registerCallables($aCallables, $sCallableType); |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * Read and set Jaxon options from a JSON config file |
| 172 | 172 | * |
| 173 | 173 | * @param Config $xConfig The config options |
@@ -175,33 +175,33 @@ discard block |
||
| 175 | 175 | * @return void |
| 176 | 176 | * @throws SetupException |
| 177 | 177 | */ |
| 178 | - private function registerItemsFromConfig(Config $xConfig): void |
|
| 179 | - { |
|
| 180 | - // Set the config for the registered callables. |
|
| 181 | - $this->xRegistry->setPackageConfig($xConfig); |
|
| 178 | +private function registerItemsFromConfig(Config $xConfig): void |
|
| 179 | +{ |
|
| 180 | +// Set the config for the registered callables. |
|
| 181 | +$this->xRegistry->setPackageConfig($xConfig); |
|
| 182 | 182 | |
| 183 | - // Register functions, classes and directories |
|
| 184 | - $this->registerCallablesFromConfig($xConfig, |
|
| 185 | - 'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 186 | - $this->registerCallablesFromConfig($xConfig, |
|
| 187 | - 'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 188 | - $this->registerCallablesFromConfig($xConfig, |
|
| 189 | - 'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 183 | +// Register functions, classes and directories |
|
| 184 | +$this->registerCallablesFromConfig($xConfig, |
|
| 185 | +'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 186 | +$this->registerCallablesFromConfig($xConfig, |
|
| 187 | +'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 188 | +$this->registerCallablesFromConfig($xConfig, |
|
| 189 | +'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 190 | 190 | |
| 191 | - // Unset the current config. |
|
| 192 | - $this->xRegistry->unsetPackageConfig(); |
|
| 191 | +// Unset the current config. |
|
| 192 | +$this->xRegistry->unsetPackageConfig(); |
|
| 193 | 193 | |
| 194 | - // Register the view namespaces |
|
| 195 | - // Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 196 | - // the user defined view namespaces. That's why it is needed here. |
|
| 197 | - $this->xViewRenderer->addNamespaces($xConfig); |
|
| 198 | - // Save items in the DI container |
|
| 199 | - $this->updateContainer($xConfig); |
|
| 200 | - // Register the exception handlers |
|
| 201 | - $this->registerExceptionHandlers($xConfig); |
|
| 202 | - } |
|
| 194 | +// Register the view namespaces |
|
| 195 | +// Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 196 | +// the user defined view namespaces. That's why it is needed here. |
|
| 197 | +$this->xViewRenderer->addNamespaces($xConfig); |
|
| 198 | +// Save items in the DI container |
|
| 199 | +$this->updateContainer($xConfig); |
|
| 200 | +// Register the exception handlers |
|
| 201 | +$this->registerExceptionHandlers($xConfig); |
|
| 202 | +} |
|
| 203 | 203 | |
| 204 | - /** |
|
| 204 | +/** |
|
| 205 | 205 | * Get the options provided by the package library |
| 206 | 206 | * |
| 207 | 207 | * @param class-string $sClassName The package class |
@@ -209,27 +209,27 @@ discard block |
||
| 209 | 209 | * @return Config |
| 210 | 210 | * @throws SetupException |
| 211 | 211 | */ |
| 212 | - private function getPackageLibConfig(string $sClassName): Config |
|
| 213 | - { |
|
| 214 | - // $this->aPackages contains packages config file paths. |
|
| 215 | - $aLibOptions = $sClassName::config(); |
|
| 216 | - if(is_string($aLibOptions)) |
|
| 217 | - { |
|
| 218 | - // A string is supposed to be the path to a config file. |
|
| 219 | - $aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 220 | - } |
|
| 221 | - elseif(!is_array($aLibOptions)) |
|
| 222 | - { |
|
| 223 | - // Otherwise, anything else than an array is not accepted. |
|
| 224 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 225 | - throw new SetupException($sMessage); |
|
| 226 | - } |
|
| 227 | - // Add the package name to the config |
|
| 228 | - $aLibOptions['package'] = $sClassName; |
|
| 229 | - return $this->xConfigManager->newConfig($aLibOptions); |
|
| 230 | - } |
|
| 212 | +private function getPackageLibConfig(string $sClassName): Config |
|
| 213 | +{ |
|
| 214 | +// $this->aPackages contains packages config file paths. |
|
| 215 | +$aLibOptions = $sClassName::config(); |
|
| 216 | +if(is_string($aLibOptions)) |
|
| 217 | +{ |
|
| 218 | +// A string is supposed to be the path to a config file. |
|
| 219 | +$aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 220 | +} |
|
| 221 | +elseif(!is_array($aLibOptions)) |
|
| 222 | +{ |
|
| 223 | +// Otherwise, anything else than an array is not accepted. |
|
| 224 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 225 | +throw new SetupException($sMessage); |
|
| 226 | +} |
|
| 227 | +// Add the package name to the config |
|
| 228 | +$aLibOptions['package'] = $sClassName; |
|
| 229 | +return $this->xConfigManager->newConfig($aLibOptions); |
|
| 230 | +} |
|
| 231 | 231 | |
| 232 | - /** |
|
| 232 | +/** |
|
| 233 | 233 | * Register a package |
| 234 | 234 | * |
| 235 | 235 | * @param class-string $sClassName The package class |
@@ -238,27 +238,27 @@ discard block |
||
| 238 | 238 | * @return void |
| 239 | 239 | * @throws SetupException |
| 240 | 240 | */ |
| 241 | - public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 242 | - { |
|
| 243 | - $sClassName = trim($sClassName, '\\ '); |
|
| 244 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 245 | - { |
|
| 246 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 247 | - throw new SetupException($sMessage); |
|
| 248 | - } |
|
| 241 | +public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 242 | +{ |
|
| 243 | +$sClassName = trim($sClassName, '\\ '); |
|
| 244 | +if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 245 | +{ |
|
| 246 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 247 | +throw new SetupException($sMessage); |
|
| 248 | +} |
|
| 249 | 249 | |
| 250 | - // Register the declarations in the package config. |
|
| 251 | - $xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 252 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 250 | +// Register the declarations in the package config. |
|
| 251 | +$xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 252 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 253 | 253 | |
| 254 | - // Register the package and its options in the DI |
|
| 255 | - $this->di->registerPackage($sClassName, $aUserOptions); |
|
| 254 | +// Register the package and its options in the DI |
|
| 255 | +$this->di->registerPackage($sClassName, $aUserOptions); |
|
| 256 | 256 | |
| 257 | - // Register the package as a code generator. |
|
| 258 | - $this->xPluginManager->registerCodeGenerator($sClassName, 500); |
|
| 259 | - } |
|
| 257 | +// Register the package as a code generator. |
|
| 258 | +$this->xPluginManager->registerCodeGenerator($sClassName, 500); |
|
| 259 | +} |
|
| 260 | 260 | |
| 261 | - /** |
|
| 261 | +/** |
|
| 262 | 262 | * Get a package instance |
| 263 | 263 | * |
| 264 | 264 | * @template T of AbstractPackage |
@@ -266,42 +266,42 @@ discard block |
||
| 266 | 266 | * |
| 267 | 267 | * @return T|null |
| 268 | 268 | */ |
| 269 | - public function getPackage(string $sClassName): ?AbstractPackage |
|
| 270 | - { |
|
| 271 | - $sClassName = trim($sClassName, '\\ '); |
|
| 272 | - return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 273 | - } |
|
| 269 | +public function getPackage(string $sClassName): ?AbstractPackage |
|
| 270 | +{ |
|
| 271 | +$sClassName = trim($sClassName, '\\ '); |
|
| 272 | +return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 273 | +} |
|
| 274 | 274 | |
| 275 | - /** |
|
| 275 | +/** |
|
| 276 | 276 | * Read and set Jaxon options from the config |
| 277 | 277 | * |
| 278 | 278 | * @return void |
| 279 | 279 | * @throws SetupException |
| 280 | 280 | */ |
| 281 | - public function registerFromConfig(): void |
|
| 282 | - { |
|
| 283 | - $xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 284 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 281 | +public function registerFromConfig(): void |
|
| 282 | +{ |
|
| 283 | +$xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 284 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 285 | 285 | |
| 286 | - // Register packages |
|
| 287 | - $aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 288 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 289 | - { |
|
| 290 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 291 | - { |
|
| 292 | - // Register a package without options |
|
| 293 | - $sClassName = $xValue; |
|
| 294 | - $this->registerPackage($sClassName); |
|
| 295 | - continue; |
|
| 296 | - } |
|
| 286 | +// Register packages |
|
| 287 | +$aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 288 | +foreach($aPackageConfig as $xKey => $xValue) |
|
| 289 | +{ |
|
| 290 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 291 | +{ |
|
| 292 | + // Register a package without options |
|
| 293 | + $sClassName = $xValue; |
|
| 294 | + $this->registerPackage($sClassName); |
|
| 295 | + continue; |
|
| 296 | +} |
|
| 297 | 297 | |
| 298 | - if(is_string($xKey) && is_array($xValue)) |
|
| 299 | - { |
|
| 300 | - // Register a package with options |
|
| 301 | - $sClassName = $xKey; |
|
| 302 | - $aPkgOptions = $xValue; |
|
| 303 | - $this->registerPackage($sClassName, $aPkgOptions); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 298 | +if(is_string($xKey) && is_array($xValue)) |
|
| 299 | +{ |
|
| 300 | + // Register a package with options |
|
| 301 | + $sClassName = $xKey; |
|
| 302 | + $aPkgOptions = $xValue; |
|
| 303 | + $this->registerPackage($sClassName, $aPkgOptions); |
|
| 304 | +} |
|
| 305 | +} |
|
| 306 | +} |
|
| 307 | 307 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | |
| 17 | 17 | interface CssCodeGeneratorInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * Get the value to be hashed |
| 21 | 21 | * |
| 22 | 22 | * @return string |
| 23 | 23 | */ |
| 24 | - public function getHash(): string; |
|
| 24 | +public function getHash(): string; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @return CssCode |
| 28 | 28 | */ |
| 29 | - public function getCssCode(): CssCode; |
|
| 29 | +public function getCssCode(): CssCode; |
|
| 30 | 30 | } |
@@ -16,59 +16,59 @@ |
||
| 16 | 16 | |
| 17 | 17 | class JsCode |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @param string $sCode |
| 21 | 21 | * @param array $aFiles |
| 22 | 22 | */ |
| 23 | - public function __construct(protected string $sCode = '', protected array $aFiles = [], |
|
| 24 | - protected string $sCodeBefore = '', protected string $sCodeAfter = '') |
|
| 25 | - {} |
|
| 23 | +public function __construct(protected string $sCode = '', protected array $aFiles = [], |
|
| 24 | +protected string $sCodeBefore = '', protected string $sCodeAfter = '') |
|
| 25 | +{} |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * Get the javascript code to include into the page |
| 29 | 29 | * |
| 30 | 30 | * The code must NOT be enclosed in HTML tags. |
| 31 | 31 | * |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function code(): string |
|
| 35 | - { |
|
| 36 | - return $this->sCode; |
|
| 37 | - } |
|
| 34 | +public function code(): string |
|
| 35 | +{ |
|
| 36 | +return $this->sCode; |
|
| 37 | +} |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * Get the javascript files to include into the page |
| 41 | 41 | * |
| 42 | 42 | * Each entry can be a string or an array with "uri" and "options". |
| 43 | 43 | * |
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | - public function files(): array |
|
| 47 | - { |
|
| 48 | - return $this->aFiles; |
|
| 49 | - } |
|
| 46 | +public function files(): array |
|
| 47 | +{ |
|
| 48 | +return $this->aFiles; |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Get the javascript code to be inserted inline before the main code |
| 53 | 53 | * |
| 54 | 54 | * The code must NOT be enclosed in HTML tags. |
| 55 | 55 | * |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - public function before(): string |
|
| 59 | - { |
|
| 60 | - return $this->sCodeBefore; |
|
| 61 | - } |
|
| 58 | +public function before(): string |
|
| 59 | +{ |
|
| 60 | +return $this->sCodeBefore; |
|
| 61 | +} |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * Get the javascript code to be inserted inline after the main code |
| 65 | 65 | * |
| 66 | 66 | * The code must NOT be enclosed in HTML tags. |
| 67 | 67 | * |
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | - public function after(): string |
|
| 71 | - { |
|
| 72 | - return $this->sCodeAfter; |
|
| 73 | - } |
|
| 70 | +public function after(): string |
|
| 71 | +{ |
|
| 72 | +return $this->sCodeAfter; |
|
| 73 | +} |
|
| 74 | 74 | } |