Completed
Push — master ( b2ef99...1ef91b )
by Vladimir
02:11
created

Module::getIssueUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
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\DbService;
13
use ymaker\email\templates\services\ServiceInterface;
14
use yii2deman\tools\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
     * Service for controller.
33
     *
34
     * @see \ymaker\email\templates\services\ServiceInterface
35
     * @var array
36
     */
37
    protected $_service = null;
38
    /**
39
     * Language provider for internationalization.
40
     *
41
     * @see \yii2deman\tools\i18n\LanguageProviderInterface
42
     * @var array
43
     */
44
    protected $_languageProvider = null;
45
46
47
    /**
48
     * Setter for service.
49
     *
50
     * @param array $service
51
     * @since 2.0
52
     */
53
    public function setService(array $service)
54
    {
55
        $this->_service = $service;
56
    }
57
58
    /**
59
     * Setter for language provider.
60
     *
61
     * @param array $provider
62
     * @since 2.0
63
     */
64
    public function setLanguageProvider(array $provider)
65
    {
66
        $this->_languageProvider = $provider;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function init()
73
    {
74
        parent::init();
75
76
        if ($this->_service === null) {
77
            $this->_service = ['class' => DbService::class];
78
        }
79
        if ($this->_languageProvider === null) {
80
            throw new InvalidConfigException('You should to configure the language provider');
81
        }
82
83
        $this->registerDependencies();
84
    }
85
86
    /**
87
     * Register dependencies to DI container.
88
     */
89
    protected function registerDependencies()
90
    {
91
        Yii::$container->setDefinitions([
92
            ServiceInterface::class => $this->_service,
93
            LanguageProviderInterface::class => $this->_languageProvider
94
        ]);
95
    }
96
97
    /**
98
     * Module wrapper for `Yii::t()` method.
99
     *
100
     * @param string $message
101
     * @param array $params
102
     * @param null|string $language
103
     * @return string
104
     */
105
    public static function t($message, $params = [], $language = null)
106
    {
107
        return Yii::t('back/email-templates', $message, $params, $language);
108
    }
109
110
    /**
111
     * Returns url to repository for creation of new issue.
112
     *
113
     * @return string
114
     * @since 2.2.0
115
     */
116
    public static function getIssueUrl()
117
    {
118
        return 'https://github.com/yiimaker/yii2-email-templates/issues/new';
119
    }
120
}
121