@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | function register(Container $di, bool $bForce = false) |
| 29 | 29 | { |
| 30 | - if(!$bForce && $di->h(UploadHandler::class)) |
|
| 30 | + if (!$bForce && $di->h(UploadHandler::class)) |
|
| 31 | 31 | { |
| 32 | 32 | return; |
| 33 | 33 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $di = jaxon()->di(); |
| 75 | 75 | $sEventListenerKey = UploadHandler::class . '\\ConfigListener'; |
| 76 | - if($di->h($sEventListenerKey)) |
|
| 76 | + if ($di->h($sEventListenerKey)) |
|
| 77 | 77 | { |
| 78 | 78 | return; |
| 79 | 79 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function onChange(Config $xConfig, string $sName) |
| 87 | 87 | { |
| 88 | 88 | $sConfigKey = 'core.upload.enabled'; |
| 89 | - if(($sName === $sConfigKey || $sName === '') && $xConfig->getOption($sConfigKey)) |
|
| 89 | + if (($sName === $sConfigKey || $sName === '') && $xConfig->getOption($sConfigKey)) |
|
| 90 | 90 | { |
| 91 | 91 | register(jaxon()->di()); |
| 92 | 92 | } |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | try |
| 154 | 154 | { |
| 155 | 155 | $xFilesystem->createDirectory($sUploadDir); |
| 156 | - if($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC) |
|
| 156 | + if ($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC) |
|
| 157 | 157 | { |
| 158 | 158 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 159 | 159 | } |
| 160 | 160 | return $sUploadDir; |
| 161 | 161 | } |
| 162 | - catch(FilesystemException $e) |
|
| 162 | + catch (FilesystemException $e) |
|
| 163 | 163 | { |
| 164 | 164 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 165 | 165 | } |
@@ -205,20 +205,20 @@ discard block |
||
| 205 | 205 | private function makeUploadedFile(Filesystem $xFilesystem, string $sUploadDir, string $sVarName, UploadedFile $xHttpFile): File |
| 206 | 206 | { |
| 207 | 207 | // Check the uploaded file validity |
| 208 | - if($xHttpFile->getError()) |
|
| 208 | + if ($xHttpFile->getError()) |
|
| 209 | 209 | { |
| 210 | 210 | throw new RequestException($this->xTranslator->trans('errors.upload.failed', ['name' => $sVarName])); |
| 211 | 211 | } |
| 212 | 212 | // Set the user file data |
| 213 | 213 | $xFile = File::fromHttpFile($xFilesystem, $sUploadDir, $xHttpFile); |
| 214 | 214 | // Verify file validity (format, size) |
| 215 | - if(!$this->xValidator->validateUploadedFile($sVarName, $xFile)) |
|
| 215 | + if (!$this->xValidator->validateUploadedFile($sVarName, $xFile)) |
|
| 216 | 216 | { |
| 217 | 217 | throw new RequestException($this->xValidator->getErrorMessage()); |
| 218 | 218 | } |
| 219 | 219 | // Filename without the extension. Needs to be sanitized. |
| 220 | 220 | $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME); |
| 221 | - if($this->cNameSanitizer !== null) |
|
| 221 | + if ($this->cNameSanitizer !== null) |
|
| 222 | 222 | { |
| 223 | 223 | $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sVarName, $this->sUploadFieldId); |
| 224 | 224 | } |
@@ -243,16 +243,16 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $aUserFiles = []; |
| 245 | 245 | $this->aAllFiles = []; // A flat list of all uploaded files |
| 246 | - foreach($aTempFiles as $sVarName => $aFiles) |
|
| 246 | + foreach ($aTempFiles as $sVarName => $aFiles) |
|
| 247 | 247 | { |
| 248 | 248 | $aUserFiles[$sVarName] = []; |
| 249 | 249 | // Get the path to the upload dir |
| 250 | 250 | [$xFilesystem, $sUploadDir] = $this->getUploadDir($sVarName); |
| 251 | - if(!is_array($aFiles)) |
|
| 251 | + if (!is_array($aFiles)) |
|
| 252 | 252 | { |
| 253 | 253 | $aFiles = [$aFiles]; |
| 254 | 254 | } |
| 255 | - foreach($aFiles as $xHttpFile) |
|
| 255 | + foreach ($aFiles as $xHttpFile) |
|
| 256 | 256 | { |
| 257 | 257 | $aUserFiles[$sVarName][] = $this->makeUploadedFile($xFilesystem, $sUploadDir, $sVarName, $xHttpFile); |
| 258 | 258 | } |
@@ -260,12 +260,12 @@ discard block |
||
| 260 | 260 | // Copy the uploaded files from the temp dir to the user dir |
| 261 | 261 | try |
| 262 | 262 | { |
| 263 | - foreach($this->aAllFiles as $aFiles) |
|
| 263 | + foreach ($this->aAllFiles as $aFiles) |
|
| 264 | 264 | { |
| 265 | 265 | $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream()->getContents()); |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | - catch(FilesystemException $e) |
|
| 268 | + catch (FilesystemException $e) |
|
| 269 | 269 | { |
| 270 | 270 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 271 | 271 | } |
@@ -284,10 +284,10 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | // Convert uploaded file to an array |
| 286 | 286 | $aFiles = []; |
| 287 | - foreach($aUserFiles as $sVarName => $aVarFiles) |
|
| 287 | + foreach ($aUserFiles as $sVarName => $aVarFiles) |
|
| 288 | 288 | { |
| 289 | 289 | $aFiles[$sVarName] = []; |
| 290 | - foreach($aVarFiles as $aVarFile) |
|
| 290 | + foreach ($aVarFiles as $aVarFile) |
|
| 291 | 291 | { |
| 292 | 292 | $aFiles[$sVarName][] = $aVarFile->toTempData(); |
| 293 | 293 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | { |
| 300 | 300 | $xFilesystem->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles)); |
| 301 | 301 | } |
| 302 | - catch(FilesystemException $e) |
|
| 302 | + catch (FilesystemException $e) |
|
| 303 | 303 | { |
| 304 | 304 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 305 | 305 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | private function getUploadTempFile(string $sTempFile): array |
| 318 | 318 | { |
| 319 | 319 | // Verify file name validity |
| 320 | - if(!$this->xValidator->validateTempFileName($sTempFile)) |
|
| 320 | + if (!$this->xValidator->validateTempFileName($sTempFile)) |
|
| 321 | 321 | { |
| 322 | 322 | throw new RequestException($this->xTranslator->trans('errors.upload.invalid')); |
| 323 | 323 | } |
@@ -325,13 +325,13 @@ discard block |
||
| 325 | 325 | $sUploadTempFile = $sUploadDir . $sTempFile . '.json'; |
| 326 | 326 | try |
| 327 | 327 | { |
| 328 | - if($xFilesystem->visibility($sUploadTempFile) !== Visibility::PUBLIC) |
|
| 328 | + if ($xFilesystem->visibility($sUploadTempFile) !== Visibility::PUBLIC) |
|
| 329 | 329 | { |
| 330 | 330 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 331 | 331 | } |
| 332 | 332 | return [$xFilesystem, $sUploadTempFile]; |
| 333 | 333 | } |
| 334 | - catch(FilesystemException $e) |
|
| 334 | + catch (FilesystemException $e) |
|
| 335 | 335 | { |
| 336 | 336 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 337 | 337 | } |
@@ -353,15 +353,15 @@ discard block |
||
| 353 | 353 | { |
| 354 | 354 | $aFiles = json_decode($xFilesystem->read($sUploadTempFile), true); |
| 355 | 355 | } |
| 356 | - catch(FilesystemException $e) |
|
| 356 | + catch (FilesystemException $e) |
|
| 357 | 357 | { |
| 358 | 358 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 359 | 359 | } |
| 360 | 360 | $aUserFiles = []; |
| 361 | - foreach($aFiles as $sVarName => $aVarFiles) |
|
| 361 | + foreach ($aFiles as $sVarName => $aVarFiles) |
|
| 362 | 362 | { |
| 363 | 363 | $aUserFiles[$sVarName] = []; |
| 364 | - foreach($aVarFiles as $aVarFile) |
|
| 364 | + foreach ($aVarFiles as $aVarFile) |
|
| 365 | 365 | { |
| 366 | 366 | $aUserFiles[$sVarName][] = File::fromTempFile($xFilesystem, $aVarFile); |
| 367 | 367 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | { |
| 371 | 371 | $xFilesystem->delete($sUploadTempFile); |
| 372 | 372 | } |
| 373 | - catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */} |
|
| 373 | + catch (FilesystemException $e) {/* Not a big deal if the file cannot be deleted. */} |
|
| 374 | 374 | return $aUserFiles; |
| 375 | 375 | } |
| 376 | 376 | } |
@@ -158,8 +158,7 @@ discard block |
||
| 158 | 158 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 159 | 159 | } |
| 160 | 160 | return $sUploadDir; |
| 161 | - } |
|
| 162 | - catch(FilesystemException $e) |
|
| 161 | + } catch(FilesystemException $e) |
|
| 163 | 162 | { |
| 164 | 163 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 165 | 164 | } |
@@ -264,8 +263,7 @@ discard block |
||
| 264 | 263 | { |
| 265 | 264 | $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream()->getContents()); |
| 266 | 265 | } |
| 267 | - } |
|
| 268 | - catch(FilesystemException $e) |
|
| 266 | + } catch(FilesystemException $e) |
|
| 269 | 267 | { |
| 270 | 268 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 271 | 269 | } |
@@ -298,8 +296,7 @@ discard block |
||
| 298 | 296 | try |
| 299 | 297 | { |
| 300 | 298 | $xFilesystem->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles)); |
| 301 | - } |
|
| 302 | - catch(FilesystemException $e) |
|
| 299 | + } catch(FilesystemException $e) |
|
| 303 | 300 | { |
| 304 | 301 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 305 | 302 | } |
@@ -330,8 +327,7 @@ discard block |
||
| 330 | 327 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 331 | 328 | } |
| 332 | 329 | return [$xFilesystem, $sUploadTempFile]; |
| 333 | - } |
|
| 334 | - catch(FilesystemException $e) |
|
| 330 | + } catch(FilesystemException $e) |
|
| 335 | 331 | { |
| 336 | 332 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 337 | 333 | } |
@@ -352,8 +348,7 @@ discard block |
||
| 352 | 348 | try |
| 353 | 349 | { |
| 354 | 350 | $aFiles = json_decode($xFilesystem->read($sUploadTempFile), true); |
| 355 | - } |
|
| 356 | - catch(FilesystemException $e) |
|
| 351 | + } catch(FilesystemException $e) |
|
| 357 | 352 | { |
| 358 | 353 | throw new RequestException($this->xTranslator->trans('errors.upload.access')); |
| 359 | 354 | } |
@@ -369,8 +364,7 @@ discard block |
||
| 369 | 364 | try |
| 370 | 365 | { |
| 371 | 366 | $xFilesystem->delete($sUploadTempFile); |
| 372 | - } |
|
| 373 | - catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */} |
|
| 367 | + } catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */} |
|
| 374 | 368 | return $aUserFiles; |
| 375 | 369 | } |
| 376 | 370 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty); |
| 99 | 99 | $aAllowed = $this->xConfigManager->getOption('upload.files.' . $sVarName . '.' . $sProperty, $xDefault); |
| 100 | - if(is_array($aAllowed) && !in_array($sValue, $aAllowed)) |
|
| 100 | + if (is_array($aAllowed) && !in_array($sValue, $aAllowed)) |
|
| 101 | 101 | { |
| 102 | 102 | $this->sErrorMessage = $this->xTranslator->trans('errors.upload.' . $sField, [$sField => $sValue]); |
| 103 | 103 | return false; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty, 0); |
| 120 | 120 | $nSize = $this->xConfigManager->getOption('upload.files.' . $sVarName . '.' . $sProperty, $xDefault); |
| 121 | - if($nSize > 0 && ( |
|
| 121 | + if ($nSize > 0 && ( |
|
| 122 | 122 | ($sProperty == 'max-size' && $nFileSize > $nSize) || |
| 123 | 123 | ($sProperty == 'min-size' && $nFileSize < $nSize))) |
| 124 | 124 | { |
@@ -140,25 +140,25 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $this->sErrorMessage = ''; |
| 142 | 142 | // Verify the file extension |
| 143 | - if(!$this->validateFileProperty($sVarName, $xFile->type(), 'types', 'type')) |
|
| 143 | + if (!$this->validateFileProperty($sVarName, $xFile->type(), 'types', 'type')) |
|
| 144 | 144 | { |
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Verify the file extension |
| 149 | - if(!$this->validateFileProperty($sVarName, $xFile->extension(), 'extensions', 'extension')) |
|
| 149 | + if (!$this->validateFileProperty($sVarName, $xFile->extension(), 'extensions', 'extension')) |
|
| 150 | 150 | { |
| 151 | 151 | return false; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Verify the max size |
| 155 | - if(!$this->validateFileSize($sVarName, $xFile->size(), 'max-size')) |
|
| 155 | + if (!$this->validateFileSize($sVarName, $xFile->size(), 'max-size')) |
|
| 156 | 156 | { |
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Verify the min size |
| 161 | - if(!$this->validateFileSize($sVarName, $xFile->size(), 'min-size')) |
|
| 161 | + if (!$this->validateFileSize($sVarName, $xFile->size(), 'min-size')) |
|
| 162 | 162 | { |
| 163 | 163 | return false; |
| 164 | 164 | } |