Completed
Push — master ( 1d3c0c...8bf0fe )
by Song
03:06
created

Toastr::topCenter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Actions;
4
5
use Illuminate\Support\Arr;
6
7
class Toastr
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $type;
13
14
    /**
15
     * @var string
16
     */
17
    protected $content;
18
19
    /**
20
     * @var array
21
     */
22
    protected $options = [];
23
24
    /**
25
     * @param string $type
26
     * @param string $content
27
     *
28
     * @return $this
29
     */
30
    public function show($type, $content = '')
31
    {
32
        $this->type    = $type;
33
        $this->content = $content;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param $option
40
     * @param $value
41
     * @return $this
42
     */
43
    protected function options($option, $value)
44
    {
45
        Arr::set($this->options, $option, $value);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param $position
52
     * @return Toastr
53
     */
54
    protected function position($position)
55
    {
56
        return $this->options('positionClass', $position);
57
    }
58
59
    /**
60
     * @return Toastr
61
     */
62
    public function topCenter()
63
    {
64
        return $this->position('toast-top-center');
65
    }
66
67
    /**
68
     * @return Toastr
69
     */
70
    public function topLeft()
71
    {
72
        return $this->position('toast-top-left');
73
    }
74
75
    /**
76
     * @return Toastr
77
     */
78
    public function topRight()
79
    {
80
        return $this->position('toast-top-right');
81
    }
82
83
    /**
84
     * @return Toastr
85
     */
86
    public function bottomLeft()
87
    {
88
        return $this->position('toast-bottom-left');
89
    }
90
91
    /**
92
     * @return Toastr
93
     */
94
    public function bottomCenter()
95
    {
96
        return $this->position('toast-bottom-center');
97
    }
98
99
    /**
100
     * @return Toastr
101
     */
102
    public function bottomRight()
103
    {
104
        return $this->position('toast-bottom-right');
105
    }
106
107
    /**
108
     * @return Toastr
109
     */
110
    public function topFullWidth()
111
    {
112
        return $this->position('toast-top-full-width');
113
    }
114
115
    /**
116
     * @return Toastr
117
     */
118
    public function bottomFullWidth()
119
    {
120
        return $this->position('toast-bottom-full-width');
121
    }
122
123
    /**
124
     * @return Toastr
125
     */
126
    public function timeout($timeout = 5000)
127
    {
128
        return $this->options('timeOut', $timeout);
129
    }
130
131
    /**
132
     * @return array
133
     */
134
    public function getOptions()
135
    {
136
        if (!isset($this->options['positionClass'])) {
137
            $this->topCenter();
138
        }
139
140
        return [
141
            'toastr' => [
142
                'type'    => $this->type,
143
                'content' => $this->content,
144
                'options' => $this->options,
145
            ],
146
        ];
147
    }
148
}