1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\SlashCommand; |
4
|
|
|
|
5
|
|
|
class AttachmentField |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* The required title field of the field. |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $title; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The required value of the field. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $value; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Whether the value is short enough to fit side by side with |
23
|
|
|
* other values. |
24
|
|
|
* |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $short = false; |
28
|
|
|
|
29
|
|
|
public static function create(array $attributes) |
30
|
|
|
{ |
31
|
|
|
return new static($attributes); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $attributes |
36
|
|
|
*/ |
37
|
|
|
public function __construct(array $attributes) |
38
|
|
|
{ |
39
|
|
|
if (isset($attributes['title'])) { |
40
|
|
|
$this->setTitle($attributes['title']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (isset($attributes['value'])) { |
44
|
|
|
$this->setValue($attributes['value']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (isset($attributes['short'])) { |
48
|
|
|
$this->setShort($attributes['short']); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the title of the field. |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getTitle(): string |
58
|
|
|
{ |
59
|
|
|
return $this->title; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the title of the field. |
64
|
|
|
* |
65
|
|
|
* @param string $title |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setTitle(string $title) |
70
|
|
|
{ |
71
|
|
|
$this->title = $title; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the value of the field. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getValue(): string |
82
|
|
|
{ |
83
|
|
|
return $this->value; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Set the value of the field. |
88
|
|
|
* |
89
|
|
|
* @param string $value |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function setValue(string $value) |
93
|
|
|
{ |
94
|
|
|
$this->value = $value; |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get whether this field is short enough for displaying |
101
|
|
|
* side-by-side with other fields. |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function getShort(): bool |
106
|
|
|
{ |
107
|
|
|
return $this->short; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Set whether this field is short enough for displaying |
112
|
|
|
* side-by-side with other fields. |
113
|
|
|
* |
114
|
|
|
* @param bool $value |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
|
|
public function setShort(bool $value) |
119
|
|
|
{ |
120
|
|
|
$this->short = $value; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the array representation of this attachment field. |
127
|
|
|
* |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
|
|
public function toArray(): array |
131
|
|
|
{ |
132
|
|
|
return [ |
133
|
|
|
'title' => $this->getTitle(), |
134
|
|
|
'value' => $this->getValue(), |
135
|
|
|
'short' => $this->getShort(), |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
} |