mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-15 04:44:36 +02:00
Applied code style rules to src/
This commit is contained in:
parent
700c049d26
commit
f861de791f
186 changed files with 1462 additions and 1059 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -71,17 +74,6 @@ class AttachmentSubmitHandler
|
|||
SupplierAttachment::class => 'supplier', UserAttachment::class => 'user', ];
|
||||
}
|
||||
|
||||
protected function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
//If no preview image was set yet, the new uploaded file will become the preview image
|
||||
'become_preview_if_empty' => true,
|
||||
//When an URL is given download the URL
|
||||
'download_url' => false,
|
||||
'secure_attachment' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a filename for the given attachment and extension.
|
||||
* The filename contains a random id, so every time this function is called you get an unique name.
|
||||
|
@ -125,7 +117,7 @@ class AttachmentSubmitHandler
|
|||
}
|
||||
|
||||
//Ensure the given attachment class is known to mapping
|
||||
if (!isset($this->folder_mapping[\get_class($attachment)])) {
|
||||
if (! isset($this->folder_mapping[\get_class($attachment)])) {
|
||||
throw new \InvalidArgumentException('The given attachment class is not known! The passed class was: '.\get_class($attachment));
|
||||
}
|
||||
//Ensure the attachment has an assigned element
|
||||
|
@ -178,6 +170,17 @@ class AttachmentSubmitHandler
|
|||
return $attachment;
|
||||
}
|
||||
|
||||
protected function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
//If no preview image was set yet, the new uploaded file will become the preview image
|
||||
'become_preview_if_empty' => true,
|
||||
//When an URL is given download the URL
|
||||
'download_url' => false,
|
||||
'secure_attachment' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the given attachment to secure location (or back to public folder) if needed.
|
||||
*
|
||||
|
@ -200,13 +203,13 @@ class AttachmentSubmitHandler
|
|||
|
||||
//Determine the old filepath
|
||||
$old_path = $this->pathResolver->placeholderToRealPath($attachment->getPath());
|
||||
if (!file_exists($old_path)) {
|
||||
if (! file_exists($old_path)) {
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
$filename = basename($old_path);
|
||||
//If the basename is not one of the new unique on, we have to save the old filename
|
||||
if (!preg_match('/\w+-\w{13}\./', $filename)) {
|
||||
if (! preg_match('/\w+-\w{13}\./', $filename)) {
|
||||
//Save filename to attachment field
|
||||
$attachment->setFilename($attachment->getFilename());
|
||||
}
|
||||
|
@ -236,7 +239,7 @@ class AttachmentSubmitHandler
|
|||
protected function downloadURL(Attachment $attachment, array $options): Attachment
|
||||
{
|
||||
//Check if we are allowed to download files
|
||||
if (!$this->allow_attachments_downloads) {
|
||||
if (! $this->allow_attachments_downloads) {
|
||||
throw new \RuntimeException('Download of attachments is not allowed!');
|
||||
}
|
||||
|
||||
|
@ -286,7 +289,7 @@ class AttachmentSubmitHandler
|
|||
|
||||
//Check if we have a extension given
|
||||
$pathinfo = pathinfo($filename);
|
||||
if (!empty($pathinfo['extension'])) {
|
||||
if (! empty($pathinfo['extension'])) {
|
||||
$new_ext = $pathinfo['extension'];
|
||||
} else { //Otherwise we have to guess the extension for the new file, based on its content
|
||||
$new_ext = $this->mimeTypes->getExtensions($this->mimeTypes->guessMimeType($tmp_path))[0] ?? 'tmp';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue