@@ -258,8 +258,7 @@ |
||
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | return $this->xMetadata; |
| 261 | - } |
|
| 262 | - catch(Exception|Error $e) |
|
| 261 | + } catch(Exception|Error $e) |
|
| 263 | 262 | { |
| 264 | 263 | throw new SetupException($e->getMessage()); |
| 265 | 264 | } |
@@ -214,8 +214,7 @@ |
||
| 214 | 214 | if($this->bOnConfirm) |
| 215 | 215 | { |
| 216 | 216 | $this->aConfirmCommands[] = $xCommand; |
| 217 | - } |
|
| 218 | - else |
|
| 217 | + } else |
|
| 219 | 218 | { |
| 220 | 219 | $this->aCommands[] = $xCommand; |
| 221 | 220 | } |
@@ -218,8 +218,7 @@ |
||
| 218 | 218 | { |
| 219 | 219 | // A string is supposed to be the path to a config file. |
| 220 | 220 | $aLibOptions = $this->xConfigManager->read($aLibOptions); |
| 221 | - } |
|
| 222 | - elseif(!is_array($aLibOptions)) |
|
| 221 | + } elseif(!is_array($aLibOptions)) |
|
| 223 | 222 | { |
| 224 | 223 | // Otherwise, anything else than an array is not accepted. |
| 225 | 224 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class PackageManager |
| 36 | 36 | { |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The constructor |
| 39 | 39 | * |
| 40 | 40 | * @param Container $di |
@@ -46,48 +46,48 @@ discard block |
||
| 46 | 46 | * @param CallbackManager $xCallbackManager |
| 47 | 47 | * @param ComponentRegistry $xRegistry |
| 48 | 48 | */ |
| 49 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | - private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | - private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | - private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | - {} |
|
| 49 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | +private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | +private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | +private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | +{} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Save items in the DI container |
| 57 | 57 | * |
| 58 | 58 | * @param Config $xConfig |
| 59 | 59 | * |
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | - private function updateContainer(Config $xConfig): void |
|
| 63 | - { |
|
| 64 | - $aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | - foreach($aOptions as $xKey => $xValue) |
|
| 66 | - { |
|
| 67 | - // The key is the class name. It must be a string. |
|
| 68 | - $this->di->set((string)$xKey, $xValue); |
|
| 69 | - } |
|
| 70 | - $aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | - foreach($aOptions as $xKey => $xValue) |
|
| 72 | - { |
|
| 73 | - // The key is the class name. It must be a string. |
|
| 74 | - $this->di->val((string)$xKey, $xValue); |
|
| 75 | - } |
|
| 76 | - $aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | - foreach($aOptions as $xValue) |
|
| 78 | - { |
|
| 79 | - // The key is the class name. It must be a string. |
|
| 80 | - $this->di->auto((string)$xValue); |
|
| 81 | - } |
|
| 82 | - $aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | - foreach($aOptions as $xKey => $xValue) |
|
| 84 | - { |
|
| 85 | - // The key is the class name. It must be a string. |
|
| 86 | - $this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | - } |
|
| 88 | - } |
|
| 62 | +private function updateContainer(Config $xConfig): void |
|
| 63 | +{ |
|
| 64 | +$aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | +foreach($aOptions as $xKey => $xValue) |
|
| 66 | +{ |
|
| 67 | +// The key is the class name. It must be a string. |
|
| 68 | +$this->di->set((string)$xKey, $xValue); |
|
| 69 | +} |
|
| 70 | +$aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | +foreach($aOptions as $xKey => $xValue) |
|
| 72 | +{ |
|
| 73 | +// The key is the class name. It must be a string. |
|
| 74 | +$this->di->val((string)$xKey, $xValue); |
|
| 75 | +} |
|
| 76 | +$aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | +foreach($aOptions as $xValue) |
|
| 78 | +{ |
|
| 79 | +// The key is the class name. It must be a string. |
|
| 80 | +$this->di->auto((string)$xValue); |
|
| 81 | +} |
|
| 82 | +$aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | +foreach($aOptions as $xKey => $xValue) |
|
| 84 | +{ |
|
| 85 | +// The key is the class name. It must be a string. |
|
| 86 | +$this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | +} |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register callables from a section of the config |
| 92 | 92 | * |
| 93 | 93 | * @param array $aOptions The content of the config section |
@@ -96,41 +96,41 @@ discard block |
||
| 96 | 96 | * @return void |
| 97 | 97 | * @throws SetupException |
| 98 | 98 | */ |
| 99 | - private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | - { |
|
| 101 | - foreach($aOptions as $xKey => $xValue) |
|
| 102 | - { |
|
| 103 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | - { |
|
| 105 | - // Register a function without options |
|
| 106 | - $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 99 | +private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | +{ |
|
| 101 | +foreach($aOptions as $xKey => $xValue) |
|
| 102 | +{ |
|
| 103 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | +{ |
|
| 105 | + // Register a function without options |
|
| 106 | + $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | + continue; |
|
| 108 | +} |
|
| 109 | 109 | |
| 110 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | - { |
|
| 112 | - // Register a function with options |
|
| 113 | - $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | +if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | +{ |
|
| 112 | + // Register a function with options |
|
| 113 | + $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | +} |
|
| 115 | +} |
|
| 116 | +} |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | +/** |
|
| 119 | 119 | * Register exceptions handlers |
| 120 | 120 | * |
| 121 | 121 | * @param Config $xConfig |
| 122 | 122 | * |
| 123 | 123 | * @return void |
| 124 | 124 | */ |
| 125 | - private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | - { |
|
| 127 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | - { |
|
| 129 | - $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | - } |
|
| 131 | - } |
|
| 125 | +private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | +{ |
|
| 127 | +foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | +{ |
|
| 129 | +$this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | +} |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get a callable list from config |
| 135 | 135 | * |
| 136 | 136 | * @param Config $xConfig |
@@ -140,36 +140,36 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | - private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | - string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | - { |
|
| 146 | - // The callable (directory path, class or function name) can be used as the |
|
| 147 | - // key of the array item, a string as the value of an entry without a key, |
|
| 148 | - // or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | - $aCallables = []; |
|
| 150 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | - { |
|
| 152 | - if(is_string($xKey)) |
|
| 153 | - { |
|
| 154 | - $aCallables[$xKey] = $xValue; |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - if(is_string($xValue)) |
|
| 158 | - { |
|
| 159 | - $aCallables[] = $xValue; |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 143 | +private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | +string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | +{ |
|
| 146 | +// The callable (directory path, class or function name) can be used as the |
|
| 147 | +// key of the array item, a string as the value of an entry without a key, |
|
| 148 | +// or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | +$aCallables = []; |
|
| 150 | +foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | +{ |
|
| 152 | +if(is_string($xKey)) |
|
| 153 | +{ |
|
| 154 | + $aCallables[$xKey] = $xValue; |
|
| 155 | + continue; |
|
| 156 | +} |
|
| 157 | +if(is_string($xValue)) |
|
| 158 | +{ |
|
| 159 | + $aCallables[] = $xValue; |
|
| 160 | + continue; |
|
| 161 | +} |
|
| 162 | 162 | |
| 163 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | - { |
|
| 165 | - $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | - } |
|
| 167 | - // Invalid values are ignored. |
|
| 168 | - } |
|
| 169 | - $this->registerCallables($aCallables, $sCallableType); |
|
| 170 | - } |
|
| 163 | +if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | +{ |
|
| 165 | + $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | +} |
|
| 167 | +// Invalid values are ignored. |
|
| 168 | +} |
|
| 169 | +$this->registerCallables($aCallables, $sCallableType); |
|
| 170 | +} |
|
| 171 | 171 | |
| 172 | - /** |
|
| 172 | +/** |
|
| 173 | 173 | * Read and set Jaxon options from a JSON config file |
| 174 | 174 | * |
| 175 | 175 | * @param Config $xConfig The config options |
@@ -177,33 +177,33 @@ discard block |
||
| 177 | 177 | * @return void |
| 178 | 178 | * @throws SetupException |
| 179 | 179 | */ |
| 180 | - private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | - { |
|
| 182 | - // Set the config for the registered callables. |
|
| 183 | - $this->xRegistry->setPackageConfig($xConfig); |
|
| 180 | +private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | +{ |
|
| 182 | +// Set the config for the registered callables. |
|
| 183 | +$this->xRegistry->setPackageConfig($xConfig); |
|
| 184 | 184 | |
| 185 | - // Register functions, classes and directories |
|
| 186 | - $this->registerCallablesFromConfig($xConfig, |
|
| 187 | - 'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | - $this->registerCallablesFromConfig($xConfig, |
|
| 189 | - 'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | - $this->registerCallablesFromConfig($xConfig, |
|
| 191 | - 'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 185 | +// Register functions, classes and directories |
|
| 186 | +$this->registerCallablesFromConfig($xConfig, |
|
| 187 | +'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | +$this->registerCallablesFromConfig($xConfig, |
|
| 189 | +'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | +$this->registerCallablesFromConfig($xConfig, |
|
| 191 | +'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 192 | 192 | |
| 193 | - // Unset the current config. |
|
| 194 | - $this->xRegistry->unsetPackageConfig(); |
|
| 193 | +// Unset the current config. |
|
| 194 | +$this->xRegistry->unsetPackageConfig(); |
|
| 195 | 195 | |
| 196 | - // Register the view namespaces |
|
| 197 | - // Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | - // the user defined view namespaces. That's why it is needed here. |
|
| 199 | - $this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | - // Save items in the DI container |
|
| 201 | - $this->updateContainer($xConfig); |
|
| 202 | - // Register the exception handlers |
|
| 203 | - $this->registerExceptionHandlers($xConfig); |
|
| 204 | - } |
|
| 196 | +// Register the view namespaces |
|
| 197 | +// Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | +// the user defined view namespaces. That's why it is needed here. |
|
| 199 | +$this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | +// Save items in the DI container |
|
| 201 | +$this->updateContainer($xConfig); |
|
| 202 | +// Register the exception handlers |
|
| 203 | +$this->registerExceptionHandlers($xConfig); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Get the options provided by the package library |
| 208 | 208 | * |
| 209 | 209 | * @param class-string $sClassName The package class |
@@ -211,27 +211,27 @@ discard block |
||
| 211 | 211 | * @return Config |
| 212 | 212 | * @throws SetupException |
| 213 | 213 | */ |
| 214 | - private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | - { |
|
| 216 | - // $this->aPackages contains packages config file paths. |
|
| 217 | - $aLibOptions = $sClassName::config(); |
|
| 218 | - if(is_string($aLibOptions)) |
|
| 219 | - { |
|
| 220 | - // A string is supposed to be the path to a config file. |
|
| 221 | - $aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | - } |
|
| 223 | - elseif(!is_array($aLibOptions)) |
|
| 224 | - { |
|
| 225 | - // Otherwise, anything else than an array is not accepted. |
|
| 226 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | - throw new SetupException($sMessage); |
|
| 228 | - } |
|
| 229 | - // Add the package name to the config |
|
| 230 | - $aLibOptions['package'] = $sClassName; |
|
| 231 | - return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | - } |
|
| 214 | +private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | +{ |
|
| 216 | +// $this->aPackages contains packages config file paths. |
|
| 217 | +$aLibOptions = $sClassName::config(); |
|
| 218 | +if(is_string($aLibOptions)) |
|
| 219 | +{ |
|
| 220 | +// A string is supposed to be the path to a config file. |
|
| 221 | +$aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | +} |
|
| 223 | +elseif(!is_array($aLibOptions)) |
|
| 224 | +{ |
|
| 225 | +// Otherwise, anything else than an array is not accepted. |
|
| 226 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | +throw new SetupException($sMessage); |
|
| 228 | +} |
|
| 229 | +// Add the package name to the config |
|
| 230 | +$aLibOptions['package'] = $sClassName; |
|
| 231 | +return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 234 | +/** |
|
| 235 | 235 | * Register a package |
| 236 | 236 | * |
| 237 | 237 | * @param class-string $sClassName The package class |
@@ -240,27 +240,27 @@ discard block |
||
| 240 | 240 | * @return void |
| 241 | 241 | * @throws SetupException |
| 242 | 242 | */ |
| 243 | - public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | - { |
|
| 245 | - $sClassName = trim($sClassName, '\\ '); |
|
| 246 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | - { |
|
| 248 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | - throw new SetupException($sMessage); |
|
| 250 | - } |
|
| 243 | +public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | +{ |
|
| 245 | +$sClassName = trim($sClassName, '\\ '); |
|
| 246 | +if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | +{ |
|
| 248 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | +throw new SetupException($sMessage); |
|
| 250 | +} |
|
| 251 | 251 | |
| 252 | - // Register the declarations in the package config. |
|
| 253 | - $xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 252 | +// Register the declarations in the package config. |
|
| 253 | +$xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 255 | 255 | |
| 256 | - // Register the package and its options in the DI |
|
| 257 | - $this->di->registerPackage($sClassName, $aUserOptions); |
|
| 256 | +// Register the package and its options in the DI |
|
| 257 | +$this->di->registerPackage($sClassName, $aUserOptions); |
|
| 258 | 258 | |
| 259 | - // Register the package as a code generator. |
|
| 260 | - $this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | - } |
|
| 259 | +// Register the package as a code generator. |
|
| 260 | +$this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | +} |
|
| 262 | 262 | |
| 263 | - /** |
|
| 263 | +/** |
|
| 264 | 264 | * Get a package instance |
| 265 | 265 | * |
| 266 | 266 | * @template T of AbstractPackage |
@@ -268,42 +268,42 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return T|null |
| 270 | 270 | */ |
| 271 | - public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | - { |
|
| 273 | - $sClassName = trim($sClassName, '\\ '); |
|
| 274 | - return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | - } |
|
| 271 | +public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | +{ |
|
| 273 | +$sClassName = trim($sClassName, '\\ '); |
|
| 274 | +return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | +} |
|
| 276 | 276 | |
| 277 | - /** |
|
| 277 | +/** |
|
| 278 | 278 | * Read and set Jaxon options from the config |
| 279 | 279 | * |
| 280 | 280 | * @return void |
| 281 | 281 | * @throws SetupException |
| 282 | 282 | */ |
| 283 | - public function registerFromConfig(): void |
|
| 284 | - { |
|
| 285 | - $xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 283 | +public function registerFromConfig(): void |
|
| 284 | +{ |
|
| 285 | +$xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 287 | 287 | |
| 288 | - // Register packages |
|
| 289 | - $aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | - { |
|
| 292 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | - { |
|
| 294 | - // Register a package without options |
|
| 295 | - $sClassName = $xValue; |
|
| 296 | - $this->registerPackage($sClassName); |
|
| 297 | - continue; |
|
| 298 | - } |
|
| 288 | +// Register packages |
|
| 289 | +$aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | +foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | +{ |
|
| 292 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | +{ |
|
| 294 | + // Register a package without options |
|
| 295 | + $sClassName = $xValue; |
|
| 296 | + $this->registerPackage($sClassName); |
|
| 297 | + continue; |
|
| 298 | +} |
|
| 299 | 299 | |
| 300 | - if(is_string($xKey) && is_array($xValue)) |
|
| 301 | - { |
|
| 302 | - // Register a package with options |
|
| 303 | - $sClassName = $xKey; |
|
| 304 | - $aPkgOptions = $xValue; |
|
| 305 | - $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 300 | +if(is_string($xKey) && is_array($xValue)) |
|
| 301 | +{ |
|
| 302 | + // Register a package with options |
|
| 303 | + $sClassName = $xKey; |
|
| 304 | + $aPkgOptions = $xValue; |
|
| 305 | + $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | +} |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | } |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | if(is_string($xOptions)) |
| 93 | 93 | { |
| 94 | 94 | $xOptions = ['include' => $xOptions]; |
| 95 | - } |
|
| 96 | - elseif(!is_array($xOptions)) |
|
| 95 | + } elseif(!is_array($xOptions)) |
|
| 97 | 96 | { |
| 98 | 97 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 99 | 98 | } |
@@ -236,8 +235,7 @@ discard block |
||
| 236 | 235 | { |
| 237 | 236 | /** @var CallableFunction */ |
| 238 | 237 | $xFunction = $this->getCallable($sRequestedFunction); |
| 239 | - } |
|
| 240 | - catch(Exception $e) |
|
| 238 | + } catch(Exception $e) |
|
| 241 | 239 | { |
| 242 | 240 | // Unable to find the requested function |
| 243 | 241 | $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
@@ -246,8 +244,7 @@ discard block |
||
| 246 | 244 | try |
| 247 | 245 | { |
| 248 | 246 | $xFunction->call($this->xTarget->args()); |
| 249 | - } |
|
| 250 | - catch(Exception $e) |
|
| 247 | + } catch(Exception $e) |
|
| 251 | 248 | { |
| 252 | 249 | // Unable to execute the requested function |
| 253 | 250 | $this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
@@ -69,23 +69,19 @@ discard block |
||
| 69 | 69 | try |
| 70 | 70 | { |
| 71 | 71 | return $this->xConfigReader->read($sConfigFile); |
| 72 | - } |
|
| 73 | - catch(YamlExtension $e) |
|
| 72 | + } catch(YamlExtension $e) |
|
| 74 | 73 | { |
| 75 | 74 | $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
| 76 | 75 | throw new SetupException($sMessage); |
| 77 | - } |
|
| 78 | - catch(FileExtension $e) |
|
| 76 | + } catch(FileExtension $e) |
|
| 79 | 77 | { |
| 80 | 78 | $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
| 81 | 79 | throw new SetupException($sMessage); |
| 82 | - } |
|
| 83 | - catch(FileAccess $e) |
|
| 80 | + } catch(FileAccess $e) |
|
| 84 | 81 | { |
| 85 | 82 | $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
| 86 | 83 | throw new SetupException($sMessage); |
| 87 | - } |
|
| 88 | - catch(FileContent $e) |
|
| 84 | + } catch(FileContent $e) |
|
| 89 | 85 | { |
| 90 | 86 | $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
| 91 | 87 | throw new SetupException($sMessage); |
@@ -110,8 +106,7 @@ discard block |
||
| 110 | 106 | ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
| 111 | 107 | // Call the config change listeners. |
| 112 | 108 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 113 | - } |
|
| 114 | - catch(DataDepth $e) |
|
| 109 | + } catch(DataDepth $e) |
|
| 115 | 110 | { |
| 116 | 111 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 117 | 112 | 'key' => $e->sPrefix, |
@@ -139,8 +134,7 @@ discard block |
||
| 139 | 134 | // Call the config change listeners. |
| 140 | 135 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 141 | 136 | return $this->xLibConfig->changed(); |
| 142 | - } |
|
| 143 | - catch(DataDepth $e) |
|
| 137 | + } catch(DataDepth $e) |
|
| 144 | 138 | { |
| 145 | 139 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 146 | 140 | 'key' => $e->sPrefix, |
@@ -246,8 +240,7 @@ discard block |
||
| 246 | 240 | // Call the config change listeners. |
| 247 | 241 | $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
| 248 | 242 | return $this->xAppConfig->changed(); |
| 249 | - } |
|
| 250 | - catch(DataDepth $e) |
|
| 243 | + } catch(DataDepth $e) |
|
| 251 | 244 | { |
| 252 | 245 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 253 | 246 | 'key' => $e->sPrefix, |
@@ -296,8 +289,7 @@ discard block |
||
| 296 | 289 | try |
| 297 | 290 | { |
| 298 | 291 | return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
| 299 | - } |
|
| 300 | - catch(DataDepth $e) |
|
| 292 | + } catch(DataDepth $e) |
|
| 301 | 293 | { |
| 302 | 294 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 303 | 295 | 'key' => $e->sPrefix, |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class ConfigManager |
| 31 | 31 | { |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @var Config |
| 34 | 34 | */ |
| 35 | - protected $xLibConfig; |
|
| 35 | +protected $xLibConfig; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @var Config |
| 39 | 39 | */ |
| 40 | - protected $xAppConfig; |
|
| 40 | +protected $xAppConfig; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * The constructor |
| 44 | 44 | * |
| 45 | 45 | * @param array $aDefaultOptions |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | * @param ConfigSetter $xConfigSetter |
| 49 | 49 | * @param ConfigEventManager $xEventManager |
| 50 | 50 | */ |
| 51 | - public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | - private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | - private ConfigEventManager $xEventManager) |
|
| 54 | - { |
|
| 55 | - $this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | - $this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | - } |
|
| 51 | +public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | +private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | +private ConfigEventManager $xEventManager) |
|
| 54 | +{ |
|
| 55 | +$this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | +$this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * Read a config file |
| 61 | 61 | * |
| 62 | 62 | * @param string $sConfigFile |
@@ -64,35 +64,35 @@ discard block |
||
| 64 | 64 | * @return array |
| 65 | 65 | * @throws SetupException |
| 66 | 66 | */ |
| 67 | - public function read(string $sConfigFile): array |
|
| 68 | - { |
|
| 69 | - try |
|
| 70 | - { |
|
| 71 | - return $this->xConfigReader->read($sConfigFile); |
|
| 72 | - } |
|
| 73 | - catch(YamlExtension $e) |
|
| 74 | - { |
|
| 75 | - $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | - throw new SetupException($sMessage); |
|
| 77 | - } |
|
| 78 | - catch(FileExtension $e) |
|
| 79 | - { |
|
| 80 | - $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | - throw new SetupException($sMessage); |
|
| 82 | - } |
|
| 83 | - catch(FileAccess $e) |
|
| 84 | - { |
|
| 85 | - $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | - throw new SetupException($sMessage); |
|
| 87 | - } |
|
| 88 | - catch(FileContent $e) |
|
| 89 | - { |
|
| 90 | - $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | - throw new SetupException($sMessage); |
|
| 92 | - } |
|
| 93 | - } |
|
| 67 | +public function read(string $sConfigFile): array |
|
| 68 | +{ |
|
| 69 | +try |
|
| 70 | +{ |
|
| 71 | +return $this->xConfigReader->read($sConfigFile); |
|
| 72 | +} |
|
| 73 | +catch(YamlExtension $e) |
|
| 74 | +{ |
|
| 75 | +$sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | +throw new SetupException($sMessage); |
|
| 77 | +} |
|
| 78 | +catch(FileExtension $e) |
|
| 79 | +{ |
|
| 80 | +$sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | +throw new SetupException($sMessage); |
|
| 82 | +} |
|
| 83 | +catch(FileAccess $e) |
|
| 84 | +{ |
|
| 85 | +$sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | +throw new SetupException($sMessage); |
|
| 87 | +} |
|
| 88 | +catch(FileContent $e) |
|
| 89 | +{ |
|
| 90 | +$sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | +throw new SetupException($sMessage); |
|
| 92 | +} |
|
| 93 | +} |
|
| 94 | 94 | |
| 95 | - /** |
|
| 95 | +/** |
|
| 96 | 96 | * Read options from a config file and set the library config |
| 97 | 97 | * |
| 98 | 98 | * @param string $sConfigFile The full path to the config file |
@@ -101,27 +101,27 @@ discard block |
||
| 101 | 101 | * @return void |
| 102 | 102 | * @throws SetupException |
| 103 | 103 | */ |
| 104 | - public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | - { |
|
| 106 | - try |
|
| 107 | - { |
|
| 108 | - // Read the options and save in the config. |
|
| 109 | - $this->xLibConfig = $this->xConfigSetter |
|
| 110 | - ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | - // Call the config change listeners. |
|
| 112 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | - } |
|
| 114 | - catch(DataDepth $e) |
|
| 115 | - { |
|
| 116 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | - 'key' => $e->sPrefix, |
|
| 118 | - 'depth' => $e->nDepth, |
|
| 119 | - ]); |
|
| 120 | - throw new SetupException($sMessage); |
|
| 121 | - } |
|
| 122 | - } |
|
| 104 | +public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | +{ |
|
| 106 | +try |
|
| 107 | +{ |
|
| 108 | +// Read the options and save in the config. |
|
| 109 | +$this->xLibConfig = $this->xConfigSetter |
|
| 110 | + ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | +// Call the config change listeners. |
|
| 112 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | +} |
|
| 114 | +catch(DataDepth $e) |
|
| 115 | +{ |
|
| 116 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | + 'key' => $e->sPrefix, |
|
| 118 | + 'depth' => $e->nDepth, |
|
| 119 | +]); |
|
| 120 | +throw new SetupException($sMessage); |
|
| 121 | +} |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Set the config options of the library |
| 126 | 126 | * |
| 127 | 127 | * @param array $aOptions |
@@ -130,27 +130,27 @@ discard block |
||
| 130 | 130 | * @return bool |
| 131 | 131 | * @throws SetupException |
| 132 | 132 | */ |
| 133 | - public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | - { |
|
| 135 | - try |
|
| 136 | - { |
|
| 137 | - $this->xLibConfig = $this->xConfigSetter |
|
| 138 | - ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | - // Call the config change listeners. |
|
| 140 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | - return $this->xLibConfig->changed(); |
|
| 142 | - } |
|
| 143 | - catch(DataDepth $e) |
|
| 144 | - { |
|
| 145 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | - 'key' => $e->sPrefix, |
|
| 147 | - 'depth' => $e->nDepth, |
|
| 148 | - ]); |
|
| 149 | - throw new SetupException($sMessage); |
|
| 150 | - } |
|
| 151 | - } |
|
| 133 | +public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | +{ |
|
| 135 | +try |
|
| 136 | +{ |
|
| 137 | +$this->xLibConfig = $this->xConfigSetter |
|
| 138 | + ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | +// Call the config change listeners. |
|
| 140 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | +return $this->xLibConfig->changed(); |
|
| 142 | +} |
|
| 143 | +catch(DataDepth $e) |
|
| 144 | +{ |
|
| 145 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | + 'key' => $e->sPrefix, |
|
| 147 | + 'depth' => $e->nDepth, |
|
| 148 | +]); |
|
| 149 | +throw new SetupException($sMessage); |
|
| 150 | +} |
|
| 151 | +} |
|
| 152 | 152 | |
| 153 | - /** |
|
| 153 | +/** |
|
| 154 | 154 | * Set the value of a config option |
| 155 | 155 | * |
| 156 | 156 | * @param string $sName The option name |
@@ -158,15 +158,15 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return void |
| 160 | 160 | */ |
| 161 | - public function setOption(string $sName, $xValue): void |
|
| 162 | - { |
|
| 163 | - $this->xLibConfig = $this->xConfigSetter |
|
| 164 | - ->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | - // Call the config change listeners. |
|
| 166 | - $this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | - } |
|
| 161 | +public function setOption(string $sName, $xValue): void |
|
| 162 | +{ |
|
| 163 | +$this->xLibConfig = $this->xConfigSetter |
|
| 164 | +->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | +// Call the config change listeners. |
|
| 166 | +$this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * Get the value of a config option |
| 171 | 171 | * |
| 172 | 172 | * @param string $sName The option name |
@@ -174,36 +174,36 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return mixed |
| 176 | 176 | */ |
| 177 | - public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | - { |
|
| 179 | - return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | - } |
|
| 177 | +public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | +{ |
|
| 179 | +return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Check the presence of a config option |
| 184 | 184 | * |
| 185 | 185 | * @param string $sName The option name |
| 186 | 186 | * |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - public function hasOption(string $sName): bool |
|
| 190 | - { |
|
| 191 | - return $this->xLibConfig->hasOption($sName); |
|
| 192 | - } |
|
| 189 | +public function hasOption(string $sName): bool |
|
| 190 | +{ |
|
| 191 | +return $this->xLibConfig->hasOption($sName); |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * Get the names of the options matching a given prefix |
| 196 | 196 | * |
| 197 | 197 | * @param string $sPrefix The prefix to match |
| 198 | 198 | * |
| 199 | 199 | * @return array |
| 200 | 200 | */ |
| 201 | - public function getOptionNames(string $sPrefix): array |
|
| 202 | - { |
|
| 203 | - return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | - } |
|
| 201 | +public function getOptionNames(string $sPrefix): array |
|
| 202 | +{ |
|
| 203 | +return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Set the value of a config option |
| 208 | 208 | * |
| 209 | 209 | * @param string $sName The option name |
@@ -211,25 +211,25 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | - public function setAppOption(string $sName, $xValue): void |
|
| 215 | - { |
|
| 216 | - $this->xAppConfig = $this->xConfigSetter |
|
| 217 | - ->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | - // Call the config change listeners. |
|
| 219 | - $this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | - } |
|
| 214 | +public function setAppOption(string $sName, $xValue): void |
|
| 215 | +{ |
|
| 216 | +$this->xAppConfig = $this->xConfigSetter |
|
| 217 | +->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | +// Call the config change listeners. |
|
| 219 | +$this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | +} |
|
| 221 | 221 | |
| 222 | - /** |
|
| 222 | +/** |
|
| 223 | 223 | * Get the application config |
| 224 | 224 | * |
| 225 | 225 | * @return Config |
| 226 | 226 | */ |
| 227 | - public function getAppConfig(): Config |
|
| 228 | - { |
|
| 229 | - return $this->xAppConfig; |
|
| 230 | - } |
|
| 227 | +public function getAppConfig(): Config |
|
| 228 | +{ |
|
| 229 | +return $this->xAppConfig; |
|
| 230 | +} |
|
| 231 | 231 | |
| 232 | - /** |
|
| 232 | +/** |
|
| 233 | 233 | * Set the application config options |
| 234 | 234 | * |
| 235 | 235 | * @param array $aAppOptions |
@@ -237,27 +237,27 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | - { |
|
| 242 | - try |
|
| 243 | - { |
|
| 244 | - $this->xAppConfig = $this->xConfigSetter |
|
| 245 | - ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | - // Call the config change listeners. |
|
| 247 | - $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | - return $this->xAppConfig->changed(); |
|
| 249 | - } |
|
| 250 | - catch(DataDepth $e) |
|
| 251 | - { |
|
| 252 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | - 'key' => $e->sPrefix, |
|
| 254 | - 'depth' => $e->nDepth, |
|
| 255 | - ]); |
|
| 256 | - throw new SetupException($sMessage); |
|
| 257 | - } |
|
| 258 | - } |
|
| 240 | +public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | +{ |
|
| 242 | +try |
|
| 243 | +{ |
|
| 244 | +$this->xAppConfig = $this->xConfigSetter |
|
| 245 | + ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | +// Call the config change listeners. |
|
| 247 | +$this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | +return $this->xAppConfig->changed(); |
|
| 249 | +} |
|
| 250 | +catch(DataDepth $e) |
|
| 251 | +{ |
|
| 252 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | + 'key' => $e->sPrefix, |
|
| 254 | + 'depth' => $e->nDepth, |
|
| 255 | +]); |
|
| 256 | +throw new SetupException($sMessage); |
|
| 257 | +} |
|
| 258 | +} |
|
| 259 | 259 | |
| 260 | - /** |
|
| 260 | +/** |
|
| 261 | 261 | * Get the value of an application config option |
| 262 | 262 | * |
| 263 | 263 | * @param string $sName The option name |
@@ -265,24 +265,24 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return mixed |
| 267 | 267 | */ |
| 268 | - public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | - { |
|
| 270 | - return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | - } |
|
| 268 | +public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | +{ |
|
| 270 | +return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | +} |
|
| 272 | 272 | |
| 273 | - /** |
|
| 273 | +/** |
|
| 274 | 274 | * Check the presence of an application config option |
| 275 | 275 | * |
| 276 | 276 | * @param string $sName The option name |
| 277 | 277 | * |
| 278 | 278 | * @return bool |
| 279 | 279 | */ |
| 280 | - public function hasAppOption(string $sName): bool |
|
| 281 | - { |
|
| 282 | - return $this->xAppConfig->hasOption($sName); |
|
| 283 | - } |
|
| 280 | +public function hasAppOption(string $sName): bool |
|
| 281 | +{ |
|
| 282 | +return $this->xAppConfig->hasOption($sName); |
|
| 283 | +} |
|
| 284 | 284 | |
| 285 | - /** |
|
| 285 | +/** |
|
| 286 | 286 | * Create a new the config object |
| 287 | 287 | * |
| 288 | 288 | * @param array $aOptions The options array |
@@ -291,54 +291,54 @@ discard block |
||
| 291 | 291 | * @return Config |
| 292 | 292 | * @throws SetupException |
| 293 | 293 | */ |
| 294 | - public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | - { |
|
| 296 | - try |
|
| 297 | - { |
|
| 298 | - return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | - } |
|
| 300 | - catch(DataDepth $e) |
|
| 301 | - { |
|
| 302 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | - 'key' => $e->sPrefix, |
|
| 304 | - 'depth' => $e->nDepth, |
|
| 305 | - ]); |
|
| 306 | - throw new SetupException($sMessage); |
|
| 307 | - } |
|
| 308 | - } |
|
| 294 | +public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | +{ |
|
| 296 | +try |
|
| 297 | +{ |
|
| 298 | +return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | +} |
|
| 300 | +catch(DataDepth $e) |
|
| 301 | +{ |
|
| 302 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | + 'key' => $e->sPrefix, |
|
| 304 | + 'depth' => $e->nDepth, |
|
| 305 | +]); |
|
| 306 | +throw new SetupException($sMessage); |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | |
| 310 | - /** |
|
| 310 | +/** |
|
| 311 | 311 | * @param string $sClassName |
| 312 | 312 | * |
| 313 | 313 | * @return void |
| 314 | 314 | */ |
| 315 | - public function addLibEventListener(string $sClassName): void |
|
| 316 | - { |
|
| 317 | - $this->xEventManager->addLibConfigListener($sClassName); |
|
| 318 | - } |
|
| 315 | +public function addLibEventListener(string $sClassName): void |
|
| 316 | +{ |
|
| 317 | +$this->xEventManager->addLibConfigListener($sClassName); |
|
| 318 | +} |
|
| 319 | 319 | |
| 320 | - /** |
|
| 320 | +/** |
|
| 321 | 321 | * @param string $sClassName |
| 322 | 322 | * |
| 323 | 323 | * @return void |
| 324 | 324 | */ |
| 325 | - public function addAppEventListener(string $sClassName): void |
|
| 326 | - { |
|
| 327 | - $this->xEventManager->addAppConfigListener($sClassName); |
|
| 328 | - } |
|
| 325 | +public function addAppEventListener(string $sClassName): void |
|
| 326 | +{ |
|
| 327 | +$this->xEventManager->addAppConfigListener($sClassName); |
|
| 328 | +} |
|
| 329 | 329 | |
| 330 | - /** |
|
| 330 | +/** |
|
| 331 | 331 | * Make the helpers functions available in the global namespace. |
| 332 | 332 | * |
| 333 | 333 | * @param bool $bForce |
| 334 | 334 | * |
| 335 | 335 | * @return void |
| 336 | 336 | */ |
| 337 | - public function globals(bool $bForce = false): void |
|
| 338 | - { |
|
| 339 | - if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 340 | - { |
|
| 341 | - require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 342 | - } |
|
| 343 | - } |
|
| 337 | +public function globals(bool $bForce = false): void |
|
| 338 | +{ |
|
| 339 | +if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 340 | +{ |
|
| 341 | +require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 342 | +} |
|
| 343 | +} |
|
| 344 | 344 | } |
@@ -6,53 +6,53 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class PageComponent extends NodeComponent |
| 8 | 8 | { |
| 9 | - /** |
|
| 9 | +/** |
|
| 10 | 10 | * The current page number. |
| 11 | 11 | * |
| 12 | 12 | * @var int |
| 13 | 13 | */ |
| 14 | - private int $currentPage = 1; |
|
| 14 | +private int $currentPage = 1; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 16 | +/** |
|
| 17 | 17 | * Get the total number of items to paginate. |
| 18 | 18 | * |
| 19 | 19 | * @return int |
| 20 | 20 | */ |
| 21 | - abstract protected function count(): int; |
|
| 21 | +abstract protected function count(): int; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Get the max number of items per page. |
| 25 | 25 | * |
| 26 | 26 | * @return int |
| 27 | 27 | */ |
| 28 | - abstract protected function limit(): int; |
|
| 28 | +abstract protected function limit(): int; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * Get the paginator for the component. |
| 32 | 32 | * |
| 33 | 33 | * @param int $pageNumber |
| 34 | 34 | * |
| 35 | 35 | * @return Paginator |
| 36 | 36 | */ |
| 37 | - protected function paginator(int $pageNumber): Paginator |
|
| 38 | - { |
|
| 39 | - return $this->cl(Component\Pagination::class) |
|
| 40 | - // Use the js class name as component item identifier. |
|
| 41 | - ->item($this->rq()->_class()) |
|
| 42 | - ->paginator($pageNumber > 0 ? $pageNumber : 1, $this->limit(), $this->count()) |
|
| 43 | - // This callback will receive the final value of the current page number. |
|
| 44 | - ->page(function(int $currentPage) { |
|
| 45 | - $this->currentPage = $currentPage; |
|
| 46 | - }); |
|
| 47 | - } |
|
| 37 | +protected function paginator(int $pageNumber): Paginator |
|
| 38 | +{ |
|
| 39 | +return $this->cl(Component\Pagination::class) |
|
| 40 | +// Use the js class name as component item identifier. |
|
| 41 | +->item($this->rq()->_class()) |
|
| 42 | +->paginator($pageNumber > 0 ? $pageNumber : 1, $this->limit(), $this->count()) |
|
| 43 | +// This callback will receive the final value of the current page number. |
|
| 44 | +->page(function(int $currentPage) { |
|
| 45 | + $this->currentPage = $currentPage; |
|
| 46 | +}); |
|
| 47 | +} |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * Get the current page number |
| 51 | 51 | * |
| 52 | 52 | * @return int |
| 53 | 53 | */ |
| 54 | - protected function currentPage(): int |
|
| 55 | - { |
|
| 56 | - return $this->currentPage; |
|
| 57 | - } |
|
| 54 | +protected function currentPage(): int |
|
| 55 | +{ |
|
| 56 | +return $this->currentPage; |
|
| 57 | +} |
|
| 58 | 58 | } |
@@ -6,81 +6,81 @@ |
||
| 6 | 6 | |
| 7 | 7 | trait PageDatabagTrait |
| 8 | 8 | { |
| 9 | - /** |
|
| 9 | +/** |
|
| 10 | 10 | * The current page number. |
| 11 | 11 | * |
| 12 | 12 | * @var int |
| 13 | 13 | */ |
| 14 | - private int $currentPage = 1; |
|
| 14 | +private int $currentPage = 1; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 16 | +/** |
|
| 17 | 17 | * Get the pagination databag name. |
| 18 | 18 | * |
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | - abstract protected function bagName(): string; |
|
| 21 | +abstract protected function bagName(): string; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Get the pagination databag attribute. |
| 25 | 25 | * |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - abstract protected function bagAttr(): string; |
|
| 28 | +abstract protected function bagAttr(): string; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * Get the page number. |
| 32 | 32 | * |
| 33 | 33 | * @param int $pageNumber |
| 34 | 34 | * |
| 35 | 35 | * @return int |
| 36 | 36 | */ |
| 37 | - private function getPageNumber(int $pageNumber): int |
|
| 38 | - { |
|
| 39 | - // If no page number is provided, then get the value from the databag. |
|
| 40 | - return $pageNumber > 0 ? $pageNumber : |
|
| 41 | - (int)$this->bag($this->bagName())->get($this->bagAttr(), 1); |
|
| 42 | - } |
|
| 37 | +private function getPageNumber(int $pageNumber): int |
|
| 38 | +{ |
|
| 39 | +// If no page number is provided, then get the value from the databag. |
|
| 40 | +return $pageNumber > 0 ? $pageNumber : |
|
| 41 | +(int)$this->bag($this->bagName())->get($this->bagAttr(), 1); |
|
| 42 | +} |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * Set the page number. |
| 46 | 46 | * |
| 47 | 47 | * @param int $currentPage |
| 48 | 48 | * |
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | - private function setCurrentPage(int $currentPage): void |
|
| 52 | - { |
|
| 53 | - // Save the current page in the databag. |
|
| 54 | - $this->bag($this->bagName())->set($this->bagAttr(), $currentPage); |
|
| 55 | - $this->currentPage = $currentPage; |
|
| 56 | - } |
|
| 51 | +private function setCurrentPage(int $currentPage): void |
|
| 52 | +{ |
|
| 53 | +// Save the current page in the databag. |
|
| 54 | +$this->bag($this->bagName())->set($this->bagAttr(), $currentPage); |
|
| 55 | +$this->currentPage = $currentPage; |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Get the paginator for the component. |
| 60 | 60 | * |
| 61 | 61 | * @param int $pageNumber |
| 62 | 62 | * |
| 63 | 63 | * @return Paginator |
| 64 | 64 | */ |
| 65 | - protected function paginator(int $pageNumber): Paginator |
|
| 66 | - { |
|
| 67 | - return $this->cl(Component\Pagination::class) |
|
| 68 | - // Use the js class name as component item identifier. |
|
| 69 | - ->item($this->rq()->_class()) |
|
| 70 | - ->paginator($this->getPageNumber($pageNumber), $this->limit(), $this->count()) |
|
| 71 | - // This callback will receive the final value of the current page number. |
|
| 72 | - ->page(function(int $currentPage) { |
|
| 73 | - $this->setCurrentPage($currentPage); |
|
| 74 | - }); |
|
| 75 | - } |
|
| 65 | +protected function paginator(int $pageNumber): Paginator |
|
| 66 | +{ |
|
| 67 | +return $this->cl(Component\Pagination::class) |
|
| 68 | +// Use the js class name as component item identifier. |
|
| 69 | +->item($this->rq()->_class()) |
|
| 70 | +->paginator($this->getPageNumber($pageNumber), $this->limit(), $this->count()) |
|
| 71 | +// This callback will receive the final value of the current page number. |
|
| 72 | +->page(function(int $currentPage) { |
|
| 73 | + $this->setCurrentPage($currentPage); |
|
| 74 | +}); |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * Get the current page number |
| 79 | 79 | * |
| 80 | 80 | * @return int |
| 81 | 81 | */ |
| 82 | - protected function currentPage(): int |
|
| 83 | - { |
|
| 84 | - return $this->currentPage; |
|
| 85 | - } |
|
| 82 | +protected function currentPage(): int |
|
| 83 | +{ |
|
| 84 | +return $this->currentPage; |
|
| 85 | +} |
|
| 86 | 86 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function cl(string $sClassName): mixed |
| 34 | 34 | { |
| 35 | - return \Jaxon\cl($sClassName); |
|
| 35 | +return \Jaxon\cl($sClassName); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | function rq(string $sClassName = ''): JxnCall |
| 46 | 46 | { |
| 47 | - return \Jaxon\rq($sClassName); |
|
| 47 | +return \Jaxon\rq($sClassName); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function jo(string $sJsObject = ''): JsObjectCall |
| 58 | 58 | { |
| 59 | - return \Jaxon\jo($sJsObject); |
|
| 59 | +return \Jaxon\jo($sJsObject); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | function jq(string $sPath = '', $xContext = null): JqSelectorCall |
| 71 | 71 | { |
| 72 | - return \Jaxon\jq($sPath, $xContext); |
|
| 72 | +return \Jaxon\jq($sPath, $xContext); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function je(string $sElementId = ''): JsSelectorCall |
| 83 | 83 | { |
| 84 | - return \Jaxon\je($sElementId); |
|
| 84 | +return \Jaxon\je($sElementId); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -91,5 +91,5 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function attr(): HtmlAttrHelper |
| 93 | 93 | { |
| 94 | - return \Jaxon\attr(); |
|
| 94 | +return \Jaxon\attr(); |
|
| 95 | 95 | } |
@@ -142,8 +142,7 @@ |
||
| 142 | 142 | { |
| 143 | 143 | $this->xResponseManager->error($e->getMessage()); |
| 144 | 144 | $this->xCallbackManager->onInvalid($e); |
| 145 | - } |
|
| 146 | - catch(Exception $e) |
|
| 145 | + } catch(Exception $e) |
|
| 147 | 146 | { |
| 148 | 147 | $this->xResponseManager->error($e->getMessage()); |
| 149 | 148 | $this->xCallbackManager->onError($e); |