1 | <?php |
||
8 | class Attachment extends Partial implements AttachmentInterface |
||
9 | { |
||
10 | protected $optional = [ |
||
11 | 'fallback', |
||
12 | 'text', |
||
13 | 'pretext', |
||
14 | 'color', |
||
15 | 'fields', |
||
16 | 'author_name', |
||
17 | 'author_link', |
||
18 | 'author_icon', |
||
19 | 'title', |
||
20 | 'title_link', |
||
21 | 'image_url', |
||
22 | 'thumb_url', |
||
23 | 'mrkdwn_in', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 15 | public function __construct($data = []) |
|
30 | { |
||
31 | 15 | if (!isset($data['fields'])) { |
|
32 | 9 | $data['fields'] = new FieldCollection(); |
|
33 | 9 | } |
|
34 | |||
35 | 15 | parent::__construct($data); |
|
36 | 15 | } |
|
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | 15 | protected function setDefaultOptions(OptionsResolver $resolver) |
|
42 | { |
||
43 | 15 | parent::setDefaultOptions($resolver); |
|
44 | |||
45 | 15 | $resolver->setTypesAllowed([ |
|
46 | 15 | 'fields' => '\Crummy\Phlack\Message\Collection\FieldCollection', |
|
47 | 15 | ]); |
|
48 | 15 | } |
|
49 | |||
50 | /** |
||
51 | * @param FieldInterface $field |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | 4 | public function addField(FieldInterface $field) |
|
56 | { |
||
57 | 4 | $this['fields']->add($field); |
|
58 | |||
59 | 4 | return $this; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return FieldCollection |
||
64 | */ |
||
65 | 2 | public function getFields() |
|
69 | } |
||
70 |