php-slack /
slack
| 1 | <?php |
||
| 2 | namespace Maknz\Slack; |
||
| 3 | |||
| 4 | use InvalidArgumentException; |
||
| 5 | |||
| 6 | class AttachmentAction extends Payload |
||
| 7 | { |
||
| 8 | const TYPE_BUTTON = 'button'; |
||
| 9 | |||
| 10 | const STYLE_DEFAULT = 'default'; |
||
| 11 | const STYLE_PRIMARY = 'primary'; |
||
| 12 | const STYLE_DANGER = 'danger'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The required name field of the action. The name will be returned to your Action URL. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $name; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The required label for the action. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $text; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Button style. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $style; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The required type of the action. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $type = self::TYPE_BUTTON; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Optional value. It will be sent to your Action URL. |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $value; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Optional URL. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $url; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Confirmation field. |
||
| 58 | * |
||
| 59 | * @var ActionConfirmation |
||
| 60 | */ |
||
| 61 | protected $confirm; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Internal attribute to property map. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected static $availableAttributes = [ |
||
| 69 | 'name' => 'name', |
||
| 70 | 'text' => 'text', |
||
| 71 | 'style' => 'style', |
||
| 72 | 'type' => 'type', |
||
| 73 | 'url' => 'url', |
||
| 74 | 'value' => 'value', |
||
| 75 | 'confirm' => 'confirm', |
||
| 76 | ]; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Instantiate a new AttachmentAction. |
||
| 80 | * |
||
| 81 | * @param array $attributes |
||
| 82 | * |
||
| 83 | * @throws InvalidArgumentException |
||
| 84 | */ |
||
| 85 | 4 | public function __construct(array $attributes) |
|
| 86 | { |
||
| 87 | 4 | parent::__construct($attributes); |
|
| 88 | 4 | } |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | 2 | public function getName() |
|
| 94 | { |
||
| 95 | 2 | return $this->name; |
|
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $name |
||
| 100 | * @return AttachmentAction |
||
| 101 | */ |
||
| 102 | 4 | public function setName($name) |
|
| 103 | { |
||
| 104 | 4 | $this->name = $name; |
|
| 105 | |||
| 106 | 4 | return $this; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | 3 | public function getText() |
|
| 113 | { |
||
| 114 | 3 | return $this->text; |
|
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @param string $text |
||
| 119 | * @return AttachmentAction |
||
| 120 | */ |
||
| 121 | 4 | public function setText($text) |
|
| 122 | { |
||
| 123 | 4 | $this->text = $text; |
|
| 124 | |||
| 125 | 4 | return $this; |
|
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return string |
||
| 130 | */ |
||
| 131 | 2 | public function getUrl() |
|
| 132 | { |
||
| 133 | 2 | return $this->url; |
|
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param string $url |
||
| 138 | * @return AttachmentAction |
||
| 139 | */ |
||
| 140 | 2 | public function setUrl($url) |
|
| 141 | { |
||
| 142 | 2 | $this->url = $url; |
|
| 143 | |||
| 144 | 2 | return $this; |
|
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | 2 | public function getStyle() |
|
| 151 | { |
||
| 152 | 2 | return $this->style; |
|
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param string $style |
||
| 157 | * @return AttachmentAction |
||
| 158 | */ |
||
| 159 | 4 | public function setStyle($style) |
|
| 160 | { |
||
| 161 | 4 | $this->style = $style; |
|
| 162 | |||
| 163 | 4 | return $this; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | 2 | public function getType() |
|
| 170 | { |
||
| 171 | 2 | return $this->type; |
|
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param string $type |
||
| 176 | * @return AttachmentAction |
||
| 177 | */ |
||
| 178 | 4 | public function setType($type) |
|
| 179 | { |
||
| 180 | 4 | $this->type = $type; |
|
| 181 | |||
| 182 | 4 | return $this; |
|
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @return string |
||
| 187 | */ |
||
| 188 | 2 | public function getValue() |
|
| 189 | { |
||
| 190 | 2 | return $this->value; |
|
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param string $value |
||
| 195 | * @return AttachmentAction |
||
| 196 | */ |
||
| 197 | 4 | public function setValue($value) |
|
| 198 | { |
||
| 199 | 4 | $this->value = $value; |
|
| 200 | |||
| 201 | 4 | return $this; |
|
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return ActionConfirmation |
||
| 206 | */ |
||
| 207 | 2 | public function getConfirm() |
|
| 208 | { |
||
| 209 | 2 | return $this->confirm; |
|
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param ActionConfirmation|array $confirm |
||
| 214 | * |
||
| 215 | * @return AttachmentAction |
||
| 216 | * |
||
| 217 | * @throws InvalidArgumentException |
||
| 218 | */ |
||
| 219 | 4 | public function setConfirm($confirm) |
|
| 220 | { |
||
| 221 | 4 | if ($confirm instanceof ActionConfirmation) { |
|
| 222 | $this->confirm = $confirm; |
||
| 223 | |||
| 224 | return $this; |
||
| 225 | 4 | } elseif (is_array($confirm)) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 226 | 4 | $this->confirm = new ActionConfirmation($confirm); |
|
| 227 | |||
| 228 | 4 | return $this; |
|
| 229 | } |
||
| 230 | |||
| 231 | throw new InvalidArgumentException('The action confirmation must be an instance of Maknz\Slack\ActionConfirmation or a keyed array'); |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get the array representation of this attachment action. |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | 2 | public function toArray() |
|
| 240 | { |
||
| 241 | 2 | $array = [ |
|
| 242 | 2 | 'name' => $this->getName(), |
|
| 243 | 2 | 'text' => $this->getText(), |
|
| 244 | 2 | 'style' => $this->getStyle(), |
|
| 245 | 2 | 'type' => $this->getType(), |
|
| 246 | 2 | 'value' => $this->getValue(), |
|
| 247 | 2 | 'url' => $this->getUrl(), |
|
| 248 | ]; |
||
| 249 | |||
| 250 | 2 | if (($confirm = $this->getConfirm()) !== null) { |
|
| 251 | 2 | $array['confirm'] = $confirm->toArray(); |
|
| 252 | } |
||
| 253 | |||
| 254 | 2 | return $array; |
|
| 255 | } |
||
| 256 | } |
||
| 257 |