@@ -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 | } |
@@ -38,81 +38,81 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | class ResponseManager |
| 40 | 40 | { |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * The current response object that will be sent back to the browser |
| 43 | 43 | * once the request processing phase is complete |
| 44 | 44 | * |
| 45 | 45 | * @var AjaxResponse|null |
| 46 | 46 | */ |
| 47 | - private $xResponse = null; |
|
| 47 | +private $xResponse = null; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * The error message |
| 51 | 51 | * |
| 52 | 52 | * @var string |
| 53 | 53 | */ |
| 54 | - private $sErrorMessage = ''; |
|
| 54 | +private $sErrorMessage = ''; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * The debug messages |
| 58 | 58 | * |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - private $aDebugMessages = []; |
|
| 61 | +private $aDebugMessages = []; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * The commands that will be sent to the browser in the response |
| 65 | 65 | * |
| 66 | 66 | * @var array |
| 67 | 67 | */ |
| 68 | - protected $aCommands = []; |
|
| 68 | +protected $aCommands = []; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 70 | +/** |
|
| 71 | 71 | * If the commands beeing added are to be confirmed |
| 72 | 72 | * |
| 73 | 73 | * @var bool |
| 74 | 74 | */ |
| 75 | - private $bOnConfirm = false; |
|
| 75 | +private $bOnConfirm = false; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * The commands that will be sent to the browser in the response |
| 79 | 79 | * |
| 80 | 80 | * @var array |
| 81 | 81 | */ |
| 82 | - private $aConfirmCommands = []; |
|
| 82 | +private $aConfirmCommands = []; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * @param Container $di |
| 86 | 86 | * @param Translator $xTranslator |
| 87 | 87 | * @param string $sCharacterEncoding |
| 88 | 88 | */ |
| 89 | - public function __construct(private Container $di, |
|
| 90 | - private Translator $xTranslator, private string $sCharacterEncoding) |
|
| 91 | - {} |
|
| 89 | +public function __construct(private Container $di, |
|
| 90 | +private Translator $xTranslator, private string $sCharacterEncoding) |
|
| 91 | +{} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Get the configured character encoding |
| 95 | 95 | * |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getCharacterEncoding(): string |
|
| 99 | - { |
|
| 100 | - return $this->sCharacterEncoding; |
|
| 101 | - } |
|
| 98 | +public function getCharacterEncoding(): string |
|
| 99 | +{ |
|
| 100 | +return $this->sCharacterEncoding; |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Convert to string |
| 105 | 105 | * |
| 106 | 106 | * @param mixed $xData |
| 107 | 107 | * |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public function str($xData): string |
|
| 111 | - { |
|
| 112 | - return trim((string)$xData, " \t\n"); |
|
| 113 | - } |
|
| 110 | +public function str($xData): string |
|
| 111 | +{ |
|
| 112 | +return trim((string)$xData, " \t\n"); |
|
| 113 | +} |
|
| 114 | 114 | |
| 115 | - /** |
|
| 115 | +/** |
|
| 116 | 116 | * Get a translated string |
| 117 | 117 | * |
| 118 | 118 | * @param string $sText The key of the translated string |
@@ -120,81 +120,81 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return string |
| 122 | 122 | */ |
| 123 | - public function trans(string $sText, array $aPlaceHolders = []): string |
|
| 124 | - { |
|
| 125 | - return $this->xTranslator->trans($sText, $aPlaceHolders); |
|
| 126 | - } |
|
| 123 | +public function trans(string $sText, array $aPlaceHolders = []): string |
|
| 124 | +{ |
|
| 125 | +return $this->xTranslator->trans($sText, $aPlaceHolders); |
|
| 126 | +} |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Set the error message |
| 130 | 130 | * |
| 131 | 131 | * @param string $sErrorMessage |
| 132 | 132 | * |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - public function setErrorMessage(string $sErrorMessage): void |
|
| 136 | - { |
|
| 137 | - $this->sErrorMessage = $sErrorMessage; |
|
| 138 | - } |
|
| 135 | +public function setErrorMessage(string $sErrorMessage): void |
|
| 136 | +{ |
|
| 137 | +$this->sErrorMessage = $sErrorMessage; |
|
| 138 | +} |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | +/** |
|
| 141 | 141 | * Get the error message |
| 142 | 142 | * |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function getErrorMessage(): string |
|
| 146 | - { |
|
| 147 | - return $this->sErrorMessage; |
|
| 148 | - } |
|
| 145 | +public function getErrorMessage(): string |
|
| 146 | +{ |
|
| 147 | +return $this->sErrorMessage; |
|
| 148 | +} |
|
| 149 | 149 | |
| 150 | - /** |
|
| 150 | +/** |
|
| 151 | 151 | * Get the commands in the response |
| 152 | 152 | * |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - public function getCommands(): array |
|
| 156 | - { |
|
| 157 | - return $this->aCommands; |
|
| 158 | - } |
|
| 155 | +public function getCommands(): array |
|
| 156 | +{ |
|
| 157 | +return $this->aCommands; |
|
| 158 | +} |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * Get the number of commands in the response |
| 162 | 162 | * |
| 163 | 163 | * @return int |
| 164 | 164 | */ |
| 165 | - public function getCommandCount(): int |
|
| 166 | - { |
|
| 167 | - return count($this->aCommands); |
|
| 168 | - } |
|
| 165 | +public function getCommandCount(): int |
|
| 166 | +{ |
|
| 167 | +return count($this->aCommands); |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * Clear all the commands already added to the response |
| 172 | 172 | * |
| 173 | 173 | * @return void |
| 174 | 174 | */ |
| 175 | - public function clearCommands(): void |
|
| 176 | - { |
|
| 177 | - $this->aCommands = []; |
|
| 178 | - } |
|
| 175 | +public function clearCommands(): void |
|
| 176 | +{ |
|
| 177 | +$this->aCommands = []; |
|
| 178 | +} |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | +/** |
|
| 181 | 181 | * @param array|JsonSerializable $aArgs The command arguments |
| 182 | 182 | * @param bool $bRemoveEmpty If true, remove empty arguments |
| 183 | 183 | * |
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array |
|
| 187 | - { |
|
| 188 | - if(!$bRemoveEmpty) |
|
| 189 | - { |
|
| 190 | - return $aArgs; |
|
| 191 | - } |
|
| 192 | - return array_filter($aArgs, function($xArg) { |
|
| 193 | - return !empty($xArg); |
|
| 194 | - }); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 186 | +private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array |
|
| 187 | +{ |
|
| 188 | +if(!$bRemoveEmpty) |
|
| 189 | +{ |
|
| 190 | +return $aArgs; |
|
| 191 | +} |
|
| 192 | +return array_filter($aArgs, function($xArg) { |
|
| 193 | +return !empty($xArg); |
|
| 194 | +}); |
|
| 195 | +} |
|
| 196 | + |
|
| 197 | +/** |
|
| 198 | 198 | * Add a response command to the array of commands |
| 199 | 199 | * |
| 200 | 200 | * @param string $sName The command name |
@@ -203,25 +203,25 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @return Command |
| 205 | 205 | */ |
| 206 | - public function addCommand(string $sName, array|JsonSerializable $aArgs, |
|
| 207 | - bool $bRemoveEmpty = false): Command |
|
| 208 | - { |
|
| 209 | - $xCommand = new Command([ |
|
| 210 | - 'name' => $this->str($sName), |
|
| 211 | - 'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty), |
|
| 212 | - ]); |
|
| 213 | - if($this->bOnConfirm) |
|
| 214 | - { |
|
| 215 | - $this->aConfirmCommands[] = $xCommand; |
|
| 216 | - } |
|
| 217 | - else |
|
| 218 | - { |
|
| 219 | - $this->aCommands[] = $xCommand; |
|
| 220 | - } |
|
| 221 | - return $xCommand; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 206 | +public function addCommand(string $sName, array|JsonSerializable $aArgs, |
|
| 207 | +bool $bRemoveEmpty = false): Command |
|
| 208 | +{ |
|
| 209 | +$xCommand = new Command([ |
|
| 210 | +'name' => $this->str($sName), |
|
| 211 | +'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty), |
|
| 212 | +]); |
|
| 213 | +if($this->bOnConfirm) |
|
| 214 | +{ |
|
| 215 | +$this->aConfirmCommands[] = $xCommand; |
|
| 216 | +} |
|
| 217 | +else |
|
| 218 | +{ |
|
| 219 | +$this->aCommands[] = $xCommand; |
|
| 220 | +} |
|
| 221 | +return $xCommand; |
|
| 222 | +} |
|
| 223 | + |
|
| 224 | +/** |
|
| 225 | 225 | * Response command that prompts user with [ok] [cancel] style message box |
| 226 | 226 | * |
| 227 | 227 | * The provided closure will be called with a response object as unique parameter. |
@@ -236,29 +236,29 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return self |
| 238 | 238 | */ |
| 239 | - public function addConfirmCommand(string $sName, Closure $fConfirm, |
|
| 240 | - string $sQuestion, array $aArgs = []): self |
|
| 241 | - { |
|
| 242 | - if($this->bOnConfirm) |
|
| 243 | - { |
|
| 244 | - throw new AppException($this->xTranslator->trans('errors.app.confirm.nested')); |
|
| 245 | - } |
|
| 246 | - $this->bOnConfirm = true; |
|
| 247 | - $fConfirm(); |
|
| 248 | - $this->bOnConfirm = false; |
|
| 249 | - if(($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 250 | - { |
|
| 251 | - $aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs); |
|
| 252 | - $aCommand['count'] = $nCommandCount; |
|
| 253 | - // The confirm command must be inserted before the commands to be confirmed. |
|
| 254 | - $this->addCommand($sName, $aCommand); |
|
| 255 | - $this->aCommands = array_merge($this->aCommands, $this->aConfirmCommands); |
|
| 256 | - $this->aConfirmCommands = []; |
|
| 257 | - } |
|
| 258 | - return $this; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 239 | +public function addConfirmCommand(string $sName, Closure $fConfirm, |
|
| 240 | +string $sQuestion, array $aArgs = []): self |
|
| 241 | +{ |
|
| 242 | +if($this->bOnConfirm) |
|
| 243 | +{ |
|
| 244 | +throw new AppException($this->xTranslator->trans('errors.app.confirm.nested')); |
|
| 245 | +} |
|
| 246 | +$this->bOnConfirm = true; |
|
| 247 | +$fConfirm(); |
|
| 248 | +$this->bOnConfirm = false; |
|
| 249 | +if(($nCommandCount = count($this->aConfirmCommands)) > 0) |
|
| 250 | +{ |
|
| 251 | +$aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs); |
|
| 252 | +$aCommand['count'] = $nCommandCount; |
|
| 253 | +// The confirm command must be inserted before the commands to be confirmed. |
|
| 254 | +$this->addCommand($sName, $aCommand); |
|
| 255 | +$this->aCommands = array_merge($this->aCommands, $this->aConfirmCommands); |
|
| 256 | +$this->aConfirmCommands = []; |
|
| 257 | +} |
|
| 258 | +return $this; |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +/** |
|
| 262 | 262 | * Add a command to display an alert message to the user |
| 263 | 263 | * |
| 264 | 264 | * @param string $sName The command name |
@@ -269,56 +269,56 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return self |
| 271 | 271 | */ |
| 272 | - public function addAlertCommand(string $sName, string $sMessage, array $aArgs = []): self |
|
| 273 | - { |
|
| 274 | - $aCommand = $this->di->getDialogCommand()->info($this->str($sMessage), $aArgs); |
|
| 275 | - $this->addCommand($sName, $aCommand); |
|
| 276 | - return $this; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 272 | +public function addAlertCommand(string $sName, string $sMessage, array $aArgs = []): self |
|
| 273 | +{ |
|
| 274 | +$aCommand = $this->di->getDialogCommand()->info($this->str($sMessage), $aArgs); |
|
| 275 | +$this->addCommand($sName, $aCommand); |
|
| 276 | +return $this; |
|
| 277 | +} |
|
| 278 | + |
|
| 279 | +/** |
|
| 280 | 280 | * Get the response to the Jaxon request |
| 281 | 281 | * |
| 282 | 282 | * @return Response |
| 283 | 283 | */ |
| 284 | - public function getResponse(): Response |
|
| 285 | - { |
|
| 286 | - return $this->di->getResponse(); |
|
| 287 | - } |
|
| 284 | +public function getResponse(): Response |
|
| 285 | +{ |
|
| 286 | +return $this->di->getResponse(); |
|
| 287 | +} |
|
| 288 | 288 | |
| 289 | - /** |
|
| 289 | +/** |
|
| 290 | 290 | * Create a new Jaxon response |
| 291 | 291 | * |
| 292 | 292 | * @return Response |
| 293 | 293 | */ |
| 294 | - public function newResponse(): Response |
|
| 295 | - { |
|
| 296 | - return $this->xResponse = $this->di->newResponse(); |
|
| 297 | - } |
|
| 294 | +public function newResponse(): Response |
|
| 295 | +{ |
|
| 296 | +return $this->xResponse = $this->di->newResponse(); |
|
| 297 | +} |
|
| 298 | 298 | |
| 299 | - /** |
|
| 299 | +/** |
|
| 300 | 300 | * Get the Jaxon ajax response returned |
| 301 | 301 | * |
| 302 | 302 | * @return AjaxResponse |
| 303 | 303 | */ |
| 304 | - public function ajaxResponse(): AjaxResponse |
|
| 305 | - { |
|
| 306 | - return $this->xResponse ?: $this->di->getResponse(); |
|
| 307 | - } |
|
| 304 | +public function ajaxResponse(): AjaxResponse |
|
| 305 | +{ |
|
| 306 | +return $this->xResponse ?: $this->di->getResponse(); |
|
| 307 | +} |
|
| 308 | 308 | |
| 309 | - /** |
|
| 309 | +/** |
|
| 310 | 310 | * Create a new reponse for a Jaxon component |
| 311 | 311 | * |
| 312 | 312 | * @param JxnCall $xJxnCall |
| 313 | 313 | * |
| 314 | 314 | * @return NodeResponse |
| 315 | 315 | */ |
| 316 | - public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 317 | - { |
|
| 318 | - return $this->di->newNodeResponse($xJxnCall); |
|
| 319 | - } |
|
| 316 | +public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 317 | +{ |
|
| 318 | +return $this->di->newNodeResponse($xJxnCall); |
|
| 319 | +} |
|
| 320 | 320 | |
| 321 | - /** |
|
| 321 | +/** |
|
| 322 | 322 | * Appends a debug message on the end of the debug message queue |
| 323 | 323 | * |
| 324 | 324 | * Debug messages will be sent to the client with the normal response |
@@ -328,66 +328,66 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return void |
| 330 | 330 | */ |
| 331 | - public function debug(string $sMessage): void |
|
| 332 | - { |
|
| 333 | - $this->aDebugMessages[] = $sMessage; |
|
| 334 | - } |
|
| 331 | +public function debug(string $sMessage): void |
|
| 332 | +{ |
|
| 333 | +$this->aDebugMessages[] = $sMessage; |
|
| 334 | +} |
|
| 335 | 335 | |
| 336 | - /** |
|
| 336 | +/** |
|
| 337 | 337 | * Clear the response and appends a debug message on the end of the debug message queue |
| 338 | 338 | * |
| 339 | 339 | * @param string $sMessage The debug message |
| 340 | 340 | * |
| 341 | 341 | * @return void |
| 342 | 342 | */ |
| 343 | - public function error(string $sMessage): void |
|
| 344 | - { |
|
| 345 | - $this->clearCommands(); |
|
| 346 | - $this->debug($sMessage); |
|
| 347 | - } |
|
| 343 | +public function error(string $sMessage): void |
|
| 344 | +{ |
|
| 345 | +$this->clearCommands(); |
|
| 346 | +$this->debug($sMessage); |
|
| 347 | +} |
|
| 348 | 348 | |
| 349 | - /** |
|
| 349 | +/** |
|
| 350 | 350 | * Prints the debug messages into the current response object |
| 351 | 351 | * |
| 352 | 352 | * @return void |
| 353 | 353 | */ |
| 354 | - public function printDebug() |
|
| 355 | - { |
|
| 356 | - foreach($this->aDebugMessages as $sMessage) |
|
| 357 | - { |
|
| 358 | - $this->addCommand('script.debug', ['message' => $this->str($sMessage)]); |
|
| 359 | - } |
|
| 360 | - // $this->aDebugMessages = []; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 354 | +public function printDebug() |
|
| 355 | +{ |
|
| 356 | +foreach($this->aDebugMessages as $sMessage) |
|
| 357 | +{ |
|
| 358 | +$this->addCommand('script.debug', ['message' => $this->str($sMessage)]); |
|
| 359 | +} |
|
| 360 | +// $this->aDebugMessages = []; |
|
| 361 | +} |
|
| 362 | + |
|
| 363 | +/** |
|
| 364 | 364 | * Get the content type of the HTTP response |
| 365 | 365 | * |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function getContentType(): string |
|
| 369 | - { |
|
| 370 | - return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : |
|
| 371 | - $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 372 | - } |
|
| 368 | +public function getContentType(): string |
|
| 369 | +{ |
|
| 370 | +return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : |
|
| 371 | +$this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
| 372 | +} |
|
| 373 | 373 | |
| 374 | - /** |
|
| 374 | +/** |
|
| 375 | 375 | * Get the JSON output of the response |
| 376 | 376 | * |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function getOutput(): string |
|
| 380 | - { |
|
| 381 | - return $this->getResponse()->getOutput(); |
|
| 382 | - } |
|
| 379 | +public function getOutput(): string |
|
| 380 | +{ |
|
| 381 | +return $this->getResponse()->getOutput(); |
|
| 382 | +} |
|
| 383 | 383 | |
| 384 | - /** |
|
| 384 | +/** |
|
| 385 | 385 | * Get the debug messages |
| 386 | 386 | * |
| 387 | 387 | * @return array |
| 388 | 388 | */ |
| 389 | - public function getDebugMessages(): array |
|
| 390 | - { |
|
| 391 | - return $this->aDebugMessages; |
|
| 392 | - } |
|
| 389 | +public function getDebugMessages(): array |
|
| 390 | +{ |
|
| 391 | +return $this->aDebugMessages; |
|
| 392 | +} |
|
| 393 | 393 | } |
@@ -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, |
@@ -203,12 +203,12 @@ |
||
| 203 | 203 | $sCode = match($sType) { |
| 204 | 204 | 'html' => jaxon()->package($sClass)?->getHtml() ?? '', |
| 205 | 205 | 'ready' => jaxon()->package($sClass)?->getReadyScript() ?? '', |
| 206 | - default => '' |
|
| 207 | - }; |
|
| 208 | - $sCode = trim($sCode); |
|
| 206 | +default => '' |
|
| 207 | +}; |
|
| 208 | +$sCode = trim($sCode); |
|
| 209 | 209 | |
| 210 | - return $sType !== 'ready' || $sCode === '' ? $sCode : |
|
| 211 | - // Call the ready code with the jaxon.dom.ready function. |
|
| 212 | - "jaxon.dom.ready(() => $sCode)"; |
|
| 213 | - } |
|
| 210 | +return $sType !== 'ready' || $sCode === '' ? $sCode : |
|
| 211 | +// Call the ready code with the jaxon.dom.ready function. |
|
| 212 | +"jaxon.dom.ready(() => $sCode)"; |
|
| 213 | +} |
|
| 214 | 214 | } |
@@ -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 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function jaxon(): JaxonLib |
| 32 | 32 | { |
| 33 | - return JaxonLib::getInstance(); |
|
| 33 | +return JaxonLib::getInstance(); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | function cl(string $sClassName): mixed |
| 46 | 46 | { |
| 47 | - return jaxon()->cdi()->makeComponent($sClassName); |
|
| 47 | +return jaxon()->cdi()->makeComponent($sClassName); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function rq(string $sClassName = ''): JxnCall |
| 58 | 58 | { |
| 59 | - return jaxon()->di()->getCallFactory()->rq($sClassName); |
|
| 59 | +return jaxon()->di()->getCallFactory()->rq($sClassName); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function jo(string $sJsObject = ''): JsObjectCall |
| 70 | 70 | { |
| 71 | - return jaxon()->di()->getCallFactory()->jo($sJsObject); |
|
| 71 | +return jaxon()->di()->getCallFactory()->jo($sJsObject); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function jq(string $sPath = '', $xContext = null): JqSelectorCall |
| 83 | 83 | { |
| 84 | - return jaxon()->di()->getCallFactory()->jq($sPath, $xContext); |
|
| 84 | +return jaxon()->di()->getCallFactory()->jq($sPath, $xContext); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | function je(string $sElementId = ''): JsSelectorCall |
| 95 | 95 | { |
| 96 | - return jaxon()->di()->getCallFactory()->je($sElementId); |
|
| 96 | +return jaxon()->di()->getCallFactory()->je($sElementId); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | function attr(): HtmlAttrHelper |
| 105 | 105 | { |
| 106 | - return jaxon()->di()->getHtmlAttrHelper(); |
|
| 106 | +return jaxon()->di()->getHtmlAttrHelper(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -114,5 +114,5 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | function pm(): ParameterFactory |
| 116 | 116 | { |
| 117 | - return jaxon()->di()->getParameterFactory(); |
|
| 117 | +return jaxon()->di()->getParameterFactory(); |
|
| 118 | 118 | } |