1 | <?php |
||
34 | class Module extends BaseModule |
||
35 | { |
||
36 | const MODULE_NAME = 'mfuploader'; |
||
37 | |||
38 | const THUMB_ALIAS_DEFAULT = 'default'; |
||
39 | const THUMB_ALIAS_ORIGINAL = 'original'; |
||
40 | const THUMB_ALIAS_SMALL = 'small'; |
||
41 | const THUMB_ALIAS_MEDIUM = 'medium'; |
||
42 | const THUMB_ALIAS_LARGE = 'large'; |
||
43 | |||
44 | const URL_FILE_MANAGER = '/'.self::MODULE_NAME.'/managers/filemanager'; |
||
45 | const URL_UPLOAD_MANAGER = '/'.self::MODULE_NAME.'/managers/uploadmanager'; |
||
46 | const URL_FILE_INFO = '/'.self::MODULE_NAME.'/fileinfo/index'; |
||
47 | const URL_LOCAL_SEND = '/'.self::MODULE_NAME.'/upload/local-upload/send'; |
||
48 | const URL_LOCAL_UPDATE = '/'.self::MODULE_NAME.'/upload/local-upload/update'; |
||
49 | const URL_LOCAL_DELETE = '/'.self::MODULE_NAME.'/upload/local-upload/delete'; |
||
50 | const URL_S3_SEND = '/'.self::MODULE_NAME.'/upload/s3-upload/send'; |
||
51 | const URL_S3_UPDATE = '/'.self::MODULE_NAME.'/upload/s3-upload/update'; |
||
52 | const URL_S3_DELETE = '/'.self::MODULE_NAME.'/upload/s3-upload/delete'; |
||
53 | |||
54 | const BACK_URL_PARAM = '__backUrl'; |
||
55 | |||
56 | const ORIGINAL_PREVIEW_WIDTH = 300; |
||
57 | const ORIGINAL_PREVIEW_HEIGHT = 240; |
||
58 | const SCANTY_PREVIEW_SIZE = 50; |
||
59 | |||
60 | const STORAGE_TYPE_LOCAL = 'local'; |
||
61 | const STORAGE_TYPE_S3 = 's3'; |
||
62 | |||
63 | /** |
||
64 | * Login url. |
||
65 | * |
||
66 | * @var null|string|array |
||
67 | */ |
||
68 | public $loginUrl = null; |
||
69 | |||
70 | /** |
||
71 | * Array of roles to module access. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | public $accessRoles = ['@']; |
||
76 | |||
77 | /** |
||
78 | * Name of the file field to load using Ajax request. |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | public $fileAttributeName = 'file'; |
||
83 | |||
84 | /** |
||
85 | * Preview options for som types of mediafiles according with their location. |
||
86 | * See how it's done in "preview-options" config file as an example. |
||
87 | * |
||
88 | * @var array |
||
89 | */ |
||
90 | public $previewOptions = []; |
||
91 | |||
92 | /** |
||
93 | * Thumbs config with their types and sizes. |
||
94 | * See how it's done in "thumbs-config" config file as an example. |
||
95 | * |
||
96 | * @var array of thumbnails. |
||
97 | */ |
||
98 | public $thumbsConfig = []; |
||
99 | |||
100 | /** |
||
101 | * Use thumb config from /config/thumbs-config.php |
||
102 | * |
||
103 | * @var bool |
||
104 | */ |
||
105 | public $useInitialThumbsConfig = true; |
||
106 | |||
107 | /** |
||
108 | * Thumbnails name template. |
||
109 | * Values can be the next: {original}, {width}, {height}, {alias}, {extension} |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | public $thumbFilenameTemplate = '{original}-{width}-{height}-{alias}.{extension}'; |
||
114 | |||
115 | /** |
||
116 | * Default thumbnail stub urls according with file type. |
||
117 | * See how it's done in "thumb-stub-urls" config file as an example. |
||
118 | * |
||
119 | * @var array |
||
120 | */ |
||
121 | public $thumbStubUrls = []; |
||
122 | |||
123 | /** |
||
124 | * Csrf validation. |
||
125 | * |
||
126 | * @var bool |
||
127 | */ |
||
128 | public $enableCsrfValidation = true; |
||
129 | |||
130 | /** |
||
131 | * Default storage type. Can be 'local' or 's3'. |
||
132 | * |
||
133 | * @var string |
||
134 | */ |
||
135 | public $defaultStorageType = self::STORAGE_TYPE_LOCAL; |
||
136 | |||
137 | /** |
||
138 | * Public base project url, to set before media files url. |
||
139 | * |
||
140 | * @var string |
||
141 | */ |
||
142 | public $publicBaseUrl = ''; |
||
143 | |||
144 | /** |
||
145 | * View component to render content. |
||
146 | * |
||
147 | * @var View |
||
148 | */ |
||
149 | private $_view = null; |
||
150 | |||
151 | /** |
||
152 | * Urls to send new files depending on the storage type. |
||
153 | * |
||
154 | * @var array |
||
155 | */ |
||
156 | private static $sendUrls = [ |
||
157 | self::STORAGE_TYPE_LOCAL => self::URL_LOCAL_SEND, |
||
158 | self::STORAGE_TYPE_S3 => self::URL_S3_SEND, |
||
159 | ]; |
||
160 | |||
161 | /** |
||
162 | * Urls to update existing files depending on the storage type. |
||
163 | * |
||
164 | * @var array |
||
165 | */ |
||
166 | private static $updateUrls = [ |
||
167 | self::STORAGE_TYPE_LOCAL => self::URL_LOCAL_UPDATE, |
||
168 | self::STORAGE_TYPE_S3 => self::URL_S3_UPDATE, |
||
169 | ]; |
||
170 | |||
171 | /** |
||
172 | * Urls to delete existing files depending on the storage type. |
||
173 | * |
||
174 | * @var array |
||
175 | */ |
||
176 | private static $deleteUrls = [ |
||
177 | self::STORAGE_TYPE_LOCAL => self::URL_LOCAL_DELETE, |
||
178 | self::STORAGE_TYPE_S3 => self::URL_S3_DELETE, |
||
179 | ]; |
||
180 | |||
181 | /** |
||
182 | * Module translations. |
||
183 | * |
||
184 | * @var array|null |
||
185 | */ |
||
186 | private static $_translations = null; |
||
187 | |||
188 | /** |
||
189 | * @inheritdoc |
||
190 | */ |
||
191 | public function init() |
||
192 | { |
||
193 | parent::init(); |
||
194 | |||
195 | Yii::setAlias('@'.self::MODULE_NAME.'', static::getBaseDir()); |
||
196 | |||
197 | if (null !== $this->loginUrl && method_exists(Yii::$app, 'getUser')) { |
||
198 | Yii::$app->getUser()->loginUrl = $this->loginUrl; |
||
|
|||
199 | } |
||
200 | |||
201 | self::registerTranslations(); |
||
202 | |||
203 | $this->previewOptions = array_merge( |
||
204 | require __DIR__ . '/config/preview-options.php', |
||
205 | $this->previewOptions |
||
206 | ); |
||
207 | |||
208 | $this->thumbStubUrls = array_merge( |
||
209 | require __DIR__ . '/config/thumb-stub-urls.php', |
||
210 | $this->thumbStubUrls |
||
211 | ); |
||
212 | |||
213 | $this->thumbsConfig = array_merge($this->useInitialThumbsConfig ? require __DIR__ . '/config/thumbs-config.php' : [], |
||
214 | $this->thumbsConfig |
||
215 | ); |
||
216 | |||
217 | /** |
||
218 | * Set aws s3 upload component. |
||
219 | */ |
||
220 | $this->setComponents( |
||
221 | ArrayHelper::merge($this->getS3UploadComponentConfig(), $this->components) |
||
222 | ); |
||
223 | |||
224 | /** |
||
225 | * Set local upload component. |
||
226 | */ |
||
227 | $this->setComponents( |
||
228 | ArrayHelper::merge($this->getLocalUploadComponentConfig(), $this->components) |
||
229 | ); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Get the view. |
||
234 | * |
||
235 | * @return View |
||
236 | */ |
||
237 | public function getView() |
||
238 | { |
||
239 | if (null === $this->_view) { |
||
240 | $this->_view = $this->get('view'); |
||
241 | } |
||
242 | |||
243 | return $this->_view; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * Returns module root directory. |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | public static function getBaseDir(): string |
||
252 | { |
||
253 | return __DIR__; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * Get src to send new files. |
||
258 | * |
||
259 | * @param string $storageType |
||
260 | * |
||
261 | * @return string |
||
262 | * |
||
263 | * @throws InvalidConfigException |
||
264 | */ |
||
265 | public static function getSendUrl(string $storageType): string |
||
273 | |||
274 | /** |
||
275 | * Get src to update existing files. |
||
276 | * |
||
277 | * @param string $storageType |
||
278 | * |
||
279 | * @return string |
||
280 | * |
||
281 | * @throws InvalidConfigException |
||
282 | */ |
||
283 | public static function getUpdateUrl(string $storageType): string |
||
291 | |||
292 | /** |
||
293 | * Get src to delete existing files. |
||
294 | * |
||
295 | * @param string $storageType |
||
296 | * |
||
297 | * @return string |
||
298 | * |
||
299 | * @throws InvalidConfigException |
||
300 | */ |
||
301 | public static function getDeleteUrl(string $storageType): string |
||
309 | |||
310 | /** |
||
311 | * Set thumb configuration. |
||
312 | * |
||
313 | * @param string $alias |
||
314 | * @param array $config |
||
315 | * |
||
316 | * @throws InvalidConfigException |
||
317 | * |
||
318 | * @return ThumbConfigInterface |
||
319 | * |
||
320 | */ |
||
321 | public static function configureThumb(string $alias, array $config): ThumbConfigInterface |
||
346 | |||
347 | /** |
||
348 | * Default thumb config |
||
349 | * |
||
350 | * @return array |
||
351 | */ |
||
352 | public static function getDefaultThumbConfig(): array |
||
359 | |||
360 | /** |
||
361 | * Get preview options for som types of mediafiles according with their location. |
||
362 | * |
||
363 | * @param string $fileType |
||
364 | * @param string $location |
||
365 | * @param Mediafile|null $mediafile |
||
366 | * |
||
367 | * @return array |
||
368 | */ |
||
369 | public function getPreviewOptions(string $fileType, string $location, Mediafile $mediafile = null): array |
||
400 | |||
401 | /** |
||
402 | * Module translator. |
||
403 | * |
||
404 | * @param $category |
||
405 | * @param $message |
||
406 | * @param array $params |
||
407 | * @param null $language |
||
408 | * |
||
409 | * @return string |
||
410 | */ |
||
411 | public static function t($category, $message, $params = [], $language = null) |
||
419 | |||
420 | /** |
||
421 | * Set i18N component. |
||
422 | * |
||
423 | * @return void |
||
424 | */ |
||
425 | private static function registerTranslations(): void |
||
448 | |||
449 | /** |
||
450 | * File local upload component config. |
||
451 | * |
||
452 | * @return array |
||
453 | */ |
||
454 | private function getLocalUploadComponentConfig(): array |
||
464 | |||
465 | /** |
||
466 | * File aws s3 upload component config. |
||
467 | * |
||
468 | * @return array |
||
469 | */ |
||
470 | private function getS3UploadComponentConfig(): array |
||
480 | } |
||
481 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: