1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiimaker/yii2-email-templates |
4
|
|
|
* @copyright Copyright (c) 2017-2019 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\repositories\EmailTemplatesRepository; |
13
|
|
|
use ymaker\email\templates\repositories\EmailTemplatesRepositoryInterface; |
14
|
|
|
use motion\i18n\LanguageProviderInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Module for CRUD operations under email templates in backend. |
18
|
|
|
* |
19
|
|
|
* @property array $repository |
20
|
|
|
* @property array $languageProvider |
21
|
|
|
* |
22
|
|
|
* @author Volodymyr Kupriienko <[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\repositories\EmailTemplatesRepositoryInterface |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
* |
39
|
|
|
* @since 4.0 |
40
|
|
|
*/ |
41
|
|
|
protected $repository; |
42
|
|
|
/** |
43
|
|
|
* Language provider for internationalization. |
44
|
|
|
* |
45
|
|
|
* @see \motion\i18n\LanguageProviderInterface |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $languageProvider; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $repository |
54
|
|
|
* |
55
|
|
|
* @since 4.0 |
56
|
|
|
*/ |
57
|
|
|
public function setRepository(array $repository) |
58
|
|
|
{ |
59
|
|
|
$this->repository = $repository; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param array $provider |
64
|
|
|
* |
65
|
|
|
* @since 2.0 |
66
|
|
|
*/ |
67
|
|
|
public function setLanguageProvider(array $provider) |
68
|
|
|
{ |
69
|
|
|
$this->languageProvider = $provider; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {{@inheritdoc}} |
74
|
|
|
*/ |
75
|
|
|
public function init() |
76
|
|
|
{ |
77
|
|
|
parent::init(); |
78
|
|
|
|
79
|
|
|
if (null === $this->repository) { |
80
|
|
|
$this->repository = ['class' => EmailTemplatesRepository::class]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (null === $this->languageProvider) { |
84
|
|
|
throw new InvalidConfigException('You should configure the language provider'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->registerDependencies(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Register dependencies to DI container. |
92
|
|
|
*/ |
93
|
|
|
protected function registerDependencies() |
94
|
|
|
{ |
95
|
|
|
Yii::$container->setDefinitions([ |
96
|
|
|
EmailTemplatesRepositoryInterface::class => $this->repository, |
97
|
|
|
LanguageProviderInterface::class => $this->languageProvider, |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Module wrapper for `Yii::t()` method. |
103
|
|
|
* |
104
|
|
|
* @param string $message |
105
|
|
|
* @param array $params |
106
|
|
|
* @param null|string $language |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public static function t($message, $params = [], $language = null) |
111
|
|
|
{ |
112
|
|
|
return Yii::t('back/email-templates', $message, $params, $language); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Returns url to repository for creation of new issue. |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
* |
120
|
|
|
* @since 3.0 |
121
|
|
|
*/ |
122
|
|
|
final public static function getIssueUrl() |
123
|
|
|
{ |
124
|
|
|
return self::getRepoUrl() . '/issues/new'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns url of official repository. |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
* |
132
|
|
|
* @since 3.0 |
133
|
|
|
*/ |
134
|
|
|
final public static function getRepoUrl() |
135
|
|
|
{ |
136
|
|
|
return 'https://github.com/yiimaker/yii2-email-templates'; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|