Completed
Pull Request — master (#26)
by Geoffry Van
09:02 queued 05:40
created

Module::setLanguageProvider()   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 1
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-email-templates
4
 * @copyright Copyright (c) 2017-2018 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 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\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
    public function getLanguageProvider()
73
    {
74
        return $this->languageProvider;
75
    }
76
77
    /**
78
     * {{@inheritdoc}}
79
     */
80
    public function init()
81
    {
82
        parent::init();
83
84
        if ($this->repository === null) {
85
            $this->repository = ['class' => EmailTemplatesRepository::class];
86
        }
87
        if ($this->languageProvider === null) {
88
            throw new InvalidConfigException('You should configure the language provider');
89
        }
90
91
        $this->registerDependencies();
92
    }
93
94
    /**
95
     * Register dependencies to DI container.
96
     */
97
    protected function registerDependencies()
98
    {
99
        Yii::$container->setDefinitions([
100
            EmailTemplatesRepositoryInterface::class => $this->repository,
101
            LanguageProviderInterface::class => $this->languageProvider,
102
        ]);
103
    }
104
105
    /**
106
     * Module wrapper for `Yii::t()` method.
107
     *
108
     * @param string        $message
109
     * @param array         $params
110
     * @param null|string   $language
111
     *
112
     * @return string
113
     */
114
    public static function t($message, $params = [], $language = null)
115
    {
116
        return Yii::t('back/email-templates', $message, $params, $language);
117
    }
118
119
    /**
120
     * Returns url to repository for creation of new issue.
121
     *
122
     * @return string
123
     *
124
     * @since 3.0
125
     */
126
    final public static function getIssueUrl()
127
    {
128
        return self::getRepoUrl() . '/issues/new';
129
    }
130
131
    /**
132
     * Returns url of official repository.
133
     *
134
     * @return string
135
     *
136
     * @since 3.0
137
     */
138
    final public static function getRepoUrl()
139
    {
140
        return 'https://github.com/yiimaker/yii2-email-templates';
141
    }
142
}
143