Completed
Push — master ( f15f2a...6d9f7a )
by Igor
02:25
created

FileManager::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @link https://github.com/rkit/filemanager-yii2
5
 * @copyright Copyright (c) 2015 Igor Romanov
6
 * @license [MIT](http://opensource.org/licenses/MIT)
7
 */
8
9
namespace rkit\filemanager;
10
11
use Yii;
12
use yii\base\Component;
13
use yii\base\InvalidParamException;
14
15
/**
16
 * Component of FileManager
17
 *
18
 * @author Igor Romanov <[email protected]>
19
 */
20
class FileManager extends Component
21
{
22
    /**
23
     * @var string Directory to upload files protected, not accessible from the web
24
     */
25
    public $uploadDirProtected = '@runtime';
26
    /**
27
     * @var string Directory to upload files, accessible from the web
28
     */
29
    public $uploadDirUnprotected = '@app/web';
30
    /**
31
     * @var string Public path to files
32
     */
33
    public $publicPath = 'uploads';
34
    /**
35
     * @var array Type of owner in format: title:string => type:int
36
     */
37
    public $ownerTypes = [];
38
39
    /**
40
     * @internal
41
     */
42 1
    public function init()
43
    {
44 1
        parent::init();
45
46 1
        $this->registerTranslations();
47 1
    }
48
49
    /**
50
     * Get owner type
51
     *
52
     * @param string $ownerType The type of the owner
53
     * @return void
54
     * @throws InvalidParamException
55
     */
56 37
    public function getOwnerType($ownerType)
57
    {
58 37
        if (!isset($this->ownerTypes[$ownerType])) {
59 1
            throw new InvalidParamException('This type `' . $ownerType . '` is not found');
60
        }
61
62 36
        return $this->ownerTypes[$ownerType];
63
    }
64
65
    /**
66
     * Registers translator
67
     * @internal
68
     *
69
     * @return void
70
     */
71 49
    public function registerTranslations()
72
    {
73 49
        if (!isset(\Yii::$app->i18n->translations['filemanager-yii2'])) {
74 1
            \Yii::$app->i18n->translations['filemanager-yii2'] = [
75 1
                'class' => 'yii\i18n\PhpMessageSource',
76 1
                'basePath' => '@vendor/rkit/filemanager-yii2/src/messages',
77 1
                'sourceLanguage' => 'en',
78
            ];
79 1
        }
80 49
    }
81
}
82