@@ -20,45 +20,45 @@ |
||
| 20 | 20 | |
| 21 | 21 | interface UploadHandlerInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Set the uploaded file name sanitizer |
| 25 | 25 | * |
| 26 | 26 | * @param Closure $cSanitizer The closure |
| 27 | 27 | * |
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | - public function sanitizer(Closure $cSanitizer); |
|
| 30 | +public function sanitizer(Closure $cSanitizer); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * Get the uploaded files |
| 34 | 34 | * |
| 35 | 35 | * @return FileInterface[] |
| 36 | 36 | */ |
| 37 | - public function files(): array; |
|
| 37 | +public function files(): array; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * Check if the current request contains uploaded files |
| 41 | 41 | * |
| 42 | 42 | * @param ServerRequestInterface $xRequest |
| 43 | 43 | * |
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | - public function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 46 | +public function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Process the uploaded files in the HTTP request |
| 50 | 50 | * |
| 51 | 51 | * @param ServerRequestInterface $xRequest |
| 52 | 52 | * |
| 53 | 53 | * @return bool |
| 54 | 54 | */ |
| 55 | - public function processRequest(ServerRequestInterface $xRequest): bool; |
|
| 55 | +public function processRequest(ServerRequestInterface $xRequest): bool; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @param string $sStorage |
| 59 | 59 | * @param Closure $cFactory |
| 60 | 60 | * |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function registerStorageAdapter(string $sStorage, Closure $cFactory); |
|
| 63 | +public function registerStorageAdapter(string $sStorage, Closure $cFactory); |
|
| 64 | 64 | } |
@@ -133,13 +133,13 @@ discard block |
||
| 133 | 133 | try |
| 134 | 134 | {
|
| 135 | 135 | $xFilesystem->createDirectory($sUploadDir); |
| 136 | - if(!$xFilesystem->directoryExists($sUploadDir)) |
|
| 136 | + if (!$xFilesystem->directoryExists($sUploadDir)) |
|
| 137 | 137 | {
|
| 138 | 138 | throw new RequestException($this->xTranslator->trans('errors.upload.access'));
|
| 139 | 139 | } |
| 140 | 140 | return $sUploadDir; |
| 141 | 141 | } |
| 142 | - catch(FilesystemException $e) |
|
| 142 | + catch (FilesystemException $e) |
|
| 143 | 143 | {
|
| 144 | 144 | $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
|
| 145 | 145 | throw new RequestException($this->xTranslator->trans('errors.upload.access'));
|
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | {
|
| 174 | 174 | // Check the uploaded file validity |
| 175 | 175 | $nErrorCode = $xHttpFile->getError(); |
| 176 | - if($nErrorCode !== UPLOAD_ERR_OK) |
|
| 176 | + if ($nErrorCode !== UPLOAD_ERR_OK) |
|
| 177 | 177 | {
|
| 178 | 178 | $this->xLogger->error('File upload error.', [
|
| 179 | 179 | 'code' => $nErrorCode, |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | // Filename without the extension. Needs to be sanitized. |
| 186 | 186 | $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME); |
| 187 | - if($this->cNameSanitizer !== null) |
|
| 187 | + if ($this->cNameSanitizer !== null) |
|
| 188 | 188 | {
|
| 189 | 189 | $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sField, $this->sUploadFieldId); |
| 190 | 190 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | // Set the user file data |
| 193 | 193 | $xFile = File::fromHttpFile($this->xFileStorage->filesystem($sField), $xHttpFile, $sUploadDir, $sName); |
| 194 | 194 | // Verify file validity (format, size) |
| 195 | - if(!$this->xValidator->validateUploadedFile($sField, $xFile)) |
|
| 195 | + if (!$this->xValidator->validateUploadedFile($sField, $xFile)) |
|
| 196 | 196 | {
|
| 197 | 197 | throw new RequestException($this->xValidator->getErrorMessage()); |
| 198 | 198 | } |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | $aUserFiles = []; |
| 219 | 219 | $this->aAllFiles = []; // A flat list of all uploaded files |
| 220 | - foreach($aTempFiles as $sField => $aFiles) |
|
| 220 | + foreach ($aTempFiles as $sField => $aFiles) |
|
| 221 | 221 | {
|
| 222 | 222 | $aUserFiles[$sField] = []; |
| 223 | 223 | // Get the path to the upload dir |
| 224 | 224 | $sUploadDir = $this->getUploadDir($sField); |
| 225 | - if(!is_array($aFiles)) |
|
| 225 | + if (!is_array($aFiles)) |
|
| 226 | 226 | {
|
| 227 | 227 | $aFiles = [$aFiles]; |
| 228 | 228 | } |
| 229 | - foreach($aFiles as $xHttpFile) |
|
| 229 | + foreach ($aFiles as $xHttpFile) |
|
| 230 | 230 | {
|
| 231 | 231 | $aUserFiles[$sField][] = $this->makeUploadedFile($xHttpFile, $sUploadDir, $sField); |
| 232 | 232 | } |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | // Copy the uploaded files from the temp dir to the user dir |
| 235 | 235 | try |
| 236 | 236 | {
|
| 237 | - foreach($this->aAllFiles as $aFiles) |
|
| 237 | + foreach ($this->aAllFiles as $aFiles) |
|
| 238 | 238 | {
|
| 239 | 239 | $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream()); |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - catch(FilesystemException $e) |
|
| 242 | + catch (FilesystemException $e) |
|
| 243 | 243 | {
|
| 244 | 244 | $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
|
| 245 | 245 | throw new RequestException($this->xTranslator->trans('errors.upload.access'));
|