1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiimaker/yii2-email-templates |
4
|
|
|
* @copyright Copyright (c) 2017 Yii Maker |
5
|
|
|
* @license BSD 3-Clause License |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace ymaker\email\templates; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
use yii\base\InvalidConfigException; |
12
|
|
|
use ymaker\email\templates\services\EmailTemplateService; |
13
|
|
|
use ymaker\email\templates\services\ServiceInterface; |
14
|
|
|
use motion\i18n\LanguageProviderInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Module for CRUD operations under email templates in backend. |
18
|
|
|
* |
19
|
|
|
* @property array $service |
20
|
|
|
* @property array $languageProvider |
21
|
|
|
* |
22
|
|
|
* @author Vladimir Kuprienko <[email protected]> |
23
|
|
|
* @since 1.0 |
24
|
|
|
*/ |
25
|
|
|
class Module extends \yii\base\Module |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
|
|
public $controllerNamespace = 'ymaker\email\templates\controllers'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Service for controller. |
34
|
|
|
* |
35
|
|
|
* @see \ymaker\email\templates\services\ServiceInterface |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $service; |
39
|
|
|
/** |
40
|
|
|
* Language provider for internationalization. |
41
|
|
|
* |
42
|
|
|
* @see \motion\i18n\LanguageProviderInterface |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $languageProvider; |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param array $service |
50
|
|
|
* @since 2.0 |
51
|
|
|
*/ |
52
|
|
|
public function setService(array $service) |
53
|
|
|
{ |
54
|
|
|
$this->service = $service; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $provider |
59
|
|
|
* @since 2.0 |
60
|
|
|
*/ |
61
|
|
|
public function setLanguageProvider(array $provider) |
62
|
|
|
{ |
63
|
|
|
$this->languageProvider = $provider; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
|
|
public function init() |
70
|
|
|
{ |
71
|
|
|
parent::init(); |
72
|
|
|
|
73
|
|
|
if ($this->service === null) { |
74
|
|
|
$this->service = ['class' => EmailTemplateService::class]; |
75
|
|
|
} |
76
|
|
|
if ($this->languageProvider === null) { |
77
|
|
|
throw new InvalidConfigException('You should to configure the language provider'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->registerDependencies(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Register dependencies to DI container. |
85
|
|
|
*/ |
86
|
|
|
protected function registerDependencies() |
87
|
|
|
{ |
88
|
|
|
Yii::$container->setDefinitions([ |
89
|
|
|
ServiceInterface::class => $this->service, |
90
|
|
|
LanguageProviderInterface::class => $this->languageProvider |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Module wrapper for `Yii::t()` method. |
96
|
|
|
* |
97
|
|
|
* @param string $message |
98
|
|
|
* @param array $params |
99
|
|
|
* @param null|string $language |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public static function t($message, $params = [], $language = null) |
103
|
|
|
{ |
104
|
|
|
return Yii::t('back/email-templates', $message, $params, $language); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns url to repository for creation of new issue. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
* @since 3.0 |
112
|
|
|
*/ |
113
|
|
|
final public static function getIssueUrl() |
114
|
|
|
{ |
115
|
|
|
return self::getRepoUrl() . '/issues/new'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns url of official repository. |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
* @since 3.0 |
123
|
|
|
*/ |
124
|
|
|
final public static function getRepoUrl() |
125
|
|
|
{ |
126
|
|
|
return 'https://github.com/yiimaker/yii2-email-templates'; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|