1 | <?php |
||
20 | class UploaderConfig |
||
21 | { |
||
22 | /** @var string key used for CakePHP upload cache */ |
||
23 | private const CACHE_KEY = 'uploadsThumbnails'; |
||
24 | |||
25 | /** @var int max upload size in bytes */ |
||
26 | private $defaultSize = 2000000; |
||
27 | |||
28 | /** @var int max number of allowed uploads per user */ |
||
29 | private $maxNumberOfUploads = 10; |
||
30 | |||
31 | /** @var array allowed mime types */ |
||
32 | private $types = []; |
||
33 | |||
34 | /** |
||
35 | * Sets max allowed uploads per user |
||
36 | * |
||
37 | * @param int $max Max uploads |
||
38 | * @return self |
||
39 | */ |
||
40 | public function setMaxNumberOfUploadsPerUser(int $max): self |
||
46 | |||
47 | /** |
||
48 | * Gets max allowed uploads per user |
||
49 | * |
||
50 | * @return int max uploads per user |
||
51 | */ |
||
52 | public function getMaxNumberOfUploadsPerUser(): int |
||
56 | |||
57 | /** |
||
58 | * Set default max file size |
||
59 | * |
||
60 | * @param string|int $number bytes as int or string e.g. "3MB" |
||
61 | * @return self |
||
62 | */ |
||
63 | public function setDefaultMaxFileSize($number): self |
||
79 | |||
80 | /** |
||
81 | * Adds a new mime type which is allowed to be uploaded |
||
82 | * |
||
83 | * @param string $type mime type as in "image/jpeg" |
||
84 | * @param string|int|null $size optional file size different from default file size |
||
85 | * @return self |
||
86 | */ |
||
87 | public function addType(string $type, $size = null): self |
||
104 | |||
105 | /** |
||
106 | * Gets all allowed file types as array |
||
107 | * |
||
108 | * @return array file types |
||
109 | */ |
||
110 | public function getAllTypes(): array |
||
114 | |||
115 | /** |
||
116 | * Gets file size for a a mime type |
||
117 | * |
||
118 | * @param string $type mime-type |
||
119 | * @return int file-size in bytes |
||
120 | * @throws \RuntimeException if mime-type isn't set |
||
121 | */ |
||
122 | public function getSize(string $type): int |
||
133 | |||
134 | /** |
||
135 | * Gets cache key |
||
136 | * |
||
137 | * @return string cache-key |
||
138 | */ |
||
139 | public function getCacheKey(): string |
||
143 | |||
144 | /** |
||
145 | * Checks if a mime-type is registered |
||
146 | * |
||
147 | * @param string $type mime-type |
||
148 | * @return bool is type registered |
||
149 | */ |
||
150 | public function hasType(string $type): bool |
||
154 | } |
||
155 |