BaseUploadComponent   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 79
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getBaseConfigForSave() 0 9 1
1
<?php
2
3
namespace Itstructure\MFUploader\components;
4
5
use yii\base\Component;
6
use Itstructure\MFUploader\interfaces\UploadModelInterface;
7
8
/**
9
 * Class BaseUploadComponent
10
 *
11
 * @property bool $renameFiles Rename file after upload.
12
 * @property array $fileExtensions File extensions.
13
 * @property bool $checkExtensionByMimeType Check extension by MIME type (they are must match).
14
 * @property int $fileMaxSize Maximum file size.
15
 * @property array $thumbsConfig Thumbs config with their types and sizes.
16
 * @property string $thumbFilenameTemplate Thumbnails name template.
17
 * Values can be the next: {original}, {width}, {height}, {alias}, {extension}
18
 *
19
 * @package Itstructure\MFUploader\components
20
 *
21
 * @author Andrey Girnik <[email protected]>
22
 */
23
class BaseUploadComponent extends Component
24
{
25
    /**
26
     * Rename file after upload.
27
     *
28
     * @var bool
29
     */
30
    public $renameFiles = true;
31
32
    /**
33
     * File extensions.
34
     *
35
     * @var array
36
     */
37
    public $fileExtensions = [
38
        UploadModelInterface::FILE_TYPE_THUMB => [
39
            'png', 'jpg', 'jpeg', 'gif',
40
        ],
41
        UploadModelInterface::FILE_TYPE_IMAGE => [
42
            'png', 'jpg', 'jpeg', 'gif',
43
        ],
44
        UploadModelInterface::FILE_TYPE_AUDIO => [
45
            'mp3',
46
        ],
47
        UploadModelInterface::FILE_TYPE_VIDEO => [
48
            'mp4', 'ogg', 'ogv', 'oga', 'ogx', 'webm',
49
        ],
50
        UploadModelInterface::FILE_TYPE_APP => [
51
            'doc', 'docx', 'rtf', 'pdf', 'rar', 'zip', 'jar', 'mcd', 'xls',
52
        ],
53
        UploadModelInterface::FILE_TYPE_TEXT => [
54
            'txt',
55
        ],
56
        UploadModelInterface::FILE_TYPE_OTHER => null,
57
    ];
58
59
    /**
60
     * Check extension by MIME type (they are must match).
61
     *
62
     * @var bool
63
     */
64
    public $checkExtensionByMimeType = true;
65
66
    /**
67
     * Maximum file size.
68
     *
69
     * @var int
70
     */
71
    public $fileMaxSize = 1024*1024*64;
72
73
    /**
74
     * Thumbs config with their types and sizes.
75
     *
76
     * @var array
77
     */
78
    public $thumbsConfig = [];
79
80
    /**
81
     * Thumbnails name template.
82
     * Values can be the next: {original}, {width}, {height}, {alias}, {extension}
83
     *
84
     * @var string
85
     */
86
    public $thumbFilenameTemplate = '{original}-{width}-{height}-{alias}.{extension}';
87
88
    /**
89
     * Get base config for save.
90
     *
91
     * @return array
92
     */
93
    protected function getBaseConfigForSave(): array
94
    {
95
        return [
96
            'renameFiles' => $this->renameFiles,
97
            'fileExtensions' => $this->fileExtensions,
98
            'checkExtensionByMimeType' => $this->checkExtensionByMimeType,
99
            'fileMaxSize' => $this->fileMaxSize,
100
            'thumbsConfig' => $this->thumbsConfig,
101
            'thumbFilenameTemplate' => $this->thumbFilenameTemplate,
102
        ];
103
    }
104
}
105