Passed
Push — master ( fc0856...e4fdff )
by Sugeng
02:03
created

ToastrBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 176
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
eloc 71
c 5
b 1
f 1
dl 0
loc 176
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 27 2
1
<?php
2
3
namespace diecoding\toastr;
4
5
use diecoding\toastr\assets\ToastrAsset;
6
use yii\base\Widget;
7
use yii\helpers\ArrayHelper;
8
9
/**
10
 * ToastrBase is the base class for widgets.
11
 * 
12
 * @link [sugeng-sulistiyawan.github.io](sugeng-sulistiyawan.github.io)
13
 * @author Sugeng Sulistiyawan <[email protected]>
14
 * @copyright Copyright (c) 2023
15
 */
16
class ToastrBase extends Widget
17
{
18
	const TYPE_INFO    = "info";
19
	const TYPE_ERROR   = "error";
20
	const TYPE_SUCCESS = "success";
21
	const TYPE_WARNING = "warning";
22
23
	const POSITION_TOP_RIGHT      = "toast-top-right";
24
	const POSITION_TOP_LEFT       = "toast-top-left";
25
	const POSITION_TOP_CENTER     = "toast-top-center";
26
	const POSITION_TOP_FULL_WIDTH = "toast-top-full-width";
27
28
	const POSITION_BOTTOM_RIGHT      = "toast-bottom-right";
29
	const POSITION_BOTTOM_LEFT       = "toast-bottom-left";
30
	const POSITION_BOTTOM_CENTER     = "toast-bottom-center";
31
	const POSITION_BOTTOM_FULL_WIDTH = "toast-bottom-full-width";
32
33
	const TYPES = [
34
		self::TYPE_INFO,
35
		self::TYPE_ERROR,
36
		self::TYPE_SUCCESS,
37
		self::TYPE_WARNING,
38
	];
39
40
	const POSITIONS = [
41
		self::POSITION_TOP_RIGHT,
42
		self::POSITION_TOP_LEFT,
43
		self::POSITION_TOP_CENTER,
44
		self::POSITION_TOP_FULL_WIDTH,
45
46
		self::POSITION_BOTTOM_RIGHT,
47
		self::POSITION_BOTTOM_LEFT,
48
		self::POSITION_BOTTOM_CENTER,
49
		self::POSITION_BOTTOM_FULL_WIDTH,
50
	];
51
52
	/**
53
	 * @var string default `self::TYPE_INFO`
54
	 */
55
	public $typeDefault = self::TYPE_INFO;
56
57
	/**
58
	 * @var string default `""`
59
	 */
60
	public $titleDefault = "";
61
62
	/**
63
	 * @var string default `""`
64
	 */
65
	public $messageDefault = "";
66
67
	/**
68
	 * @var bool default `false`
69
	 */
70
	public $closeButton = false;
71
72
	/**
73
	 * @var bool default `false`
74
	 */
75
	public $debug = false;
76
77
	/**
78
	 * @var bool default `true`
79
	 */
80
	public $newestOnTop = true;
81
82
	/**
83
	 * @var bool default `true`
84
	 */
85
	public $progressBar = true;
86
87
	/**
88
	 * @var string default `self::POSITION_TOP_RIGHT`
89
	 */
90
	public $positionClass = self::POSITION_TOP_RIGHT;
91
92
	/**
93
	 * @var bool default `true`
94
	 */
95
	public $preventDuplicates = true;
96
97
	/**
98
	 * @var int|null default `300` in `ms`, `null` for skip
99
	 */
100
	public $showDuration = 300;
101
102
	/**
103
	 * @var int|null default `1000` in `ms`, `null` for skip
104
	 */
105
	public $hideDuration = 1000;
106
107
	/**
108
	 * @var int|null default `5000` in `ms`, `null` for skip
109
	 */
110
	public $timeOut = 5000;
111
112
	/**
113
	 * @var int|null default `1000` in `ms`, `null` for skip
114
	 */
115
	public $extendedTimeOut = 1000;
116
117
	/**
118
	 * @var string default `swing`, `swing` and `linear` are built into jQuery
119
	 */
120
	public $showEasing = "swing";
121
122
	/**
123
	 * @var string default `swing`, `swing` and `linear` are built into jQuery
124
	 */
125
	public $hideEasing = "swing";
126
127
	/**
128
	 * @var string default `slideDown`, `fadeIn`, `slideDown`, and `show` are built into jQuery
129
	 */
130
	public $showMethod = "slideDown";
131
132
	/**
133
	 * @var string default `slideUp`, `hide`, `fadeOut` and `slideUp` are built into jQuery
134
	 */
135
	public $hideMethod = "slideUp";
136
137
	/**
138
	 * @var bool default `true`
139
	 */
140
	public $tapToDismiss = true;
141
142
	/**
143
	 * @var bool default `true`
144
	 */
145
	public $escapeHtml = true;
146
147
	/**
148
	 * @var bool default `false`
149
	 */
150
	public $rtl = false;
151
152
	/**
153
	 * @var bool default `false`, `true` if use custom or external toastr assets
154
	 */
155
	public $skipCoreAssets = false;
156
157
	/**
158
	 * @var array default `[]`, Custom Toastr options and override default options
159
	 */
160
	public $options = [];
161
162
	/**
163
	 * @inheritdoc
164
	 */
165
	public function init()
166
	{
167
		parent::init();
168
169
		if ($this->skipCoreAssets === false) {
170
			$this->view->registerAssetBundle(ToastrAsset::class);
171
		}
172
173
		$this->options = ArrayHelper::merge([
174
			"closeButton"       => $this->closeButton,
175
			"debug"             => $this->debug,
176
			"newestOnTop"       => $this->newestOnTop,
177
			"progressBar"       => $this->progressBar,
178
			"positionClass"     => $this->positionClass,
179
			"preventDuplicates" => $this->preventDuplicates,
180
			"showDuration"      => $this->showDuration,
181
			"hideDuration"      => $this->hideDuration,
182
			"timeOut"           => $this->timeOut,
183
			"extendedTimeOut"   => $this->extendedTimeOut,
184
			"showEasing"        => $this->showEasing,
185
			"hideEasing"        => $this->hideEasing,
186
			"showMethod"        => $this->showMethod,
187
			"hideMethod"        => $this->hideMethod,
188
			"tapToDismiss"      => $this->tapToDismiss,
189
			"escapeHtml"        => $this->escapeHtml,
190
			"rtl"               => $this->rtl,
191
		], $this->options);
192
	}
193
}
194