@@ -22,50 +22,50 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | class PsrFactory |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The container |
| 27 | 27 | * |
| 28 | 28 | * @var Container |
| 29 | 29 | */ |
| 30 | - protected $di; |
|
| 30 | +protected $di; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * The constructor |
| 34 | 34 | * |
| 35 | 35 | * @param Container $di |
| 36 | 36 | */ |
| 37 | - public function __construct(Container $di) |
|
| 38 | - { |
|
| 39 | - $this->di = $di; |
|
| 40 | - } |
|
| 37 | +public function __construct(Container $di) |
|
| 38 | +{ |
|
| 39 | +$this->di = $di; |
|
| 40 | +} |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * Set the logger |
| 44 | 44 | * |
| 45 | 45 | * @param LoggerInterface $xLogger |
| 46 | 46 | * |
| 47 | 47 | * @return $this |
| 48 | 48 | */ |
| 49 | - public function logger(LoggerInterface $xLogger): PsrFactory |
|
| 50 | - { |
|
| 51 | - $this->di->setLogger($xLogger); |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 49 | +public function logger(LoggerInterface $xLogger): PsrFactory |
|
| 50 | +{ |
|
| 51 | +$this->di->setLogger($xLogger); |
|
| 52 | +return $this; |
|
| 53 | +} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Set the container |
| 57 | 57 | * |
| 58 | 58 | * @param ContainerInterface $xContainer |
| 59 | 59 | * |
| 60 | 60 | * @return $this |
| 61 | 61 | */ |
| 62 | - public function container(ContainerInterface $xContainer): PsrFactory |
|
| 63 | - { |
|
| 64 | - $this->di->setContainer($xContainer); |
|
| 65 | - return $this; |
|
| 66 | - } |
|
| 62 | +public function container(ContainerInterface $xContainer): PsrFactory |
|
| 63 | +{ |
|
| 64 | +$this->di->setContainer($xContainer); |
|
| 65 | +return $this; |
|
| 66 | +} |
|
| 67 | 67 | |
| 68 | - /** |
|
| 68 | +/** |
|
| 69 | 69 | * Add a view renderer with an id |
| 70 | 70 | * |
| 71 | 71 | * @param string $sRenderer The renderer name |
@@ -74,41 +74,41 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return $this |
| 76 | 76 | */ |
| 77 | - public function view(string $sRenderer, string $sExtension, Closure $xClosure): PsrFactory |
|
| 78 | - { |
|
| 79 | - $this->di->getViewRenderer()->setDefaultRenderer($sRenderer, $sExtension, $xClosure); |
|
| 80 | - return $this; |
|
| 81 | - } |
|
| 77 | +public function view(string $sRenderer, string $sExtension, Closure $xClosure): PsrFactory |
|
| 78 | +{ |
|
| 79 | +$this->di->getViewRenderer()->setDefaultRenderer($sRenderer, $sExtension, $xClosure); |
|
| 80 | +return $this; |
|
| 81 | +} |
|
| 82 | 82 | |
| 83 | - /** |
|
| 83 | +/** |
|
| 84 | 84 | * Get the Jaxon ajax PSR request handler |
| 85 | 85 | * |
| 86 | 86 | * @return PsrRequestHandler |
| 87 | 87 | */ |
| 88 | - public function handler(): PsrRequestHandler |
|
| 89 | - { |
|
| 90 | - return $this->di->getPsrRequestHandler(); |
|
| 91 | - } |
|
| 88 | +public function handler(): PsrRequestHandler |
|
| 89 | +{ |
|
| 90 | +return $this->di->getPsrRequestHandler(); |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Get the Jaxon config PSR middleware |
| 95 | 95 | * |
| 96 | 96 | * @param string $sConfigFile |
| 97 | 97 | * |
| 98 | 98 | * @return PsrConfigMiddleware |
| 99 | 99 | */ |
| 100 | - public function config(string $sConfigFile): PsrConfigMiddleware |
|
| 101 | - { |
|
| 102 | - return $this->di->getPsrConfigMiddleware($sConfigFile); |
|
| 103 | - } |
|
| 100 | +public function config(string $sConfigFile): PsrConfigMiddleware |
|
| 101 | +{ |
|
| 102 | +return $this->di->getPsrConfigMiddleware($sConfigFile); |
|
| 103 | +} |
|
| 104 | 104 | |
| 105 | - /** |
|
| 105 | +/** |
|
| 106 | 106 | * Get the Jaxon ajax PSR middleware |
| 107 | 107 | * |
| 108 | 108 | * @return PsrAjaxMiddleware |
| 109 | 109 | */ |
| 110 | - public function ajax(): PsrAjaxMiddleware |
|
| 111 | - { |
|
| 112 | - return $this->di->getPsrAjaxMiddleware(); |
|
| 113 | - } |
|
| 110 | +public function ajax(): PsrAjaxMiddleware |
|
| 111 | +{ |
|
| 112 | +return $this->di->getPsrAjaxMiddleware(); |
|
| 113 | +} |
|
| 114 | 114 | } |
@@ -27,159 +27,159 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class CallbackManager |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * The response manager. |
| 32 | 32 | * |
| 33 | 33 | * @var ResponseManager |
| 34 | 34 | */ |
| 35 | - private $xResponseManager; |
|
| 35 | +private $xResponseManager; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The callbacks to run after booting the library |
| 39 | 39 | * |
| 40 | 40 | * @var callable[] |
| 41 | 41 | */ |
| 42 | - protected $aBootCallbacks = []; |
|
| 42 | +protected $aBootCallbacks = []; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * The callbacks to run before processing the request |
| 46 | 46 | * |
| 47 | 47 | * @var callable[] |
| 48 | 48 | */ |
| 49 | - protected $aBeforeCallbacks = []; |
|
| 49 | +protected $aBeforeCallbacks = []; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * The callbacks to run after processing the request |
| 53 | 53 | * |
| 54 | 54 | * @var callable[] |
| 55 | 55 | */ |
| 56 | - protected $aAfterCallbacks = []; |
|
| 56 | +protected $aAfterCallbacks = []; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * The callbacks to run in case of invalid request |
| 60 | 60 | * |
| 61 | 61 | * @var callable[] |
| 62 | 62 | */ |
| 63 | - protected $aInvalidCallbacks = []; |
|
| 63 | +protected $aInvalidCallbacks = []; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * The callbacks to run in case of error |
| 67 | 67 | * |
| 68 | 68 | * @var callable[] |
| 69 | 69 | */ |
| 70 | - protected $aErrorCallbacks = []; |
|
| 70 | +protected $aErrorCallbacks = []; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * The callbacks to run in case of exception |
| 74 | 74 | * |
| 75 | 75 | * @var callable[][] |
| 76 | 76 | */ |
| 77 | - protected $aExceptionCallbacks = []; |
|
| 77 | +protected $aExceptionCallbacks = []; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * The callbacks to run when a class is instanced |
| 81 | 81 | * |
| 82 | 82 | * @var callable[] |
| 83 | 83 | */ |
| 84 | - protected $aInitCallbacks = []; |
|
| 84 | +protected $aInitCallbacks = []; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * @param ResponseManager $xResponseManager |
| 88 | 88 | */ |
| 89 | - public function __construct(ResponseManager $xResponseManager) |
|
| 90 | - { |
|
| 91 | - $this->xResponseManager = $xResponseManager; |
|
| 92 | - } |
|
| 89 | +public function __construct(ResponseManager $xResponseManager) |
|
| 90 | +{ |
|
| 91 | +$this->xResponseManager = $xResponseManager; |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * Get the library booting callbacks, and reset the array. |
| 96 | 96 | * |
| 97 | 97 | * @return callable[] |
| 98 | 98 | */ |
| 99 | - public function popBootCallbacks(): array |
|
| 100 | - { |
|
| 101 | - if(empty($this->aBootCallbacks)) |
|
| 102 | - { |
|
| 103 | - return []; |
|
| 104 | - } |
|
| 105 | - $aCallbacks = $this->aBootCallbacks; |
|
| 106 | - $this->aBootCallbacks = []; |
|
| 107 | - return $aCallbacks; |
|
| 108 | - } |
|
| 99 | +public function popBootCallbacks(): array |
|
| 100 | +{ |
|
| 101 | +if(empty($this->aBootCallbacks)) |
|
| 102 | +{ |
|
| 103 | +return []; |
|
| 104 | +} |
|
| 105 | +$aCallbacks = $this->aBootCallbacks; |
|
| 106 | +$this->aBootCallbacks = []; |
|
| 107 | +return $aCallbacks; |
|
| 108 | +} |
|
| 109 | 109 | |
| 110 | - /** |
|
| 110 | +/** |
|
| 111 | 111 | * Get the exception callbacks. |
| 112 | 112 | * |
| 113 | 113 | * @param Exception $xException The exception class |
| 114 | 114 | * |
| 115 | 115 | * @return callable[] |
| 116 | 116 | */ |
| 117 | - private function getExceptionCallbacks(Exception $xException): array |
|
| 118 | - { |
|
| 119 | - $aExceptionCallbacks = []; |
|
| 120 | - foreach($this->aExceptionCallbacks as $sExClass => $aCallbacks) |
|
| 121 | - { |
|
| 122 | - if(is_a($xException, $sExClass)) |
|
| 123 | - { |
|
| 124 | - $aExceptionCallbacks = array_merge($aExceptionCallbacks, $aCallbacks); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - return array_values($aExceptionCallbacks); |
|
| 128 | - } |
|
| 117 | +private function getExceptionCallbacks(Exception $xException): array |
|
| 118 | +{ |
|
| 119 | +$aExceptionCallbacks = []; |
|
| 120 | +foreach($this->aExceptionCallbacks as $sExClass => $aCallbacks) |
|
| 121 | +{ |
|
| 122 | +if(is_a($xException, $sExClass)) |
|
| 123 | +{ |
|
| 124 | + $aExceptionCallbacks = array_merge($aExceptionCallbacks, $aCallbacks); |
|
| 125 | +} |
|
| 126 | +} |
|
| 127 | +return array_values($aExceptionCallbacks); |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - /** |
|
| 130 | +/** |
|
| 131 | 131 | * Add a library booting callback. |
| 132 | 132 | * |
| 133 | 133 | * @param callable $xCallable The callback function |
| 134 | 134 | * |
| 135 | 135 | * @return CallbackManager |
| 136 | 136 | */ |
| 137 | - public function boot(callable $xCallable): CallbackManager |
|
| 138 | - { |
|
| 139 | - $this->aBootCallbacks[] = $xCallable; |
|
| 140 | - return $this; |
|
| 141 | - } |
|
| 137 | +public function boot(callable $xCallable): CallbackManager |
|
| 138 | +{ |
|
| 139 | +$this->aBootCallbacks[] = $xCallable; |
|
| 140 | +return $this; |
|
| 141 | +} |
|
| 142 | 142 | |
| 143 | - /** |
|
| 143 | +/** |
|
| 144 | 144 | * Add a pre-request processing callback. |
| 145 | 145 | * |
| 146 | 146 | * @param callable $xCallable The callback function |
| 147 | 147 | * |
| 148 | 148 | * @return CallbackManager |
| 149 | 149 | */ |
| 150 | - public function before(callable $xCallable): CallbackManager |
|
| 151 | - { |
|
| 152 | - $this->aBeforeCallbacks[] = $xCallable; |
|
| 153 | - return $this; |
|
| 154 | - } |
|
| 150 | +public function before(callable $xCallable): CallbackManager |
|
| 151 | +{ |
|
| 152 | +$this->aBeforeCallbacks[] = $xCallable; |
|
| 153 | +return $this; |
|
| 154 | +} |
|
| 155 | 155 | |
| 156 | - /** |
|
| 156 | +/** |
|
| 157 | 157 | * Add a post-request processing callback. |
| 158 | 158 | * |
| 159 | 159 | * @param callable $xCallable The callback function |
| 160 | 160 | * |
| 161 | 161 | * @return CallbackManager |
| 162 | 162 | */ |
| 163 | - public function after(callable $xCallable): CallbackManager |
|
| 164 | - { |
|
| 165 | - $this->aAfterCallbacks[] = $xCallable; |
|
| 166 | - return $this; |
|
| 167 | - } |
|
| 163 | +public function after(callable $xCallable): CallbackManager |
|
| 164 | +{ |
|
| 165 | +$this->aAfterCallbacks[] = $xCallable; |
|
| 166 | +return $this; |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * Add a invalid request callback. |
| 171 | 171 | * |
| 172 | 172 | * @param callable $xCallable The callback function |
| 173 | 173 | * |
| 174 | 174 | * @return CallbackManager |
| 175 | 175 | */ |
| 176 | - public function invalid(callable $xCallable): CallbackManager |
|
| 177 | - { |
|
| 178 | - $this->aInvalidCallbacks[] = $xCallable; |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 176 | +public function invalid(callable $xCallable): CallbackManager |
|
| 177 | +{ |
|
| 178 | +$this->aInvalidCallbacks[] = $xCallable; |
|
| 179 | +return $this; |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Add a processing error callback. |
| 184 | 184 | * |
| 185 | 185 | * @param callable $xCallable The callback function |
@@ -187,74 +187,74 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @return CallbackManager |
| 189 | 189 | */ |
| 190 | - public function error(callable $xCallable, string $sExClass = ''): CallbackManager |
|
| 191 | - { |
|
| 192 | - if($sExClass === '' || $sExClass === Exception::class) |
|
| 193 | - { |
|
| 194 | - $this->aErrorCallbacks[] = $xCallable; |
|
| 195 | - return $this; |
|
| 196 | - } |
|
| 197 | - // Callback for a given exception class |
|
| 198 | - if(isset($this->aExceptionCallbacks[$sExClass])) |
|
| 199 | - { |
|
| 200 | - $this->aExceptionCallbacks[$sExClass][] = $xCallable; |
|
| 201 | - return $this; |
|
| 202 | - } |
|
| 203 | - $this->aExceptionCallbacks[$sExClass] = [$xCallable]; |
|
| 204 | - return $this; |
|
| 205 | - } |
|
| 190 | +public function error(callable $xCallable, string $sExClass = ''): CallbackManager |
|
| 191 | +{ |
|
| 192 | +if($sExClass === '' || $sExClass === Exception::class) |
|
| 193 | +{ |
|
| 194 | +$this->aErrorCallbacks[] = $xCallable; |
|
| 195 | +return $this; |
|
| 196 | +} |
|
| 197 | +// Callback for a given exception class |
|
| 198 | +if(isset($this->aExceptionCallbacks[$sExClass])) |
|
| 199 | +{ |
|
| 200 | +$this->aExceptionCallbacks[$sExClass][] = $xCallable; |
|
| 201 | +return $this; |
|
| 202 | +} |
|
| 203 | +$this->aExceptionCallbacks[$sExClass] = [$xCallable]; |
|
| 204 | +return $this; |
|
| 205 | +} |
|
| 206 | 206 | |
| 207 | - /** |
|
| 207 | +/** |
|
| 208 | 208 | * Add a class initialisation callback. |
| 209 | 209 | * |
| 210 | 210 | * @param callable $xCallable The callback function |
| 211 | 211 | * |
| 212 | 212 | * @return CallbackManager |
| 213 | 213 | */ |
| 214 | - public function init(callable $xCallable): CallbackManager |
|
| 215 | - { |
|
| 216 | - $this->aInitCallbacks[] = $xCallable; |
|
| 217 | - return $this; |
|
| 218 | - } |
|
| 214 | +public function init(callable $xCallable): CallbackManager |
|
| 215 | +{ |
|
| 216 | +$this->aInitCallbacks[] = $xCallable; |
|
| 217 | +return $this; |
|
| 218 | +} |
|
| 219 | 219 | |
| 220 | - /** |
|
| 220 | +/** |
|
| 221 | 221 | * @param callable $xCallback |
| 222 | 222 | * @param array $aParameters |
| 223 | 223 | * |
| 224 | 224 | * @return void |
| 225 | 225 | */ |
| 226 | - private function executeCallback(callable $xCallback, array $aParameters): void |
|
| 227 | - { |
|
| 228 | - call_user_func_array($xCallback, $aParameters); |
|
| 229 | - } |
|
| 226 | +private function executeCallback(callable $xCallback, array $aParameters): void |
|
| 227 | +{ |
|
| 228 | +call_user_func_array($xCallback, $aParameters); |
|
| 229 | +} |
|
| 230 | 230 | |
| 231 | - /** |
|
| 231 | +/** |
|
| 232 | 232 | * @param array $aCallbacks |
| 233 | 233 | * @param array $aParameters |
| 234 | 234 | * |
| 235 | 235 | * @return void |
| 236 | 236 | */ |
| 237 | - private function executeCallbacks(array $aCallbacks, array $aParameters): void |
|
| 238 | - { |
|
| 239 | - foreach($aCallbacks as $xCallback) |
|
| 240 | - { |
|
| 241 | - $this->executeCallback($xCallback, $aParameters); |
|
| 242 | - } |
|
| 243 | - } |
|
| 237 | +private function executeCallbacks(array $aCallbacks, array $aParameters): void |
|
| 238 | +{ |
|
| 239 | +foreach($aCallbacks as $xCallback) |
|
| 240 | +{ |
|
| 241 | +$this->executeCallback($xCallback, $aParameters); |
|
| 242 | +} |
|
| 243 | +} |
|
| 244 | 244 | |
| 245 | - /** |
|
| 245 | +/** |
|
| 246 | 246 | * Execute the class initialisation callbacks. |
| 247 | 247 | * |
| 248 | 248 | * @param mixed $xComponent |
| 249 | 249 | * |
| 250 | 250 | * @return void |
| 251 | 251 | */ |
| 252 | - public function onInit($xComponent): void |
|
| 253 | - { |
|
| 254 | - $this->executeCallbacks($this->aInitCallbacks, [$xComponent]); |
|
| 255 | - } |
|
| 252 | +public function onInit($xComponent): void |
|
| 253 | +{ |
|
| 254 | +$this->executeCallbacks($this->aInitCallbacks, [$xComponent]); |
|
| 255 | +} |
|
| 256 | 256 | |
| 257 | - /** |
|
| 257 | +/** |
|
| 258 | 258 | * These are the pre-request processing callbacks passed to the Jaxon library. |
| 259 | 259 | * |
| 260 | 260 | * @param Target $xTarget |
@@ -263,20 +263,20 @@ discard block |
||
| 263 | 263 | * @return void |
| 264 | 264 | * @throws RequestException |
| 265 | 265 | */ |
| 266 | - public function onBefore(Target $xTarget, bool &$bEndRequest): void |
|
| 267 | - { |
|
| 268 | - // Call the user defined callback |
|
| 269 | - foreach($this->aBeforeCallbacks as $xCallback) |
|
| 270 | - { |
|
| 271 | - $this->executeCallback($xCallback, [$xTarget, &$bEndRequest]); |
|
| 272 | - if($bEndRequest) |
|
| 273 | - { |
|
| 274 | - return; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 266 | +public function onBefore(Target $xTarget, bool &$bEndRequest): void |
|
| 267 | +{ |
|
| 268 | +// Call the user defined callback |
|
| 269 | +foreach($this->aBeforeCallbacks as $xCallback) |
|
| 270 | +{ |
|
| 271 | +$this->executeCallback($xCallback, [$xTarget, &$bEndRequest]); |
|
| 272 | +if($bEndRequest) |
|
| 273 | +{ |
|
| 274 | + return; |
|
| 275 | +} |
|
| 276 | +} |
|
| 277 | +} |
|
| 278 | 278 | |
| 279 | - /** |
|
| 279 | +/** |
|
| 280 | 280 | * These are the post-request processing callbacks passed to the Jaxon library. |
| 281 | 281 | * |
| 282 | 282 | * @param Target $xTarget |
@@ -285,12 +285,12 @@ discard block |
||
| 285 | 285 | * @return void |
| 286 | 286 | * @throws RequestException |
| 287 | 287 | */ |
| 288 | - public function onAfter(Target $xTarget, bool $bEndRequest): void |
|
| 289 | - { |
|
| 290 | - $this->executeCallbacks($this->aAfterCallbacks, [$xTarget, $bEndRequest]); |
|
| 291 | - } |
|
| 288 | +public function onAfter(Target $xTarget, bool $bEndRequest): void |
|
| 289 | +{ |
|
| 290 | +$this->executeCallbacks($this->aAfterCallbacks, [$xTarget, $bEndRequest]); |
|
| 291 | +} |
|
| 292 | 292 | |
| 293 | - /** |
|
| 293 | +/** |
|
| 294 | 294 | * These callbacks are called whenever an invalid request is processed. |
| 295 | 295 | * |
| 296 | 296 | * @param RequestException $xException |
@@ -298,13 +298,13 @@ discard block |
||
| 298 | 298 | * @return void |
| 299 | 299 | * @throws RequestException |
| 300 | 300 | */ |
| 301 | - public function onInvalid(RequestException $xException): void |
|
| 302 | - { |
|
| 303 | - $this->executeCallbacks($this->aInvalidCallbacks, [$xException]); |
|
| 304 | - throw $xException; |
|
| 305 | - } |
|
| 301 | +public function onInvalid(RequestException $xException): void |
|
| 302 | +{ |
|
| 303 | +$this->executeCallbacks($this->aInvalidCallbacks, [$xException]); |
|
| 304 | +throw $xException; |
|
| 305 | +} |
|
| 306 | 306 | |
| 307 | - /** |
|
| 307 | +/** |
|
| 308 | 308 | * These callbacks are called whenever an invalid request is processed. |
| 309 | 309 | * |
| 310 | 310 | * @param Exception $xException |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | * @return void |
| 313 | 313 | * @throws Exception |
| 314 | 314 | */ |
| 315 | - public function onError(Exception $xException): void |
|
| 316 | - { |
|
| 317 | - $aExceptionCallbacks = $this->getExceptionCallbacks($xException); |
|
| 318 | - $this->executeCallbacks($aExceptionCallbacks, [$xException]); |
|
| 319 | - if(count($aExceptionCallbacks) > 0) |
|
| 320 | - { |
|
| 321 | - // Do not throw the exception if a custom handler is defined |
|
| 322 | - return; |
|
| 323 | - } |
|
| 315 | +public function onError(Exception $xException): void |
|
| 316 | +{ |
|
| 317 | +$aExceptionCallbacks = $this->getExceptionCallbacks($xException); |
|
| 318 | +$this->executeCallbacks($aExceptionCallbacks, [$xException]); |
|
| 319 | +if(count($aExceptionCallbacks) > 0) |
|
| 320 | +{ |
|
| 321 | +// Do not throw the exception if a custom handler is defined |
|
| 322 | +return; |
|
| 323 | +} |
|
| 324 | 324 | |
| 325 | - $this->executeCallbacks($this->aErrorCallbacks, [$xException]); |
|
| 326 | - throw $xException; |
|
| 327 | - } |
|
| 325 | +$this->executeCallbacks($this->aErrorCallbacks, [$xException]); |
|
| 326 | +throw $xException; |
|
| 327 | +} |
|
| 328 | 328 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function popBootCallbacks(): array |
| 100 | 100 | { |
| 101 | - if(empty($this->aBootCallbacks)) |
|
| 101 | + if (empty($this->aBootCallbacks)) |
|
| 102 | 102 | { |
| 103 | 103 | return []; |
| 104 | 104 | } |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | private function getExceptionCallbacks(Exception $xException): array |
| 118 | 118 | { |
| 119 | 119 | $aExceptionCallbacks = []; |
| 120 | - foreach($this->aExceptionCallbacks as $sExClass => $aCallbacks) |
|
| 120 | + foreach ($this->aExceptionCallbacks as $sExClass => $aCallbacks) |
|
| 121 | 121 | { |
| 122 | - if(is_a($xException, $sExClass)) |
|
| 122 | + if (is_a($xException, $sExClass)) |
|
| 123 | 123 | { |
| 124 | 124 | $aExceptionCallbacks = array_merge($aExceptionCallbacks, $aCallbacks); |
| 125 | 125 | } |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function error(callable $xCallable, string $sExClass = ''): CallbackManager |
| 191 | 191 | { |
| 192 | - if($sExClass === '' || $sExClass === Exception::class) |
|
| 192 | + if ($sExClass === '' || $sExClass === Exception::class) |
|
| 193 | 193 | { |
| 194 | 194 | $this->aErrorCallbacks[] = $xCallable; |
| 195 | 195 | return $this; |
| 196 | 196 | } |
| 197 | 197 | // Callback for a given exception class |
| 198 | - if(isset($this->aExceptionCallbacks[$sExClass])) |
|
| 198 | + if (isset($this->aExceptionCallbacks[$sExClass])) |
|
| 199 | 199 | { |
| 200 | 200 | $this->aExceptionCallbacks[$sExClass][] = $xCallable; |
| 201 | 201 | return $this; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | private function executeCallbacks(array $aCallbacks, array $aParameters): void |
| 238 | 238 | { |
| 239 | - foreach($aCallbacks as $xCallback) |
|
| 239 | + foreach ($aCallbacks as $xCallback) |
|
| 240 | 240 | { |
| 241 | 241 | $this->executeCallback($xCallback, $aParameters); |
| 242 | 242 | } |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | public function onBefore(Target $xTarget, bool &$bEndRequest): void |
| 267 | 267 | { |
| 268 | 268 | // Call the user defined callback |
| 269 | - foreach($this->aBeforeCallbacks as $xCallback) |
|
| 269 | + foreach ($this->aBeforeCallbacks as $xCallback) |
|
| 270 | 270 | { |
| 271 | 271 | $this->executeCallback($xCallback, [$xTarget, &$bEndRequest]); |
| 272 | - if($bEndRequest) |
|
| 272 | + if ($bEndRequest) |
|
| 273 | 273 | { |
| 274 | 274 | return; |
| 275 | 275 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | { |
| 317 | 317 | $aExceptionCallbacks = $this->getExceptionCallbacks($xException); |
| 318 | 318 | $this->executeCallbacks($aExceptionCallbacks, [$xException]); |
| 319 | - if(count($aExceptionCallbacks) > 0) |
|
| 319 | + if (count($aExceptionCallbacks) > 0) |
|
| 320 | 320 | { |
| 321 | 321 | // Do not throw the exception if a custom handler is defined |
| 322 | 322 | return; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public function canProcessRequest(): bool |
| 62 | 62 | { |
| 63 | 63 | // Return true if the request plugin was already found |
| 64 | - if($this->xRequestPlugin !== null) |
|
| 64 | + if ($this->xRequestPlugin !== null) |
|
| 65 | 65 | { |
| 66 | 66 | return true; |
| 67 | 67 | } |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | $xRequest = $this->di->getRequest(); |
| 71 | 71 | |
| 72 | 72 | // Find a plugin to process the request |
| 73 | - foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 73 | + foreach ($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 74 | 74 | { |
| 75 | - if($sClassName::canProcessRequest($xRequest)) |
|
| 75 | + if ($sClassName::canProcessRequest($xRequest)) |
|
| 76 | 76 | { |
| 77 | 77 | $this->xRequestPlugin = $this->di->g($sClassName); |
| 78 | 78 | $xTarget = $this->xRequestPlugin->setTarget($xRequest); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | private function _processRequest(): void |
| 93 | 93 | { |
| 94 | 94 | // Process the request |
| 95 | - if($this->xRequestPlugin !== null) |
|
| 95 | + if ($this->xRequestPlugin !== null) |
|
| 96 | 96 | { |
| 97 | 97 | $this->xRequestPlugin->processRequest(); |
| 98 | 98 | // Process the databag |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | public function processRequest(): void |
| 110 | 110 | { |
| 111 | 111 | // Check if there is a plugin to process this request |
| 112 | - if(!$this->canProcessRequest()) |
|
| 112 | + if (!$this->canProcessRequest()) |
|
| 113 | 113 | { |
| 114 | 114 | return; |
| 115 | 115 | } |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $bEndRequest = false; |
| 120 | 120 | // Handle before processing event |
| 121 | - if($this->xRequestPlugin !== null) |
|
| 121 | + if ($this->xRequestPlugin !== null) |
|
| 122 | 122 | { |
| 123 | 123 | $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest); |
| 124 | 124 | } |
| 125 | - if($bEndRequest) |
|
| 125 | + if ($bEndRequest) |
|
| 126 | 126 | { |
| 127 | 127 | return; |
| 128 | 128 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $this->_processRequest(); |
| 131 | 131 | |
| 132 | 132 | // Handle after processing event |
| 133 | - if($this->xRequestPlugin !== null) |
|
| 133 | + if ($this->xRequestPlugin !== null) |
|
| 134 | 134 | { |
| 135 | 135 | $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest); |
| 136 | 136 | } |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | // An exception was thrown while processing the request. |
| 139 | 139 | // The request missed the corresponding handler function, |
| 140 | 140 | // or an error occurred while attempting to execute the handler. |
| 141 | - catch(RequestException $e) |
|
| 141 | + catch (RequestException $e) |
|
| 142 | 142 | { |
| 143 | 143 | $this->xResponseManager->error($e->getMessage()); |
| 144 | 144 | $this->xCallbackManager->onInvalid($e); |
| 145 | 145 | } |
| 146 | - catch(Exception $e) |
|
| 146 | + catch (Exception $e) |
|
| 147 | 147 | { |
| 148 | 148 | $this->xResponseManager->error($e->getMessage()); |
| 149 | 149 | $this->xCallbackManager->onError($e); |
@@ -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); |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | class RequestHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The request plugin that is able to process the current request |
| 35 | 35 | * |
| 36 | 36 | * @var RequestHandlerInterface |
| 37 | 37 | */ |
| 38 | - private $xRequestPlugin = null; |
|
| 38 | +private $xRequestPlugin = null; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The constructor |
| 42 | 42 | * |
| 43 | 43 | * @param Container $di |
@@ -46,110 +46,110 @@ discard block |
||
| 46 | 46 | * @param CallbackManager $xCallbackManager |
| 47 | 47 | * @param DatabagPlugin $xDatabagPlugin |
| 48 | 48 | */ |
| 49 | - public function __construct(private Container $di, private PluginManager $xPluginManager, |
|
| 50 | - private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager, |
|
| 51 | - private DatabagPlugin $xDatabagPlugin) |
|
| 52 | - {} |
|
| 49 | +public function __construct(private Container $di, private PluginManager $xPluginManager, |
|
| 50 | +private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager, |
|
| 51 | +private DatabagPlugin $xDatabagPlugin) |
|
| 52 | +{} |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Check if the current request can be processed |
| 56 | 56 | * |
| 57 | 57 | * Calls each of the request plugins and determines if the current request can be processed by one of them. |
| 58 | 58 | * |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public function canProcessRequest(): bool |
|
| 62 | - { |
|
| 63 | - // Return true if the request plugin was already found |
|
| 64 | - if($this->xRequestPlugin !== null) |
|
| 65 | - { |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 61 | +public function canProcessRequest(): bool |
|
| 62 | +{ |
|
| 63 | +// Return true if the request plugin was already found |
|
| 64 | +if($this->xRequestPlugin !== null) |
|
| 65 | +{ |
|
| 66 | +return true; |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - // The HTTP request |
|
| 70 | - $xRequest = $this->di->getRequest(); |
|
| 69 | +// The HTTP request |
|
| 70 | +$xRequest = $this->di->getRequest(); |
|
| 71 | 71 | |
| 72 | - // Find a plugin to process the request |
|
| 73 | - foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 74 | - { |
|
| 75 | - if($sClassName::canProcessRequest($xRequest)) |
|
| 76 | - { |
|
| 77 | - $this->xRequestPlugin = $this->di->g($sClassName); |
|
| 78 | - $xTarget = $this->xRequestPlugin->setTarget($xRequest); |
|
| 79 | - $xTarget->setMethodArgs($this->di->getRequestArguments()); |
|
| 80 | - return true; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 72 | +// Find a plugin to process the request |
|
| 73 | +foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 74 | +{ |
|
| 75 | +if($sClassName::canProcessRequest($xRequest)) |
|
| 76 | +{ |
|
| 77 | + $this->xRequestPlugin = $this->di->g($sClassName); |
|
| 78 | + $xTarget = $this->xRequestPlugin->setTarget($xRequest); |
|
| 79 | + $xTarget->setMethodArgs($this->di->getRequestArguments()); |
|
| 80 | + return true; |
|
| 81 | +} |
|
| 82 | +} |
|
| 83 | +return false; |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * Process the current request and handle errors and exceptions. |
| 88 | 88 | * |
| 89 | 89 | * @return void |
| 90 | 90 | * @throws RequestException |
| 91 | 91 | */ |
| 92 | - private function _processRequest(): void |
|
| 93 | - { |
|
| 94 | - // Process the request |
|
| 95 | - if($this->xRequestPlugin !== null) |
|
| 96 | - { |
|
| 97 | - $this->xRequestPlugin->processRequest(); |
|
| 98 | - // Process the databag |
|
| 99 | - $this->xDatabagPlugin->writeCommand(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 92 | +private function _processRequest(): void |
|
| 93 | +{ |
|
| 94 | +// Process the request |
|
| 95 | +if($this->xRequestPlugin !== null) |
|
| 96 | +{ |
|
| 97 | +$this->xRequestPlugin->processRequest(); |
|
| 98 | +// Process the databag |
|
| 99 | +$this->xDatabagPlugin->writeCommand(); |
|
| 100 | +} |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Process the current request. |
| 105 | 105 | * |
| 106 | 106 | * @return void |
| 107 | 107 | * @throws RequestException |
| 108 | 108 | */ |
| 109 | - public function processRequest(): void |
|
| 110 | - { |
|
| 111 | - // Check if there is a plugin to process this request |
|
| 112 | - if(!$this->canProcessRequest()) |
|
| 113 | - { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 109 | +public function processRequest(): void |
|
| 110 | +{ |
|
| 111 | +// Check if there is a plugin to process this request |
|
| 112 | +if(!$this->canProcessRequest()) |
|
| 113 | +{ |
|
| 114 | +return; |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - try |
|
| 118 | - { |
|
| 119 | - $bEndRequest = false; |
|
| 120 | - // Handle before processing event |
|
| 121 | - if($this->xRequestPlugin !== null) |
|
| 122 | - { |
|
| 123 | - $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 124 | - } |
|
| 125 | - if($bEndRequest) |
|
| 126 | - { |
|
| 127 | - return; |
|
| 128 | - } |
|
| 117 | +try |
|
| 118 | +{ |
|
| 119 | +$bEndRequest = false; |
|
| 120 | +// Handle before processing event |
|
| 121 | +if($this->xRequestPlugin !== null) |
|
| 122 | +{ |
|
| 123 | + $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 124 | +} |
|
| 125 | +if($bEndRequest) |
|
| 126 | +{ |
|
| 127 | + return; |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - $this->_processRequest(); |
|
| 130 | +$this->_processRequest(); |
|
| 131 | 131 | |
| 132 | - // Handle after processing event |
|
| 133 | - if($this->xRequestPlugin !== null) |
|
| 134 | - { |
|
| 135 | - $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - // An exception was thrown while processing the request. |
|
| 139 | - // The request missed the corresponding handler function, |
|
| 140 | - // or an error occurred while attempting to execute the handler. |
|
| 141 | - catch(RequestException $e) |
|
| 142 | - { |
|
| 143 | - $this->xResponseManager->error($e->getMessage()); |
|
| 144 | - $this->xCallbackManager->onInvalid($e); |
|
| 145 | - } |
|
| 146 | - catch(Exception $e) |
|
| 147 | - { |
|
| 148 | - $this->xResponseManager->error($e->getMessage()); |
|
| 149 | - $this->xCallbackManager->onError($e); |
|
| 150 | - } |
|
| 132 | +// Handle after processing event |
|
| 133 | +if($this->xRequestPlugin !== null) |
|
| 134 | +{ |
|
| 135 | + $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 136 | +} |
|
| 137 | +} |
|
| 138 | +// An exception was thrown while processing the request. |
|
| 139 | +// The request missed the corresponding handler function, |
|
| 140 | +// or an error occurred while attempting to execute the handler. |
|
| 141 | +catch(RequestException $e) |
|
| 142 | +{ |
|
| 143 | +$this->xResponseManager->error($e->getMessage()); |
|
| 144 | +$this->xCallbackManager->onInvalid($e); |
|
| 145 | +} |
|
| 146 | +catch(Exception $e) |
|
| 147 | +{ |
|
| 148 | +$this->xResponseManager->error($e->getMessage()); |
|
| 149 | +$this->xCallbackManager->onError($e); |
|
| 150 | +} |
|
| 151 | 151 | |
| 152 | - // Print the debug messages |
|
| 153 | - $this->xResponseManager->printDebug(); |
|
| 154 | - } |
|
| 152 | +// Print the debug messages |
|
| 153 | +$this->xResponseManager->printDebug(); |
|
| 154 | +} |
|
| 155 | 155 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | class ParameterReader |
| 42 | 42 | { |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The constructor |
| 45 | 45 | * |
| 46 | 46 | * @param Container $di |
@@ -48,28 +48,28 @@ discard block |
||
| 48 | 48 | * @param ConfigManager $xConfigManager |
| 49 | 49 | * @param UriDetector $xUriDetector |
| 50 | 50 | */ |
| 51 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 52 | - private ConfigManager $xConfigManager, private UriDetector $xUriDetector) |
|
| 53 | - {} |
|
| 51 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 52 | +private ConfigManager $xConfigManager, private UriDetector $xUriDetector) |
|
| 53 | +{} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Decode input data. |
| 57 | 57 | * |
| 58 | 58 | * @param string $sStr |
| 59 | 59 | * |
| 60 | 60 | * @return string |
| 61 | 61 | */ |
| 62 | - private function decodeStr(string $sStr): string |
|
| 63 | - { |
|
| 64 | - $aServerParams = $this->di->getServerParams(); |
|
| 65 | - $sContentType = $aServerParams['CONTENT_TYPE'] ?? $aServerParams['HTTP_CONTENT_TYPE'] ?? ''; |
|
| 66 | - $sType = 'multipart/form-data'; |
|
| 67 | - // Parameters are url encoded when uploading files |
|
| 68 | - return strncmp($sContentType, $sType, strlen($sType)) !== 0 ? |
|
| 69 | - $sStr : urldecode($sStr); |
|
| 70 | - } |
|
| 62 | +private function decodeStr(string $sStr): string |
|
| 63 | +{ |
|
| 64 | +$aServerParams = $this->di->getServerParams(); |
|
| 65 | +$sContentType = $aServerParams['CONTENT_TYPE'] ?? $aServerParams['HTTP_CONTENT_TYPE'] ?? ''; |
|
| 66 | +$sType = 'multipart/form-data'; |
|
| 67 | +// Parameters are url encoded when uploading files |
|
| 68 | +return strncmp($sContentType, $sType, strlen($sType)) !== 0 ? |
|
| 69 | +$sStr : urldecode($sStr); |
|
| 70 | +} |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * Decode input data. |
| 74 | 74 | * |
| 75 | 75 | * @param string $sStr |
@@ -77,73 +77,73 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | * @throws RequestException |
| 79 | 79 | */ |
| 80 | - private function decoderUtf8Str(string $sStr): string |
|
| 81 | - { |
|
| 82 | - $sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
|
| 83 | - if(function_exists('iconv')) |
|
| 84 | - { |
|
| 85 | - return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
|
| 86 | - } |
|
| 87 | - if(function_exists('mb_convert_encoding')) |
|
| 88 | - { |
|
| 89 | - return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
|
| 90 | - } |
|
| 91 | - // By default, no decoding |
|
| 92 | - // return $sStr; |
|
| 93 | - throw new RequestException($this->xTranslator->trans('errors.request.conversion')); |
|
| 94 | - } |
|
| 80 | +private function decoderUtf8Str(string $sStr): string |
|
| 81 | +{ |
|
| 82 | +$sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
|
| 83 | +if(function_exists('iconv')) |
|
| 84 | +{ |
|
| 85 | +return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
|
| 86 | +} |
|
| 87 | +if(function_exists('mb_convert_encoding')) |
|
| 88 | +{ |
|
| 89 | +return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
|
| 90 | +} |
|
| 91 | +// By default, no decoding |
|
| 92 | +// return $sStr; |
|
| 93 | +throw new RequestException($this->xTranslator->trans('errors.request.conversion')); |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Choose the function to use to decode input data. |
| 98 | 98 | * |
| 99 | 99 | * @param string $sParam |
| 100 | 100 | * |
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | - private function decodeRequestParameter(string $sParam): string |
|
| 104 | - { |
|
| 105 | - $sParam = $this->decodeStr($sParam); |
|
| 106 | - if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 107 | - { |
|
| 108 | - return $sParam; |
|
| 109 | - } |
|
| 110 | - $this->xConfigManager->setOption('core.decode_utf8', false); |
|
| 111 | - return $this->decoderUtf8Str($sParam); |
|
| 112 | - } |
|
| 103 | +private function decodeRequestParameter(string $sParam): string |
|
| 104 | +{ |
|
| 105 | +$sParam = $this->decodeStr($sParam); |
|
| 106 | +if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 107 | +{ |
|
| 108 | +return $sParam; |
|
| 109 | +} |
|
| 110 | +$this->xConfigManager->setOption('core.decode_utf8', false); |
|
| 111 | +return $this->decoderUtf8Str($sParam); |
|
| 112 | +} |
|
| 113 | 113 | |
| 114 | - /** |
|
| 114 | +/** |
|
| 115 | 115 | * @param ServerRequestInterface $xRequest |
| 116 | 116 | * |
| 117 | 117 | * @return array|null |
| 118 | 118 | */ |
| 119 | - public function getRequestParameter(ServerRequestInterface $xRequest): ?array |
|
| 120 | - { |
|
| 121 | - $aBody = $xRequest->getParsedBody(); |
|
| 122 | - $aParams = is_array($aBody) ? $aBody : $xRequest->getQueryParams(); |
|
| 123 | - // Check if Jaxon call parameters are present. |
|
| 124 | - return !isset($aParams['jxncall']) || !is_string($aParams['jxncall']) ? null : |
|
| 125 | - json_decode($this->decodeRequestParameter($aParams['jxncall']), true); |
|
| 126 | - } |
|
| 119 | +public function getRequestParameter(ServerRequestInterface $xRequest): ?array |
|
| 120 | +{ |
|
| 121 | +$aBody = $xRequest->getParsedBody(); |
|
| 122 | +$aParams = is_array($aBody) ? $aBody : $xRequest->getQueryParams(); |
|
| 123 | +// Check if Jaxon call parameters are present. |
|
| 124 | +return !isset($aParams['jxncall']) || !is_string($aParams['jxncall']) ? null : |
|
| 125 | +json_decode($this->decodeRequestParameter($aParams['jxncall']), true); |
|
| 126 | +} |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Get the URI of the current request |
| 130 | 130 | * |
| 131 | 131 | * @throws UriException |
| 132 | 132 | */ |
| 133 | - public function uri(): string |
|
| 134 | - { |
|
| 135 | - return $this->xUriDetector->detect($this->di->getServerParams()); |
|
| 136 | - } |
|
| 133 | +public function uri(): string |
|
| 134 | +{ |
|
| 135 | +return $this->xUriDetector->detect($this->di->getServerParams()); |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * Make the specified URL suitable for redirect |
| 140 | 140 | * |
| 141 | 141 | * @param string $sURL The relative or fully qualified URL |
| 142 | 142 | * |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function parseUrl(string $sURL): string |
|
| 146 | - { |
|
| 147 | - return $this->xUriDetector->redirect($sURL, $this->di->getServerParams()); |
|
| 148 | - } |
|
| 145 | +public function parseUrl(string $sURL): string |
|
| 146 | +{ |
|
| 147 | +return $this->xUriDetector->redirect($sURL, $this->di->getServerParams()); |
|
| 148 | +} |
|
| 149 | 149 | } |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | private function decoderUtf8Str(string $sStr): string |
| 81 | 81 | { |
| 82 | 82 | $sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
| 83 | - if(function_exists('iconv')) |
|
| 83 | + if (function_exists('iconv')) |
|
| 84 | 84 | { |
| 85 | 85 | return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
| 86 | 86 | } |
| 87 | - if(function_exists('mb_convert_encoding')) |
|
| 87 | + if (function_exists('mb_convert_encoding')) |
|
| 88 | 88 | { |
| 89 | 89 | return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
| 90 | 90 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | private function decodeRequestParameter(string $sParam): string |
| 104 | 104 | { |
| 105 | 105 | $sParam = $this->decodeStr($sParam); |
| 106 | - if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 106 | + if (!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 107 | 107 | { |
| 108 | 108 | return $sParam; |
| 109 | 109 | } |
@@ -18,52 +18,52 @@ |
||
| 18 | 18 | |
| 19 | 19 | interface FileInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Get the filesystem where the file is stored |
| 23 | 23 | * |
| 24 | 24 | * @return Filesystem |
| 25 | 25 | */ |
| 26 | - public function filesystem(): Filesystem; |
|
| 26 | +public function filesystem(): Filesystem; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * Get the uploaded file type |
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function type(): string; |
|
| 33 | +public function type(): string; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * Get the uploaded file name, without the extension and slugified |
| 37 | 37 | * |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function name(): string; |
|
| 40 | +public function name(): string; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * Get the uploaded file name, with the extension |
| 44 | 44 | * |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - public function filename(): string; |
|
| 47 | +public function filename(): string; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * Get the uploaded file path |
| 51 | 51 | * |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public function path(): string; |
|
| 54 | +public function path(): string; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * Get the uploaded file size |
| 58 | 58 | * |
| 59 | 59 | * @return int |
| 60 | 60 | */ |
| 61 | - public function size(): int; |
|
| 61 | +public function size(): int; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * Get the uploaded file extension |
| 65 | 65 | * |
| 66 | 66 | * @return string |
| 67 | 67 | */ |
| 68 | - public function extension(): string; |
|
| 68 | +public function extension(): string; |
|
| 69 | 69 | } |
@@ -19,109 +19,109 @@ |
||
| 19 | 19 | |
| 20 | 20 | class ParameterFactory |
| 21 | 21 | { |
| 22 | - /** |
|
| 22 | +/** |
|
| 23 | 23 | * Make a parameter of type form values |
| 24 | 24 | * |
| 25 | 25 | * @param string $sFormId The id of the HTML form |
| 26 | 26 | * |
| 27 | 27 | * @return array |
| 28 | 28 | */ |
| 29 | - public function form(string $sFormId): array |
|
| 30 | - { |
|
| 31 | - return (new HtmlReader($sFormId))->form(); |
|
| 32 | - } |
|
| 29 | +public function form(string $sFormId): array |
|
| 30 | +{ |
|
| 31 | +return (new HtmlReader($sFormId))->form(); |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * Make a parameter of type input value |
| 36 | 36 | * |
| 37 | 37 | * @param string $sInputId the id of the HTML input element |
| 38 | 38 | * |
| 39 | 39 | * @return TypedValue |
| 40 | 40 | */ |
| 41 | - public function input(string $sInputId): TypedValue |
|
| 42 | - { |
|
| 43 | - return (new HtmlReader($sInputId))->input(); |
|
| 44 | - } |
|
| 41 | +public function input(string $sInputId): TypedValue |
|
| 42 | +{ |
|
| 43 | +return (new HtmlReader($sInputId))->input(); |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * Make a parameter of type checked value |
| 48 | 48 | * |
| 49 | 49 | * @param string $sInputId the name of the HTML form element |
| 50 | 50 | * |
| 51 | 51 | * @return array |
| 52 | 52 | */ |
| 53 | - public function checked(string $sInputId): array |
|
| 54 | - { |
|
| 55 | - return (new HtmlReader($sInputId))->checked(); |
|
| 56 | - } |
|
| 53 | +public function checked(string $sInputId): array |
|
| 54 | +{ |
|
| 55 | +return (new HtmlReader($sInputId))->checked(); |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Make a parameter of type select |
| 60 | 60 | * |
| 61 | 61 | * @param string $sInputId the name of the HTML form element |
| 62 | 62 | * |
| 63 | 63 | * @return TypedValue |
| 64 | 64 | */ |
| 65 | - public function select(string $sInputId): TypedValue |
|
| 66 | - { |
|
| 67 | - return $this->input($sInputId); |
|
| 68 | - } |
|
| 65 | +public function select(string $sInputId): TypedValue |
|
| 66 | +{ |
|
| 67 | +return $this->input($sInputId); |
|
| 68 | +} |
|
| 69 | 69 | |
| 70 | - /** |
|
| 70 | +/** |
|
| 71 | 71 | * Make a parameter of type inner html |
| 72 | 72 | * |
| 73 | 73 | * @param string $sElementId the id of the HTML element |
| 74 | 74 | * |
| 75 | 75 | * @return TypedValue |
| 76 | 76 | */ |
| 77 | - public function html(string $sElementId): TypedValue |
|
| 78 | - { |
|
| 79 | - return (new HtmlReader($sElementId))->html(); |
|
| 80 | - } |
|
| 77 | +public function html(string $sElementId): TypedValue |
|
| 78 | +{ |
|
| 79 | +return (new HtmlReader($sElementId))->html(); |
|
| 80 | +} |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | +/** |
|
| 83 | 83 | * Make a parameter of type quoted string |
| 84 | 84 | * |
| 85 | 85 | * @param string $sValue the value of the parameter |
| 86 | 86 | * |
| 87 | 87 | * @return TypedValue |
| 88 | 88 | */ |
| 89 | - public function string(string $sValue): TypedValue |
|
| 90 | - { |
|
| 91 | - return TypedValue::make($sValue); |
|
| 92 | - } |
|
| 89 | +public function string(string $sValue): TypedValue |
|
| 90 | +{ |
|
| 91 | +return TypedValue::make($sValue); |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * Make a parameter of type numeric |
| 96 | 96 | * |
| 97 | 97 | * @param int $nValue the value of the parameter |
| 98 | 98 | * |
| 99 | 99 | * @return TypedValue |
| 100 | 100 | */ |
| 101 | - public function numeric(int $nValue): TypedValue |
|
| 102 | - { |
|
| 103 | - return TypedValue::make($nValue); |
|
| 104 | - } |
|
| 101 | +public function numeric(int $nValue): TypedValue |
|
| 102 | +{ |
|
| 103 | +return TypedValue::make($nValue); |
|
| 104 | +} |
|
| 105 | 105 | |
| 106 | - /** |
|
| 106 | +/** |
|
| 107 | 107 | * Make a parameter of type numeric |
| 108 | 108 | * |
| 109 | 109 | * @param numeric $nValue the value of the parameter |
| 110 | 110 | * |
| 111 | 111 | * @return TypedValue |
| 112 | 112 | */ |
| 113 | - public function int(int $nValue): TypedValue |
|
| 114 | - { |
|
| 115 | - return $this->numeric($nValue); |
|
| 116 | - } |
|
| 113 | +public function int(int $nValue): TypedValue |
|
| 114 | +{ |
|
| 115 | +return $this->numeric($nValue); |
|
| 116 | +} |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | +/** |
|
| 119 | 119 | * Make a parameter of type page number |
| 120 | 120 | * |
| 121 | 121 | * @return TypedValue |
| 122 | 122 | */ |
| 123 | - public function page(): TypedValue |
|
| 124 | - { |
|
| 125 | - return TypedValue::page(); |
|
| 126 | - } |
|
| 123 | +public function page(): TypedValue |
|
| 124 | +{ |
|
| 125 | +return TypedValue::page(); |
|
| 126 | +} |
|
| 127 | 127 | } |
@@ -16,49 +16,49 @@ |
||
| 16 | 16 | |
| 17 | 17 | class HtmlValue extends TypedValue |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * The class contructor |
| 21 | 21 | * |
| 22 | 22 | * @param array $aValue |
| 23 | 23 | */ |
| 24 | - public function __construct(protected array $aValue) |
|
| 25 | - {} |
|
| 24 | +public function __construct(protected array $aValue) |
|
| 25 | +{} |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * @inheritDoc |
| 29 | 29 | */ |
| 30 | - public function getType(): string |
|
| 31 | - { |
|
| 32 | - return $this->aValue['_type'] ?? '_'; |
|
| 33 | - } |
|
| 30 | +public function getType(): string |
|
| 31 | +{ |
|
| 32 | +return $this->aValue['_type'] ?? '_'; |
|
| 33 | +} |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * Convert the js value to int |
| 37 | 37 | * |
| 38 | 38 | * @return self |
| 39 | 39 | */ |
| 40 | - public function toInt(): self |
|
| 41 | - { |
|
| 42 | - $this->aValue['toInt'] = true; |
|
| 43 | - return $this; |
|
| 44 | - } |
|
| 40 | +public function toInt(): self |
|
| 41 | +{ |
|
| 42 | +$this->aValue['toInt'] = true; |
|
| 43 | +return $this; |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * Trim the js value |
| 48 | 48 | * |
| 49 | 49 | * @return self |
| 50 | 50 | */ |
| 51 | - public function trim(): self |
|
| 52 | - { |
|
| 53 | - $this->aValue['trim'] = true; |
|
| 54 | - return $this; |
|
| 55 | - } |
|
| 51 | +public function trim(): self |
|
| 52 | +{ |
|
| 53 | +$this->aValue['trim'] = true; |
|
| 54 | +return $this; |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @return array |
| 59 | 59 | */ |
| 60 | - public function jsonSerialize(): array |
|
| 61 | - { |
|
| 62 | - return $this->aValue; |
|
| 63 | - } |
|
| 60 | +public function jsonSerialize(): array |
|
| 61 | +{ |
|
| 62 | +return $this->aValue; |
|
| 63 | +} |
|
| 64 | 64 | } |
@@ -7,29 +7,29 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Event implements JsonSerializable |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * The constructor. |
| 12 | 12 | * |
| 13 | 13 | * @param string $sMode The event mode: 'jq' or 'js' |
| 14 | 14 | * @param string $sName The event name |
| 15 | 15 | * @param JsExpr $xHandler The event handler |
| 16 | 16 | */ |
| 17 | - public function __construct(private string $sMode, |
|
| 18 | - private string $sName, private JsExpr $xHandler) |
|
| 19 | - {} |
|
| 17 | +public function __construct(private string $sMode, |
|
| 18 | +private string $sName, private JsExpr $xHandler) |
|
| 19 | +{} |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Convert this call to array, when converting the response into json. |
| 23 | 23 | * |
| 24 | 24 | * @return array |
| 25 | 25 | */ |
| 26 | - public function jsonSerialize(): array |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - '_type' => 'event', |
|
| 30 | - '_name' => $this->sName, |
|
| 31 | - 'mode' => $this->sMode, |
|
| 32 | - 'func' => $this->xHandler->jsonSerialize(), |
|
| 33 | - ]; |
|
| 34 | - } |
|
| 26 | +public function jsonSerialize(): array |
|
| 27 | +{ |
|
| 28 | +return [ |
|
| 29 | +'_type' => 'event', |
|
| 30 | +'_name' => $this->sName, |
|
| 31 | +'mode' => $this->sMode, |
|
| 32 | +'func' => $this->xHandler->jsonSerialize(), |
|
| 33 | +]; |
|
| 34 | +} |
|
| 35 | 35 | } |
@@ -15,25 +15,25 @@ |
||
| 15 | 15 | |
| 16 | 16 | class SimpleValue extends TypedValue |
| 17 | 17 | { |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * @param mixed $xValue |
| 20 | 20 | */ |
| 21 | - public function __construct(private mixed $xValue) |
|
| 22 | - {} |
|
| 21 | +public function __construct(private mixed $xValue) |
|
| 22 | +{} |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @inheritDoc |
| 26 | 26 | */ |
| 27 | - public function getType(): string |
|
| 28 | - { |
|
| 29 | - return '_'; |
|
| 30 | - } |
|
| 27 | +public function getType(): string |
|
| 28 | +{ |
|
| 29 | +return '_'; |
|
| 30 | +} |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return mixed |
| 34 | 34 | */ |
| 35 | - public function jsonSerialize(): mixed |
|
| 36 | - { |
|
| 37 | - return $this->xValue; |
|
| 38 | - } |
|
| 35 | +public function jsonSerialize(): mixed |
|
| 36 | +{ |
|
| 37 | +return $this->xValue; |
|
| 38 | +} |
|
| 39 | 39 | } |