| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © Melograno Venture Studio. All rights reserved. |
| 5 |
* @licence See LICENCE.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
namespace IvyForms\ValueObjects\Field; |
| 11 |
|
| 12 |
/** |
| 13 |
* File-upload-specific advanced field settings. |
| 14 |
*/ |
| 15 |
final class FileUploadFieldAdvancedSettings |
| 16 |
{ |
| 17 |
/** |
| 18 |
* Max upload size per file (MB). 0 uses server maximum. |
| 19 |
*/ |
| 20 |
private int $maxFileSizeMb; |
| 21 |
|
| 22 |
/** |
| 23 |
* Where uploads are stored: ivyforms (uploads dir) or media_library. |
| 24 |
*/ |
| 25 |
private string $saveUploadsTo; |
| 26 |
|
| 27 |
/** |
| 28 |
* Allowed extensions without dot (e.g. png, jpg). Empty = all types. |
| 29 |
* |
| 30 |
* @var array<int, string> |
| 31 |
*/ |
| 32 |
private array $allowedFileExtensions; |
| 33 |
|
| 34 |
/** |
| 35 |
* @param array<int, string> $allowedFileExtensions |
| 36 |
*/ |
| 37 |
public function __construct( |
| 38 |
int $maxFileSizeMb = 0, |
| 39 |
string $saveUploadsTo = 'ivyforms', |
| 40 |
array $allowedFileExtensions = [] |
| 41 |
) { |
| 42 |
$this->maxFileSizeMb = $maxFileSizeMb; |
| 43 |
$this->saveUploadsTo = $saveUploadsTo; |
| 44 |
$this->allowedFileExtensions = $allowedFileExtensions; |
| 45 |
} |
| 46 |
|
| 47 |
public function getMaxFileSizeMb(): int |
| 48 |
{ |
| 49 |
return $this->maxFileSizeMb; |
| 50 |
} |
| 51 |
|
| 52 |
public function setMaxFileSizeMb(int $maxFileSizeMb): void |
| 53 |
{ |
| 54 |
$this->maxFileSizeMb = $maxFileSizeMb; |
| 55 |
} |
| 56 |
|
| 57 |
public function getSaveUploadsTo(): string |
| 58 |
{ |
| 59 |
return $this->saveUploadsTo; |
| 60 |
} |
| 61 |
|
| 62 |
public function setSaveUploadsTo(string $saveUploadsTo): void |
| 63 |
{ |
| 64 |
$this->saveUploadsTo = $saveUploadsTo; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* @return array<int, string> |
| 69 |
*/ |
| 70 |
public function getAllowedFileExtensions(): array |
| 71 |
{ |
| 72 |
return $this->allowedFileExtensions; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* @param array<int, string> $allowedFileExtensions |
| 77 |
*/ |
| 78 |
public function setAllowedFileExtensions(array $allowedFileExtensions): void |
| 79 |
{ |
| 80 |
$this->allowedFileExtensions = $allowedFileExtensions; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* @return array<string, int|string|array<int, string>> |
| 85 |
*/ |
| 86 |
public function toArray(): array |
| 87 |
{ |
| 88 |
return [ |
| 89 |
'maxFileSizeMb' => $this->getMaxFileSizeMb(), |
| 90 |
'saveUploadsTo' => $this->getSaveUploadsTo(), |
| 91 |
'allowedFileExtensions' => $this->getAllowedFileExtensions(), |
| 92 |
]; |
| 93 |
} |
| 94 |
} |
| 95 |
|