@@ -116,19 +116,19 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public static function make($xValue): ParameterInterface |
| 118 | 118 | { |
| 119 | - if($xValue instanceof ParameterInterface) |
|
| 119 | + if ($xValue instanceof ParameterInterface) |
|
| 120 | 120 | { |
| 121 | 121 | return $xValue; |
| 122 | 122 | } |
| 123 | - if(is_numeric($xValue)) |
|
| 123 | + if (is_numeric($xValue)) |
|
| 124 | 124 | { |
| 125 | 125 | return new Parameter(self::NUMERIC_VALUE, $xValue); |
| 126 | 126 | } |
| 127 | - if(is_string($xValue)) |
|
| 127 | + if (is_string($xValue)) |
|
| 128 | 128 | { |
| 129 | 129 | return new Parameter(self::QUOTED_VALUE, $xValue); |
| 130 | 130 | } |
| 131 | - if(is_bool($xValue)) |
|
| 131 | + if (is_bool($xValue)) |
|
| 132 | 132 | { |
| 133 | 133 | return new Parameter(self::BOOL_VALUE, $xValue); |
| 134 | 134 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function getNumericValueScript(): string |
| 232 | 232 | { |
| 233 | - return (string)$this->xValue; |
|
| 233 | + return (string) $this->xValue; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | protected function getUnquotedValueScript(): string |
| 242 | 242 | { |
| 243 | - return (string)$this->xValue; |
|
| 243 | + return (string) $this->xValue; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | protected function getPageNumberScript(): string |
| 264 | 264 | { |
| 265 | - return (string)$this->xValue; |
|
| 265 | + return (string) $this->xValue; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | public function getScript(): string |
| 274 | 274 | { |
| 275 | 275 | $sMethodName = 'get' . $this->sType . 'Script'; |
| 276 | - if(!method_exists($this, $sMethodName)) |
|
| 276 | + if (!method_exists($this, $sMethodName)) |
|
| 277 | 277 | { |
| 278 | 278 | return ''; |
| 279 | 279 | } |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | // and the other classes will get this request from there. |
| 73 | 73 | $this->di->val(ServerRequestInterface::class, $request); |
| 74 | 74 | |
| 75 | - if(!$this->xRequestHandler->canProcessRequest()) |
|
| 75 | + if (!$this->xRequestHandler->canProcessRequest()) |
|
| 76 | 76 | { |
| 77 | 77 | // Unable to find a plugin to process the request |
| 78 | 78 | throw new RequestException($this->xTranslator->trans('errors.request.plugin')); |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | // and the other classes will get this request from there. |
| 65 | 65 | $this->di->val(ServerRequestInterface::class, $request); |
| 66 | 66 | |
| 67 | - if(!$this->xRequestHandler->canProcessRequest()) |
|
| 67 | + if (!$this->xRequestHandler->canProcessRequest()) |
|
| 68 | 68 | { |
| 69 | 69 | // Unable to find a plugin to process the request |
| 70 | 70 | return $handler->handle($request); |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | */ |
| 66 | 66 | public function popBootCallbacks(): array |
| 67 | 67 | { |
| 68 | - if(empty($this->aBootCallbacks)) |
|
| 68 | + if (empty($this->aBootCallbacks)) |
|
| 69 | 69 | { |
| 70 | 70 | return []; |
| 71 | 71 | } |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | $xTarget = $this->xRequestPlugin->getTarget(); |
| 115 | 115 | // Call the user defined callback |
| 116 | - foreach($this->xCallbackManager->getBeforeCallbacks() as $xCallback) |
|
| 116 | + foreach ($this->xCallbackManager->getBeforeCallbacks() as $xCallback) |
|
| 117 | 117 | { |
| 118 | 118 | $xReturn = call_user_func_array($xCallback, [$xTarget, &$bEndRequest]); |
| 119 | - if($xReturn instanceof ResponseInterface) |
|
| 119 | + if ($xReturn instanceof ResponseInterface) |
|
| 120 | 120 | { |
| 121 | 121 | $this->xResponseManager->append($xReturn); |
| 122 | 122 | } |
| 123 | - if($bEndRequest) |
|
| 123 | + if ($bEndRequest) |
|
| 124 | 124 | { |
| 125 | 125 | return; |
| 126 | 126 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function onAfter(bool $bEndRequest) |
| 137 | 137 | { |
| 138 | - foreach($this->xCallbackManager->getAfterCallbacks() as $xCallback) |
|
| 138 | + foreach ($this->xCallbackManager->getAfterCallbacks() as $xCallback) |
|
| 139 | 139 | { |
| 140 | 140 | $xReturn = call_user_func_array($xCallback, |
| 141 | 141 | [$this->xRequestPlugin->getTarget(), $bEndRequest]); |
| 142 | - if($xReturn instanceof ResponseInterface) |
|
| 142 | + if ($xReturn instanceof ResponseInterface) |
|
| 143 | 143 | { |
| 144 | 144 | $this->xResponseManager->append($xReturn); |
| 145 | 145 | } |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function onInvalid(RequestException $xException) |
| 158 | 158 | { |
| 159 | - foreach($this->xCallbackManager->getInvalidCallbacks() as $xCallback) |
|
| 159 | + foreach ($this->xCallbackManager->getInvalidCallbacks() as $xCallback) |
|
| 160 | 160 | { |
| 161 | 161 | $xReturn = call_user_func($xCallback, $xException); |
| 162 | - if($xReturn instanceof ResponseInterface) |
|
| 162 | + if ($xReturn instanceof ResponseInterface) |
|
| 163 | 163 | { |
| 164 | 164 | $this->xResponseManager->append($xReturn); |
| 165 | 165 | } |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function onError(Exception $xException) |
| 178 | 178 | { |
| 179 | - foreach($this->xCallbackManager->getErrorCallbacks() as $xCallback) |
|
| 179 | + foreach ($this->xCallbackManager->getErrorCallbacks() as $xCallback) |
|
| 180 | 180 | { |
| 181 | 181 | $xReturn = call_user_func($xCallback, $xException); |
| 182 | - if($xReturn instanceof ResponseInterface) |
|
| 182 | + if ($xReturn instanceof ResponseInterface) |
|
| 183 | 183 | { |
| 184 | 184 | $this->xResponseManager->append($xReturn); |
| 185 | 185 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | public function canProcessRequest(): bool |
| 197 | 197 | { |
| 198 | 198 | // Return true if the request plugin was already found |
| 199 | - if($this->xRequestPlugin !== null) |
|
| 199 | + if ($this->xRequestPlugin !== null) |
|
| 200 | 200 | { |
| 201 | 201 | return true; |
| 202 | 202 | } |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | // The HTTP request |
| 205 | 205 | $xRequest = $this->di->getRequest(); |
| 206 | 206 | // Find a plugin to process the request |
| 207 | - foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 207 | + foreach ($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 208 | 208 | { |
| 209 | - if($sClassName::canProcessRequest($xRequest)) |
|
| 209 | + if ($sClassName::canProcessRequest($xRequest)) |
|
| 210 | 210 | { |
| 211 | 211 | $this->xRequestPlugin = $this->di->g($sClassName); |
| 212 | 212 | $this->xRequestPlugin->setTarget($xRequest); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // Check if the upload plugin is enabled |
| 218 | - if($this->xUploadHandler === null) |
|
| 218 | + if ($this->xUploadHandler === null) |
|
| 219 | 219 | { |
| 220 | 220 | return false; |
| 221 | 221 | } |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | // The HTTP request |
| 238 | 238 | $xRequest = $this->di->getRequest(); |
| 239 | 239 | // Process uploaded files, if the upload plugin is enabled |
| 240 | - if($this->xUploadHandler !== null && $this->xUploadHandler->canProcessRequest($xRequest)) |
|
| 240 | + if ($this->xUploadHandler !== null && $this->xUploadHandler->canProcessRequest($xRequest)) |
|
| 241 | 241 | { |
| 242 | 242 | $this->xUploadHandler->processRequest($xRequest); |
| 243 | 243 | } |
| 244 | 244 | // Process the request |
| 245 | - if(($this->xRequestPlugin)) |
|
| 245 | + if (($this->xRequestPlugin)) |
|
| 246 | 246 | { |
| 247 | 247 | $xResponse = $this->xRequestPlugin->processRequest(); |
| 248 | - if(($xResponse)) |
|
| 248 | + if (($xResponse)) |
|
| 249 | 249 | { |
| 250 | 250 | $this->xResponseManager->append($xResponse); |
| 251 | 251 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | public function processRequest() |
| 267 | 267 | { |
| 268 | 268 | // Check if there is a plugin to process this request |
| 269 | - if(!$this->canProcessRequest()) |
|
| 269 | + if (!$this->canProcessRequest()) |
|
| 270 | 270 | { |
| 271 | 271 | return; |
| 272 | 272 | } |
@@ -275,11 +275,11 @@ discard block |
||
| 275 | 275 | { |
| 276 | 276 | $bEndRequest = false; |
| 277 | 277 | // Handle before processing event |
| 278 | - if(($this->xRequestPlugin)) |
|
| 278 | + if (($this->xRequestPlugin)) |
|
| 279 | 279 | { |
| 280 | 280 | $this->onBefore($bEndRequest); |
| 281 | 281 | } |
| 282 | - if($bEndRequest) |
|
| 282 | + if ($bEndRequest) |
|
| 283 | 283 | { |
| 284 | 284 | return; |
| 285 | 285 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $this->_processRequest(); |
| 288 | 288 | |
| 289 | 289 | // Handle after processing event |
| 290 | - if(($this->xRequestPlugin)) |
|
| 290 | + if (($this->xRequestPlugin)) |
|
| 291 | 291 | { |
| 292 | 292 | $this->onAfter($bEndRequest); |
| 293 | 293 | } |
@@ -295,13 +295,13 @@ discard block |
||
| 295 | 295 | // An exception was thrown while processing the request. |
| 296 | 296 | // The request missed the corresponding handler function, |
| 297 | 297 | // or an error occurred while attempting to execute the handler. |
| 298 | - catch(RequestException $e) |
|
| 298 | + catch (RequestException $e) |
|
| 299 | 299 | { |
| 300 | 300 | $this->xResponseManager->error($e->getMessage()); |
| 301 | 301 | $this->onInvalid($e); |
| 302 | 302 | throw $e; |
| 303 | 303 | } |
| 304 | - catch(Exception $e) |
|
| 304 | + catch (Exception $e) |
|
| 305 | 305 | { |
| 306 | 306 | $this->xResponseManager->error($e->getMessage()); |
| 307 | 307 | $this->onError($e); |
@@ -300,8 +300,7 @@ |
||
| 300 | 300 | $this->xResponseManager->error($e->getMessage()); |
| 301 | 301 | $this->onInvalid($e); |
| 302 | 302 | throw $e; |
| 303 | - } |
|
| 304 | - catch(Exception $e) |
|
| 303 | + } catch(Exception $e) |
|
| 305 | 304 | { |
| 306 | 305 | $this->xResponseManager->error($e->getMessage()); |
| 307 | 306 | $this->onError($e); |
@@ -196,19 +196,19 @@ |
||
| 196 | 196 | $sValue = substr($sValue, 1); |
| 197 | 197 | switch($cType) |
| 198 | 198 | { |
| 199 | - case 'S': |
|
| 200 | - $value = !$sValue ? '' : $sValue; |
|
| 201 | - break; |
|
| 202 | - case 'B': |
|
| 203 | - $value = $this->convertStringToBool($sValue); |
|
| 204 | - break; |
|
| 205 | - case 'N': |
|
| 206 | - $value = ($sValue == floor($sValue) ? (int)$sValue : (float)$sValue); |
|
| 207 | - break; |
|
| 208 | - case '*': |
|
| 209 | - default: |
|
| 210 | - $value = null; |
|
| 211 | - break; |
|
| 199 | + case 'S': |
|
| 200 | + $value = !$sValue ? '' : $sValue; |
|
| 201 | + break; |
|
| 202 | + case 'B': |
|
| 203 | + $value = $this->convertStringToBool($sValue); |
|
| 204 | + break; |
|
| 205 | + case 'N': |
|
| 206 | + $value = ($sValue == floor($sValue) ? (int)$sValue : (float)$sValue); |
|
| 207 | + break; |
|
| 208 | + case '*': |
|
| 209 | + default: |
|
| 210 | + $value = null; |
|
| 211 | + break; |
|
| 212 | 212 | } |
| 213 | 213 | return $value; |
| 214 | 214 | } |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | // Parameters are url encoded when uploading files |
| 108 | 108 | $aServerParams = $this->di->getRequest()->getServerParams(); |
| 109 | 109 | $sContentType = ''; |
| 110 | - if(isset($aServerParams['CONTENT_TYPE'])) |
|
| 110 | + if (isset($aServerParams['CONTENT_TYPE'])) |
|
| 111 | 111 | { |
| 112 | 112 | $sContentType = $aServerParams['CONTENT_TYPE']; |
| 113 | 113 | } |
| 114 | - elseif(isset($aServerParams['HTTP_CONTENT_TYPE'])) |
|
| 114 | + elseif (isset($aServerParams['HTTP_CONTENT_TYPE'])) |
|
| 115 | 115 | { |
| 116 | 116 | $sContentType = $aServerParams['HTTP_CONTENT_TYPE']; |
| 117 | 117 | } |
| 118 | 118 | $sType = 'multipart/form-data'; |
| 119 | - if(strncmp($sContentType, $sType, strlen($sType)) !== 0) |
|
| 119 | + if (strncmp($sContentType, $sType, strlen($sType)) !== 0) |
|
| 120 | 120 | { |
| 121 | 121 | $this->cParamDecoder = function($sParam) { return $sParam; }; |
| 122 | 122 | return; |
@@ -137,19 +137,19 @@ discard block |
||
| 137 | 137 | return $sStr; |
| 138 | 138 | }; |
| 139 | 139 | $sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
| 140 | - if(function_exists('iconv')) |
|
| 140 | + if (function_exists('iconv')) |
|
| 141 | 141 | { |
| 142 | 142 | $this->cUtf8Decoder = function($sStr) use($sEncoding) { |
| 143 | 143 | return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
| 144 | 144 | }; |
| 145 | 145 | } |
| 146 | - elseif(function_exists('mb_convert_encoding')) |
|
| 146 | + elseif (function_exists('mb_convert_encoding')) |
|
| 147 | 147 | { |
| 148 | 148 | $this->cUtf8Decoder = function($sStr) use($sEncoding) { |
| 149 | 149 | return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
| 150 | 150 | }; |
| 151 | 151 | } |
| 152 | - elseif($sEncoding === "ISO-8859-1") |
|
| 152 | + elseif ($sEncoding === "ISO-8859-1") |
|
| 153 | 153 | { |
| 154 | 154 | $this->cUtf8Decoder = function($sStr) { |
| 155 | 155 | return utf8_decode($sStr); |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | private function convertStringToBool(string $sValue): bool |
| 172 | 172 | { |
| 173 | - if(strcasecmp($sValue, 'true') === 0) |
|
| 173 | + if (strcasecmp($sValue, 'true') === 0) |
|
| 174 | 174 | { |
| 175 | 175 | return true; |
| 176 | 176 | } |
| 177 | - if(strcasecmp($sValue, 'false') === 0) |
|
| 177 | + if (strcasecmp($sValue, 'false') === 0) |
|
| 178 | 178 | { |
| 179 | 179 | return false; |
| 180 | 180 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | { |
| 195 | 195 | $cType = substr($sValue, 0, 1); |
| 196 | 196 | $sValue = substr($sValue, 1); |
| 197 | - switch($cType) |
|
| 197 | + switch ($cType) |
|
| 198 | 198 | { |
| 199 | 199 | case 'S': |
| 200 | 200 | $value = !$sValue ? '' : $sValue; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $value = $this->convertStringToBool($sValue); |
| 204 | 204 | break; |
| 205 | 205 | case 'N': |
| 206 | - $value = ($sValue == floor($sValue) ? (int)$sValue : (float)$sValue); |
|
| 206 | + $value = ($sValue == floor($sValue) ? (int) $sValue : (float) $sValue); |
|
| 207 | 207 | break; |
| 208 | 208 | case '*': |
| 209 | 209 | default: |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | private function decodeRequestParameter(string $sParam) |
| 224 | 224 | { |
| 225 | - if($sParam === '') |
|
| 225 | + if ($sParam === '') |
|
| 226 | 226 | { |
| 227 | 227 | return $sParam; |
| 228 | 228 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | $sParam = call_user_func($this->cParamDecoder, $sParam); |
| 231 | 231 | |
| 232 | 232 | $xJson = json_decode($sParam, true); |
| 233 | - if($xJson !== null && $sParam != $xJson) |
|
| 233 | + if ($xJson !== null && $sParam != $xJson) |
|
| 234 | 234 | { |
| 235 | 235 | return $xJson; |
| 236 | 236 | } |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | $aParams = []; |
| 246 | 246 | $xRequest = $this->di->getRequest(); |
| 247 | 247 | $aBody = $xRequest->getParsedBody(); |
| 248 | - if(is_array($aBody)) |
|
| 248 | + if (is_array($aBody)) |
|
| 249 | 249 | { |
| 250 | - if(isset($aBody['jxnargs'])) |
|
| 250 | + if (isset($aBody['jxnargs'])) |
|
| 251 | 251 | { |
| 252 | 252 | $aParams = $aBody['jxnargs']; |
| 253 | 253 | } |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | else |
| 256 | 256 | { |
| 257 | 257 | $aParams = $xRequest->getQueryParams(); |
| 258 | - if(isset($aParams['jxnargs'])) |
|
| 258 | + if (isset($aParams['jxnargs'])) |
|
| 259 | 259 | { |
| 260 | 260 | $aParams = $aParams['jxnargs']; |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | return array_map(function($sParam) { |
| 264 | - return $this->decodeRequestParameter((string)$sParam); |
|
| 264 | + return $this->decodeRequestParameter((string) $sParam); |
|
| 265 | 265 | }, $aParams); |
| 266 | 266 | } |
| 267 | 267 | |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | private function decodeUtf8Parameter($xValue) |
| 276 | 276 | { |
| 277 | - if(is_string($xValue)) |
|
| 277 | + if (is_string($xValue)) |
|
| 278 | 278 | { |
| 279 | 279 | return call_user_func($this->cUtf8Decoder, $xValue); |
| 280 | 280 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | private function decodeUtf8Parameters(array $aParams): array |
| 295 | 295 | { |
| 296 | 296 | $aValues = []; |
| 297 | - foreach($aParams as $sKey => $xValue) |
|
| 297 | + foreach ($aParams as $sKey => $xValue) |
|
| 298 | 298 | { |
| 299 | 299 | // Decode the key |
| 300 | 300 | $sKey = call_user_func($this->cUtf8Decoder, $sKey); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | { |
| 316 | 316 | $this->setParamDecoder(); |
| 317 | 317 | $aParams = $this->getRequestParameters(); |
| 318 | - if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 318 | + if (!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 319 | 319 | { |
| 320 | 320 | return $aParams; |
| 321 | 321 | } |
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | if(isset($aServerParams['CONTENT_TYPE'])) |
| 111 | 111 | { |
| 112 | 112 | $sContentType = $aServerParams['CONTENT_TYPE']; |
| 113 | - } |
|
| 114 | - elseif(isset($aServerParams['HTTP_CONTENT_TYPE'])) |
|
| 113 | + } elseif(isset($aServerParams['HTTP_CONTENT_TYPE'])) |
|
| 115 | 114 | { |
| 116 | 115 | $sContentType = $aServerParams['HTTP_CONTENT_TYPE']; |
| 117 | 116 | } |
@@ -142,20 +141,17 @@ discard block |
||
| 142 | 141 | $this->cUtf8Decoder = function($sStr) use($sEncoding) { |
| 143 | 142 | return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
| 144 | 143 | }; |
| 145 | - } |
|
| 146 | - elseif(function_exists('mb_convert_encoding')) |
|
| 144 | + } elseif(function_exists('mb_convert_encoding')) |
|
| 147 | 145 | { |
| 148 | 146 | $this->cUtf8Decoder = function($sStr) use($sEncoding) { |
| 149 | 147 | return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
| 150 | 148 | }; |
| 151 | - } |
|
| 152 | - elseif($sEncoding === "ISO-8859-1") |
|
| 149 | + } elseif($sEncoding === "ISO-8859-1") |
|
| 153 | 150 | { |
| 154 | 151 | $this->cUtf8Decoder = function($sStr) { |
| 155 | 152 | return utf8_decode($sStr); |
| 156 | 153 | }; |
| 157 | - } |
|
| 158 | - else |
|
| 154 | + } else |
|
| 159 | 155 | { |
| 160 | 156 | throw new RequestException($this->xTranslator->trans('errors.request.conversion')); |
| 161 | 157 | } |
@@ -251,8 +247,7 @@ discard block |
||
| 251 | 247 | { |
| 252 | 248 | $aParams = $aBody['jxnargs']; |
| 253 | 249 | } |
| 254 | - } |
|
| 255 | - else |
|
| 250 | + } else |
|
| 256 | 251 | { |
| 257 | 252 | $aParams = $xRequest->getQueryParams(); |
| 258 | 253 | if(isset($aParams['jxnargs'])) |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function canProcessRequest(ServerRequestInterface $xRequest): bool |
| 124 | 124 | { |
| 125 | - if(count($xRequest->getUploadedFiles()) > 0) |
|
| 125 | + if (count($xRequest->getUploadedFiles()) > 0) |
|
| 126 | 126 | { |
| 127 | 127 | return true; |
| 128 | 128 | } |
| 129 | 129 | $aBody = $xRequest->getParsedBody(); |
| 130 | - if(is_array($aBody)) |
|
| 130 | + if (is_array($aBody)) |
|
| 131 | 131 | { |
| 132 | 132 | return isset($aBody['jxnupl']); |
| 133 | 133 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | private function setTempFile(ServerRequestInterface $xRequest): bool |
| 146 | 146 | { |
| 147 | 147 | $aBody = $xRequest->getParsedBody(); |
| 148 | - if(is_array($aBody)) |
|
| 148 | + if (is_array($aBody)) |
|
| 149 | 149 | { |
| 150 | 150 | $this->sTempFile = trim($aBody['jxnupl'] ?? ''); |
| 151 | 151 | return $this->sTempFile !== ''; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | public function processRequest(ServerRequestInterface $xRequest): bool |
| 167 | 167 | { |
| 168 | 168 | $xUploadManager = $this->di->getUploadManager(); |
| 169 | - if($this->setTempFile($xRequest)) |
|
| 169 | + if ($this->setTempFile($xRequest)) |
|
| 170 | 170 | { |
| 171 | 171 | // Ajax request following a normal HTTP upload. |
| 172 | 172 | // Copy the previously uploaded files' location from the temp file. |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | return true; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if($this->bIsAjaxRequest) |
|
| 177 | + if ($this->bIsAjaxRequest) |
|
| 178 | 178 | { |
| 179 | 179 | // Ajax request with upload. |
| 180 | 180 | // Copy the uploaded files from the HTTP request. |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $sTempFile = $xUploadManager->saveToTempFile($this->aUserFiles); |
| 192 | 192 | $this->xResponseManager->append(new UploadResponse($this->di->getPsr17Factory(), $sTempFile)); |
| 193 | 193 | } |
| 194 | - catch(Exception $e) |
|
| 194 | + catch (Exception $e) |
|
| 195 | 195 | { |
| 196 | 196 | $this->xResponseManager->append(new UploadResponse($this->di->getPsr17Factory(), '', $e->getMessage())); |
| 197 | 197 | } |
@@ -190,8 +190,7 @@ |
||
| 190 | 190 | $this->aUserFiles = $xUploadManager->readFromHttpData($xRequest); |
| 191 | 191 | $sTempFile = $xUploadManager->saveToTempFile($this->aUserFiles); |
| 192 | 192 | $this->xResponseManager->append(new UploadResponse($this->di->getPsr17Factory(), $sTempFile)); |
| 193 | - } |
|
| 194 | - catch(Exception $e) |
|
| 193 | + } catch(Exception $e) |
|
| 195 | 194 | { |
| 196 | 195 | $this->xResponseManager->append(new UploadResponse($this->di->getPsr17Factory(), '', $e->getMessage())); |
| 197 | 196 | } |
@@ -150,12 +150,12 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $sUploadDir = realpath(rtrim(trim($sUploadDir), '/\\')); |
| 152 | 152 | // Verify that the upload dir exists and is writable |
| 153 | - if(!is_dir($sUploadDir) || !is_writable($sUploadDir)) |
|
| 153 | + if (!is_dir($sUploadDir) || !is_writable($sUploadDir)) |
|
| 154 | 154 | { |
| 155 | 155 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 156 | 156 | } |
| 157 | 157 | $sUploadDir .= DIRECTORY_SEPARATOR . $sUploadSubDir . DIRECTORY_SEPARATOR; |
| 158 | - if(!file_exists($sUploadDir) && !@mkdir($sUploadDir)) |
|
| 158 | + if (!file_exists($sUploadDir) && !@mkdir($sUploadDir)) |
|
| 159 | 159 | { |
| 160 | 160 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 161 | 161 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | // Default upload dir |
| 176 | 176 | $sDefaultUploadDir = $this->xConfigManager->getOption('upload.default.dir'); |
| 177 | 177 | $sUploadDir = $this->xConfigManager->getOption('upload.files.' . $sFieldId . '.dir', $sDefaultUploadDir); |
| 178 | - if(!is_string($sUploadDir)) |
|
| 178 | + if (!is_string($sUploadDir)) |
|
| 179 | 179 | { |
| 180 | 180 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 181 | 181 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | { |
| 193 | 193 | // Default upload dir |
| 194 | 194 | $sUploadDir = $this->xConfigManager->getOption('upload.default.dir'); |
| 195 | - if(!is_string($sUploadDir)) |
|
| 195 | + if (!is_string($sUploadDir)) |
|
| 196 | 196 | { |
| 197 | 197 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 198 | 198 | } |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | // Filename without the extension. Needs to be sanitized. |
| 215 | 215 | $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME); |
| 216 | - if($this->cNameSanitizer !== null) |
|
| 216 | + if ($this->cNameSanitizer !== null) |
|
| 217 | 217 | { |
| 218 | - $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sVarName, $this->sUploadFieldId); |
|
| 218 | + $sName = (string) call_user_func($this->cNameSanitizer, $sName, $sVarName, $this->sUploadFieldId); |
|
| 219 | 219 | } |
| 220 | 220 | // Check the uploaded file validity |
| 221 | - if($xHttpFile->getError()) |
|
| 221 | + if ($xHttpFile->getError()) |
|
| 222 | 222 | { |
| 223 | 223 | throw new RequestException($this->xTranslator->trans('errors.upload.failed', ['name' => $sVarName])); |
| 224 | 224 | } |
| 225 | 225 | // Set the user file data |
| 226 | 226 | $xFile = File::fromHttpFile($sName, $sUploadDir, $xHttpFile); |
| 227 | 227 | // Verify file validity (format, size) |
| 228 | - if(!$this->xValidator->validateUploadedFile($sVarName, $xFile)) |
|
| 228 | + if (!$this->xValidator->validateUploadedFile($sVarName, $xFile)) |
|
| 229 | 229 | { |
| 230 | 230 | throw new RequestException($this->xValidator->getErrorMessage()); |
| 231 | 231 | } |
@@ -249,22 +249,22 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | $aUserFiles = []; |
| 251 | 251 | $this->aAllFiles = []; // A flat list of all uploaded files |
| 252 | - foreach($aTempFiles as $sVarName => $aFiles) |
|
| 252 | + foreach ($aTempFiles as $sVarName => $aFiles) |
|
| 253 | 253 | { |
| 254 | 254 | $aUserFiles[$sVarName] = []; |
| 255 | 255 | // Get the path to the upload dir |
| 256 | 256 | $sUploadDir = $this->getUploadDir($sVarName); |
| 257 | - if(!is_array($aFiles)) |
|
| 257 | + if (!is_array($aFiles)) |
|
| 258 | 258 | { |
| 259 | 259 | $aFiles = [$aFiles]; |
| 260 | 260 | } |
| 261 | - foreach($aFiles as $xHttpFile) |
|
| 261 | + foreach ($aFiles as $xHttpFile) |
|
| 262 | 262 | { |
| 263 | 263 | $aUserFiles[$sVarName][] = $this->makeUploadedFile($sVarName, $sUploadDir, $xHttpFile); |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | // Copy the uploaded files from the temp dir to the user dir |
| 267 | - foreach($this->aAllFiles as $aFiles) |
|
| 267 | + foreach ($this->aAllFiles as $aFiles) |
|
| 268 | 268 | { |
| 269 | 269 | $aFiles['temp']->moveTo($aFiles['user']->path()); |
| 270 | 270 | } |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | { |
| 284 | 284 | // Convert uploaded file to an array |
| 285 | 285 | $aFiles = []; |
| 286 | - foreach($aUserFiles as $sVarName => $aVarFiles) |
|
| 286 | + foreach ($aUserFiles as $sVarName => $aVarFiles) |
|
| 287 | 287 | { |
| 288 | 288 | $aFiles[$sVarName] = []; |
| 289 | - foreach($aVarFiles as $aVarFile) |
|
| 289 | + foreach ($aVarFiles as $aVarFile) |
|
| 290 | 290 | { |
| 291 | 291 | $aFiles[$sVarName][] = $aVarFile->toTempData(); |
| 292 | 292 | } |
@@ -309,14 +309,14 @@ discard block |
||
| 309 | 309 | protected function getUploadTempFile(string $sTempFile): string |
| 310 | 310 | { |
| 311 | 311 | // Verify file name validity |
| 312 | - if(!$this->xValidator->validateTempFileName($sTempFile)) |
|
| 312 | + if (!$this->xValidator->validateTempFileName($sTempFile)) |
|
| 313 | 313 | { |
| 314 | 314 | throw new RequestException($this->xTranslator->trans('errors.upload.invalid')); |
| 315 | 315 | } |
| 316 | 316 | $sUploadDir = $this->xConfigManager->getOption('upload.default.dir', ''); |
| 317 | 317 | $sUploadDir = realpath(rtrim(trim($sUploadDir), '/\\')) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; |
| 318 | 318 | $sUploadTempFile = $sUploadDir . $sTempFile . '.json'; |
| 319 | - if(!is_readable($sUploadTempFile)) |
|
| 319 | + if (!is_readable($sUploadTempFile)) |
|
| 320 | 320 | { |
| 321 | 321 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 322 | 322 | } |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | $sUploadTempFile = $this->getUploadTempFile($sTempFile); |
| 338 | 338 | $aFiles = json_decode(file_get_contents($sUploadTempFile), true); |
| 339 | 339 | $aUserFiles = []; |
| 340 | - foreach($aFiles as $sVarName => $aVarFiles) |
|
| 340 | + foreach ($aFiles as $sVarName => $aVarFiles) |
|
| 341 | 341 | { |
| 342 | 342 | $aUserFiles[$sVarName] = []; |
| 343 | - foreach($aVarFiles as $aVarFile) |
|
| 343 | + foreach ($aVarFiles as $aVarFile) |
|
| 344 | 344 | { |
| 345 | 345 | $aUserFiles[$sVarName][] = File::fromTempFile($aVarFile); |
| 346 | 346 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty); |
| 140 | 140 | $aAllowed = $this->xConfigManager->getOption('upload.files.' . $sName . '.' . $sProperty, $xDefault); |
| 141 | - if(is_array($aAllowed) && !in_array($sValue, $aAllowed)) |
|
| 141 | + if (is_array($aAllowed) && !in_array($sValue, $aAllowed)) |
|
| 142 | 142 | { |
| 143 | 143 | $this->sErrorMessage = $this->xTranslator->trans('errors.upload.' . $sField, [$sField => $sValue]); |
| 144 | 144 | return false; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | { |
| 160 | 160 | $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty, 0); |
| 161 | 161 | $nSize = $this->xConfigManager->getOption('upload.files.' . $sName . '.' . $sProperty, $xDefault); |
| 162 | - if($nSize > 0 && ( |
|
| 162 | + if ($nSize > 0 && ( |
|
| 163 | 163 | ($sProperty == 'max-size' && $nFileSize > $nSize) || |
| 164 | 164 | ($sProperty == 'min-size' && $nFileSize < $nSize))) |
| 165 | 165 | { |
@@ -181,25 +181,25 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | $this->sErrorMessage = ''; |
| 183 | 183 | // Verify the file extension |
| 184 | - if(!$this->validateFileProperty($sName, $xFile->type(), 'types', 'type')) |
|
| 184 | + if (!$this->validateFileProperty($sName, $xFile->type(), 'types', 'type')) |
|
| 185 | 185 | { |
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Verify the file extension |
| 190 | - if(!$this->validateFileProperty($sName, $xFile->extension(), 'extensions', 'extension')) |
|
| 190 | + if (!$this->validateFileProperty($sName, $xFile->extension(), 'extensions', 'extension')) |
|
| 191 | 191 | { |
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Verify the max size |
| 196 | - if(!$this->validateFileSize($sName, $xFile->size(), 'max-size')) |
|
| 196 | + if (!$this->validateFileSize($sName, $xFile->size(), 'max-size')) |
|
| 197 | 197 | { |
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Verify the min size |
| 202 | - if(!$this->validateFileSize($sName, $xFile->size(), 'min-size')) |
|
| 202 | + if (!$this->validateFileSize($sName, $xFile->size(), 'min-size')) |
|
| 203 | 203 | { |
| 204 | 204 | return false; |
| 205 | 205 | } |