-
Notifications
You must be signed in to change notification settings - Fork 8
/
Module.php
89 lines (73 loc) · 1.94 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace iutbay\yii2\mm;
use Yii;
use Imagine\Image\ManipulatorInterface;
use iutbay\yii2\mm\components\FileSystem;
use iutbay\yii2\mm\models\Thumb;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'iutbay\yii2\mm\controllers';
/**
* @var Custom filesystem
*/
public $fs;
/**
* Filesystem component name
* @var string
*/
public $fsComponent = 'fs';
/**
* Directory separator
* @var string
*/
public $directorySeparator = '/';
/**
* api controller options
* @var array
*/
public $apiOptions = [
'cors' => false,
];
/**
* @var components\ImageCache
*/
public $thumbsPath = '@webroot/thumbs';
public $thumbsUrl = '@web/thumbs';
public $thumbsSize = Thumb::SIZE_THUMB;
public $resizeMode = ManipulatorInterface::THUMBNAIL_INSET;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
Yii::setAlias('@mm', __DIR__);
if (!isset(Yii::$app->{$this->fsComponent}))
throw new \yii\base\InvalidConfigException();
$this->fs = new FileSystem([
'fs' => Yii::$app->{$this->fsComponent},
'directorySeparator' => $this->directorySeparator,
]);
Thumb::$fs = $this->fs;
Thumb::$thumbsPath = $this->thumbsPath;
Thumb::$thumbsUrl = $this->thumbsUrl;
Thumb::$thumbsSize = $this->thumbsSize;
Thumb::$resizeMode = $this->resizeMode;
}
/**
* @return array
*/
public function getCorsOptions()
{
if (isset($this->apiOptions['cors'])) {
if (is_array($this->apiOptions['cors'])) {
return [
'class' => 'yii\filters\Cors',
'cors' => $this->apiOptions['cors'],
];
} else {
return $this->apiOptions['cors'] ? true : false;
}
}
}
}